Token导航 LogoToken导航TokenDH.com
开发需要联网github未标认证来源可访问许可证需确认审计提醒

optimizing-database-connection-pooling优化数据库连接池

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

659

周安装

28

GitHub Stars

2,097

下载量

231
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:optimizing-database-connection-pooling(优化数据库连接池)
来源仓库:https://github.com/jeremylongshore/claude-code-plugins-plus-skills
仓库路径:skills/optimizing-database-connection-pooling
安装命令:
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill optimizing-database-connection-pooling
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill optimizing-database-connection-pooling

简介

用于辅助数据库表结构、查询语句和迁移脚本的处理,支持 schema 分析与索引优化。

  • 适用于编写 SQL、排查查询问题或生成迁移建议的场景。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用。
  • 涉及数据变更时应优先 dry-run 或事务保护,避免误操作。
  • optimizing-database-connection-pooling 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Database Connection Pooler

Overview

Configure and optimize database connection pooling using external poolers (PgBouncer, ProxySQL, Odyssey) and application-level pool settings to prevent connection exhaustion, reduce connection overhead, and improve database throughput.

Prerequisites

  • psql or mysql CLI for querying connection metrics
  • Access to database configuration files (postgresql.conf, my.cnf) for max_connections settings
  • PgBouncer, ProxySQL, or Odyssey installed if using external pooling
  • Application connection pool settings accessible (database URL, pool size parameters)
  • Server CPU core count and available memory for pool sizing calculations

Instructions

  1. Audit current connection usage by querying active connections:

- PostgreSQL: SELECT count(*) AS total, state, usename FROM pg_stat_activity GROUP BY state, usename ORDER BY total DESC - MySQL: SHOW STATUS LIKE 'Threads_connected' and SHOW PROCESSLIST - Compare against max_connections setting to determine headroom

  1. Calculate the optimal pool size using the formula: pool_size = (core_count * 2) + effective_spindle_count. For SSD-backed databases, use core_count * 2 + 1. A 4-core server with SSD storage should have a pool size of approximately 9. This formula applies per application instance.
  2. Configure application-level connection pool parameters:

- minimumIdle: Set to 2-5 for low-traffic periods (avoids cold-start latency) - maximumPoolSize: Set using the formula from step 2 - connectionTimeout: 5-10 seconds (fail fast rather than queue indefinitely) - idleTimeout: 10-30 minutes (release idle connections back to pool) - maxLifetime: 30 minutes (prevent stale connections from accumulating) - leakDetectionThreshold: 60 seconds (log warning for connections held too long)

  1. For PostgreSQL with many application instances, deploy PgBouncer in transaction pooling mode:

- Set pool_mode = transaction to multiplex connections (one backend connection serves many clients between transactions) - Set default_pool_size = 20 and max_client_conn = 1000 - Configure server_idle_timeout = 600 to close unused backend connections - Set server_lifetime = 3600 to periodically refresh connections

  1. For MySQL with many application instances, deploy ProxySQL:

- Configure connection multiplexing in mysql_servers table - Set max_connections per backend server - Configure query rules for read/write splitting to replicas - Enable connection pooling with free_connections_pct = 10

  1. Set max_connections in the database server based on available memory. Each PostgreSQL connection uses approximately 5-10MB of memory. For a server with 8GB RAM: max_connections = (8192MB - 2048MB_for_OS - 2048MB_shared_buffers) / 10MB = ~400. For MySQL, each thread uses approximately 1-4MB.
  2. Implement connection health checks. Configure the pool to validate connections before lending (testOnBorrow or validation-query). Use a lightweight query: SELECT 1 for MySQL or a simple query for PostgreSQL. Set validation interval to avoid excessive overhead.
  3. Monitor connection pool metrics continuously:

- Active connections vs. pool size (saturation indicator) - Wait time for connection acquisition (queuing indicator) - Connection creation rate (churn indicator) - Idle connection count (waste indicator) - Connection leak warnings (application bug indicator)

  1. Handle connection storms (sudden spike in connection requests) by configuring a connection request queue with a bounded wait time, implementing retry with exponential backoff in the application, and pre-warming the pool during application startup.
  2. Document the connection architecture: application pool size per instance, number of application instances, PgBouncer/ProxySQL settings, database max_connections, and the maximum theoretical connections formula (instances * pool_size_per_instance).

Output

  • PgBouncer/ProxySQL configuration files with optimized pool settings
  • Application pool configuration with connection string and pool parameters
  • Connection sizing worksheet documenting the calculation from cores to pool size
  • Monitoring queries for connection metrics and health checks
  • Connection architecture diagram showing application -> pooler -> database flow

Error Handling

ErrorCauseSolution
FATAL: too many connections for roleApplication pool size exceeds max_connections or connection leakReduce pool size; fix connection leaks (enable leak detection); add PgBouncer for connection multiplexing
Connection timeout after 5 secondsPool exhausted, all connections in useIncrease pool size cautiously; check for long-running transactions holding connections; add connection queue with backpressure
connection reset by peer errorsServer-side idle timeout killed the connectionSet pool maxLifetime shorter than server idle_in_transaction_session_timeout; enable connection validation
PgBouncer no more connections allowedmax_client_conn exceededIncrease max_client_conn; or reduce client connection demand; check for connection leaks in application
High connection churn (create/destroy rate)Pool too small for workload or maxLifetime too shortIncrease pool size; extend maxLifetime to 30 minutes; ensure minimumIdle is set to avoid constant pool resizing

Examples

Right-sizing a pool for a Spring Boot microservice: 4-core server, SSD storage, 3 microservice instances. Optimal pool per instance: (4 * 2) + 1 = 9. Total connections: 9 * 3 = 27. Database max_connections = 100 with comfortable headroom. Application startup pre-warms 5 connections per instance. Connection leak detection set to 60 seconds catches a missing connection.close() in an error handler.

PgBouncer deployment for a serverless application: Lambda functions create a new database connection per invocation, overwhelming PostgreSQL with 500+ connections. PgBouncer deployed between Lambda and PostgreSQL with pool_mode = transaction, default_pool_size = 25, max_client_conn = 5000. Lambda connects to PgBouncer; PgBouncer multiplexes to 25 backend connections. Connection errors eliminated; database CPU reduced from 95% to 30%.

ProxySQL read/write splitting: A MySQL application sends 80% reads and 20% writes. ProxySQL routes writes to the primary and distributes reads across 2 replicas. Connection pooling reduces backend connections from 300 (direct) to 60 (pooled). Average query latency drops from 8ms to 3ms due to reduced connection overhead.

Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

32.74%
按下载量换算76

Claude

31.64%
按下载量换算73

Cursor

19.72%
按下载量换算46

Gemini CLI

9.91%
按下载量换算23

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills