Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:18:10 +08:00
commit 85a6a9fef3
8 changed files with 390 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
{
"name": "database-connection-pooler",
"description": "Implement and optimize database connection pooling for improved performance and resource management",
"version": "1.0.0",
"author": {
"name": "Claude Code Plugins",
"email": "[email protected]"
},
"skills": [
"./skills"
],
"commands": [
"./commands"
]
}

3
README.md Normal file
View File

@@ -0,0 +1,3 @@
# database-connection-pooler
Implement and optimize database connection pooling for improved performance and resource management

183
commands/connection-pool.md Normal file
View File

@@ -0,0 +1,183 @@
---
description: Set up and optimize database connection pooling
---
# Database Connection Pooler
You are a database connection pooling expert. Help implement efficient connection management.
## Connection Pooling Concepts
1. **Why Connection Pooling?**
- Reduce connection overhead
- Reuse established connections
- Control max concurrent connections
- Improve application performance
- Prevent database overload
2. **Pool Configuration**
- Min pool size: Minimum idle connections
- Max pool size: Maximum total connections
- Connection timeout: Wait time for available connection
- Idle timeout: Remove idle connections
- Max lifetime: Recycle old connections
3. **Best Practices**
- Pool size = (CPU cores * 2) + disk spindles
- Monitor connection usage
- Set appropriate timeouts
- Handle connection failures
- Validate connections
## Implementation Examples
### Node.js (pg-pool)
```javascript
const { Pool } = require('pg');
const pool = new Pool({
host: 'localhost',
port: 5432,
database: 'mydb',
user: 'user',
password: 'password',
max: 20, // Max connections
min: 5, // Min connections
idleTimeoutMillis: 30000, // Close idle after 30s
connectionTimeoutMillis: 2000, // Wait 2s for connection
maxUses: 7500 // Recycle after 7500 uses
});
// Query with pool
async function getUser(id) {
const client = await pool.connect();
try {
const result = await client.query('SELECT * FROM users WHERE id = $1', [id]);
return result.rows[0];
} finally {
client.release();
}
}
// Or use pool.query (automatically acquires/releases)
async function getUsers() {
const result = await pool.query('SELECT * FROM users');
return result.rows;
}
```
### Python (SQLAlchemy)
```python
from sqlalchemy import create_engine
from sqlalchemy.pool import QueuePool
engine = create_engine(
'postgresql://user:password@localhost/mydb',
poolclass=QueuePool,
pool_size=10, # Number of connections
max_overflow=20, # Additional connections if needed
pool_timeout=30, # Wait 30s for connection
pool_recycle=3600, # Recycle after 1 hour
pool_pre_ping=True # Verify connection before use
)
# Use with context manager
def get_user(user_id):
with engine.connect() as conn:
result = conn.execute("SELECT * FROM users WHERE id = %s", user_id)
return result.fetchone()
```
### Java (HikariCP)
```java
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:postgresql://localhost:5432/mydb");
config.setUsername("user");
config.setPassword("password");
config.setMaximumPoolSize(20);
config.setMinimumIdle(5);
config.setConnectionTimeout(30000);
config.setIdleTimeout(600000);
config.setMaxLifetime(1800000);
HikariDataSource dataSource = new HikariDataSource(config);
// Use connection
try (Connection conn = dataSource.getConnection()) {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM users");
// Process results
}
```
## Monitoring Metrics
Track these metrics:
- Active connections
- Idle connections
- Wait time for connections
- Connection errors
- Pool exhaustion events
- Connection creation rate
- Average connection duration
## Common Issues
### Problem: Connection Pool Exhaustion
**Symptom**: Timeout errors, slow requests
**Causes**:
- Pool too small
- Connections not being released
- Long-running queries
- Connection leaks
**Solutions**:
```javascript
// Always release connections
const client = await pool.connect();
try {
// Your query
} finally {
client.release(); // CRITICAL
}
// Or use pool.query (auto-releases)
await pool.query('SELECT * FROM users');
```
### Problem: Too Many Connections
**Symptom**: Database rejecting connections
**Solution**: Reduce max pool size or increase database max_connections
## Configuration Guidelines
### Small Application
```
Min: 2-5
Max: 10-20
```
### Medium Application
```
Min: 5-10
Max: 20-50
```
### Large Application
```
Min: 10-20
Max: 50-100
```
## When Invoked
1. Identify programming language and framework
2. Determine database system
3. Analyze expected load
4. Provide pool configuration
5. Generate implementation code
6. Include monitoring setup
7. Suggest best practices

61
plugin.lock.json Normal file
View File

@@ -0,0 +1,61 @@
{
"$schema": "internal://schemas/plugin.lock.v1.json",
"pluginId": "gh:jeremylongshore/claude-code-plugins-plus:plugins/database/database-connection-pooler",
"normalized": {
"repo": null,
"ref": "refs/tags/v20251128.0",
"commit": "54b0b1a778a5285e9a6c8ab1e51dffde233a80e7",
"treeHash": "95cc82523fefa0df14916d1468ce2587198ac73f5b73e172e4b508a19e37482a",
"generatedAt": "2025-11-28T10:18:19.092995Z",
"toolVersion": "publish_plugins.py@0.2.0"
},
"origin": {
"remote": "git@github.com:zhongweili/42plugin-data.git",
"branch": "master",
"commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390",
"repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data"
},
"manifest": {
"name": "database-connection-pooler",
"description": "Implement and optimize database connection pooling for improved performance and resource management",
"version": "1.0.0"
},
"content": {
"files": [
{
"path": "README.md",
"sha256": "0784135d53227b0ce54c47c519e266dde6374423ba3e43dc198ddbf6326f937d"
},
{
"path": ".claude-plugin/plugin.json",
"sha256": "61e44e5fddccc6d1741443c2f45e3fb2ff6c86b0753a44dbd29f53410ef77dc2"
},
{
"path": "commands/connection-pool.md",
"sha256": "9df61b911fa7a82edb19462b3807557874fb3946344bf4daee9ac760f20a906a"
},
{
"path": "skills/database-connection-pooler/SKILL.md",
"sha256": "19c860ad2af180d345660727a6cbde85537c322109736f5d2cbefab3d3fe3f6a"
},
{
"path": "skills/database-connection-pooler/references/README.md",
"sha256": "db9680278e03728fef93321fc76c435387bc0c8fe1dcc9870bdf2fa236ea8ac3"
},
{
"path": "skills/database-connection-pooler/scripts/README.md",
"sha256": "f042646ad5b685556c044080a6b73202a490fb8288be8219328faefc12d5a30e"
},
{
"path": "skills/database-connection-pooler/assets/README.md",
"sha256": "33bfb083485b48c78a1738368c52cd9f202724a414bce507db181d8291b83aec"
}
],
"dirSha256": "95cc82523fefa0df14916d1468ce2587198ac73f5b73e172e4b508a19e37482a"
},
"security": {
"scannedAt": null,
"scannerVersion": null,
"flags": []
}
}

View File

@@ -0,0 +1,52 @@
---
name: optimizing-database-connection-pooling
description: |
This skill optimizes database connection pooling for enhanced performance and resource management. It is activated when the user requests assistance with connection pooling, database performance tuning, or connection lifecycle management. Use this skill to implement and configure connection pools in various programming languages, identify optimal pool settings, and troubleshoot common connection-related issues. The skill is triggered by phrases like "connection pooling," "optimize database connections," or "improve database performance with connection pool."
allowed-tools: Read, Write, Edit, Grep, Glob, Bash
version: 1.0.0
---
## Overview
This skill enables Claude to generate and configure database connection pools, ensuring optimal performance and resource utilization. It provides guidance on selecting appropriate pool settings, managing connection lifecycles, and monitoring pool performance.
## How It Works
1. **Identify Requirements**: Analyzes the user's request to determine the target database, programming language, and performance goals.
2. **Generate Configuration**: Creates a connection pool configuration tailored to the specified environment, including settings for minimum and maximum pool size, connection timeout, and other relevant parameters.
3. **Implement Monitoring**: Sets up monitoring for key pool metrics, such as connection usage, wait times, and error rates.
## When to Use This Skill
This skill activates when you need to:
- Implement connection pooling for a database application.
- Optimize existing connection pool configurations.
- Troubleshoot connection-related performance issues.
## Examples
### Example 1: Implementing Connection Pooling in Python
User request: "Implement connection pooling in Python for a PostgreSQL database to improve performance."
The skill will:
1. Generate a Python code snippet using a connection pool library like `psycopg2` or `SQLAlchemy`.
2. Configure the connection pool with optimal settings for the PostgreSQL database, such as maximum pool size and connection timeout.
### Example 2: Optimizing Connection Pool Configuration in Java
User request: "Optimize the connection pool configuration in my Java application using HikariCP to reduce connection wait times."
The skill will:
1. Analyze the existing HikariCP configuration.
2. Suggest adjustments to parameters like minimum idle connections, maximum pool size, and connection timeout to minimize wait times.
## Best Practices
- **Connection Timeout**: Set a reasonable connection timeout to prevent indefinite waiting.
- **Pool Size**: Adjust the pool size based on the application's workload and database server capacity.
- **Connection Testing**: Implement connection validation to ensure connections are still valid before use.
## Integration
This skill can integrate with other Claude Code plugins for database management, code generation, and performance monitoring to provide a comprehensive solution for database optimization.

View File

@@ -0,0 +1,26 @@
# Skill Assets
This directory contains static assets used by this skill.
## Purpose
Assets can include:
- Configuration files (JSON, YAML)
- Data files
- Templates
- Schemas
- Test fixtures
## Guidelines
- Keep assets small and focused
- Document asset purpose and format
- Use standard file formats
- Include schema validation where applicable
## Common Asset Types
- **config.json** - Configuration templates
- **schema.json** - JSON schemas
- **template.yaml** - YAML templates
- **test-data.json** - Test fixtures

View File

@@ -0,0 +1,26 @@
# Skill References
This directory contains reference materials that enhance this skill's capabilities.
## Purpose
References can include:
- Code examples
- Style guides
- Best practices documentation
- Template files
- Configuration examples
## Guidelines
- Keep references concise and actionable
- Use markdown for documentation
- Include clear examples
- Link to external resources when appropriate
## Types of References
- **examples.md** - Usage examples
- **style-guide.md** - Coding standards
- **templates/** - Reusable templates
- **patterns.md** - Design patterns

View File

@@ -0,0 +1,24 @@
# Skill Scripts
This directory contains optional helper scripts that support this skill's functionality.
## Purpose
Scripts here can be:
- Referenced by the skill for automation
- Used as examples for users
- Executed during skill activation
## Guidelines
- All scripts should be well-documented
- Include usage examples in comments
- Make scripts executable (`chmod +x`)
- Use `#!/bin/bash` or `#!/usr/bin/env python3` shebangs
## Adding Scripts
1. Create script file (e.g., `analyze.sh`, `process.py`)
2. Add documentation header
3. Make executable: `chmod +x script-name.sh`
4. Test thoroughly before committing