Preface¶
Issues like slow queries, missing indexes, and connection pool exhaustion often require juggling between documentation, EXPLAIN outputs, and operational experience. When involving an Agent in troubleshooting, without a stable set of PostgreSQL optimization guidelines, the responses tend to be scattered, and SQL examples inconsistent.
Below is an introduction to Postgres优化 (Postgres Optimization) on SkillHub (Location: @user_3c6cb52e/postgres-optimization-sh-g3z1h6, Version 1.0.0). It is published in the universal SKILL.md format. Once installed, the Agent can assist you with Postgres-related tasks by following the key points regarding indexes, execution plans, partitioning, and connection pooling organized within the skill.
What is this¶
Postgres优化 is a specialized PostgreSQL optimization skill designed for AI Agents. Its official description is: Help agents efficiently complete related tasks.
- Source: SkillHub community skill, published by user_3c6cb52e
- Category:
dev-programming(The skill metadata also tags it as “Developer Tools”) - License: MIT (See the header of
SKILL.mdwithin the skill package) - Dependencies: Tag requires_api_key=false, no additional API Key needed
- Compatible Frameworks (Listed in skill metadata): Claude Code, Codex, Hermes Agent, OpenClaw, QClaw, WorkBuddy, etc.; Clients like Cursor can install it to their respective skills directories via the SkillHub CLI.
Skill Homepage and API Entry:
- Page: https://www.skillhub.cn/skills/user_3c6cb52e/postgres-optimization-sh-g3z1h6
- API: https://api.skillhub.cn/user_3c6cb52e/postgres-optimization-sh-g3z1h6
As of the time of data retrieval, SkillHub displays a rating of 100000 and 1460 downloads (Installation count is 0, subject to page statistics).
Core Functions¶
The body of the skill focuses on PostgreSQL Optimization, breaking down common optimization tasks into quotable snippets and checklists. It mainly includes:
- Index Strategy: Example SQL for B-tree, composite index column order, partial indexes, covering indexes (
INCLUDE), GIN (JSONB), GiST (Full Text),CREATE INDEX CONCURRENTLY, etc. - Reading Execution Plans: Examples of
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT), with explanations of plan nodes to watch for (such asSeq Scan,Nested Loop,Sort, buffer hit/read). - Table Partitioning: Examples of
RANGEpartitioned tables and sub-partitions; suggests considering partitioning when filtering by partition key and row count exceeds approximately 10 million. - JSONB: Examples of containment (
@>), nested field querying and updating,jsonb_array_elements_text, etc. - Connection Pooling:
pgbouncer.inisnippets (transaction pool mode, connection counts, etc.), distinguishing between the applicable scenarios for transaction-level and session-level pooling. - Common Diagnostic SQL: Finding slow queries based on
pg_stat_statements, finding unused indexes based onpg_stat_user_indexes. - Anti-patterns and Checklists: E.g., blindly creating indexes, not writing
EXPLAIN ANALYZE, runningVACUUM FULLduring peak hours; includes an optimization checklist (pg_stat_statements, composite index order, PgBouncer/pgcat, etc.).
The above capabilities are all derived from the SKILL.md within the skill package and do not include standalone executable scripts; the Agent primarily aligns with these conventions and examples during conversations and when modifying SQL/configurations.
Installation and Activation¶
1. Install SkillHub CLI¶
First, check if the CLI is already on your machine:
command -v skillhub && skillhub --version
If not installed, follow the official SkillHub installation documentation to perform a full installation (CLI + Default Skill):
curl -fsSL https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/install.sh | bash
To install only the CLI:
curl -fsSL https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/install.sh | bash -s -- --cli-only
2. Install the Postgres优化 Skill¶
When installing, you must use --dir to point to the current Agent’s skills directory; otherwise, it defaults to ./skills/, which the Agent may not be able to load.
skillhub install '@user_3c6cb52e/postgres-optimization-sh-g3z1h6' --dir <skills directory>
Common client skills paths (Excerpt from SkillHub installation docs):
- Cursor:
~/.cursor/skills/ - Claude Code:
~/.claude/skills/ - Codex:
~/.codex/skills/or.agents/skills/under the project
You can also send the prompt provided on the official page to the Agent and have it complete the installation according to https://skillhub.cn/install/skillhub.md:
Please install `@user_3c6cb52e/postgres-optimization-sh-g3z1h6` based on https://skillhub.cn/install/skillhub.md.
After installation is complete, restart or refresh the Agent according to the requirements of your client to activate the skill.
Typical Usage¶
The skill does not provide a separate CLI; the typical workflow is: Install Skill → Describe the database tables and slow query symptoms in conversation → Let the Agent provide index, plan interpretation, or configuration suggestions based on the patterns in the skill.
The following two snippets are from the skill body and can be used directly as a starting point for reproduction and alignment with the Agent.
Analyze key queries with EXPLAIN (The Agent can explain whether full table scans appear in the plan or if sorting bypasses indexes, etc.):
EXPLAIN (ANALYZE, BUFFERS, FORMAT TEXT)
SELECT o.id, o.total, u.name
FROM orders o
JOIN users u ON o.user_id = u.id
WHERE o.status = 'shipped'
AND o.created_at > NOW() - INTERVAL '30 days'
ORDER BY o.created_at DESC
LIMIT 20;
Create a partial index for high-frequency filter conditions:
CREATE INDEX idx_orders_pending ON orders (created_at)
WHERE status = 'pending';
You can also ask the Agent to check the current environment item by item against the Checklist at the end of the skill (pg_stat_statements, composite index column order, connection pooling, partitioning, and unused indexes, etc.).
Applicable Scenarios and Notes¶
Who is it for
- Those who use PostgreSQL daily and need the Agent to provide advice consistent with documentation regarding index design,
EXPLAINinterpretation, JSONB queries, and PgBouncer configuration. - Those already using Skills in clients like Cursor, Claude Code, Codex, or the OpenClaw series, who wish to solidify Postgres optimization knowledge into a reusable prompt package.
Limitations and Notes
- The skill content consists of knowledge and SQL/configuration templates; it will not automatically connect to your database. Production changes still require you to verify in the target environment and execute operations like
CREATE INDEX CONCURRENTLYduring off-peak hours. - The
homepage/repositoryin the metadata point to a GitHub user page; the maintenance relationship with SkillHub package version 1.0.0 is subject to the SkillHub release. For upgrades, useskillhubwithin the corresponding skills directory to update (follow the instructions in https://skillhub.cn/install/skillhub.md). - Partitioning, pooling parameters, etc., need to be combined with actual data volumes and access patterns; thresholds given in the skill (e.g., considering partitioning at around 10 million rows) are empirical hints, not hard rules.
Conclusion¶
Postgres优化 consolidates indexes, execution plans, partitioning, JSONB, connection pooling, and diagnostic SQL into a single SKILL.md, giving the Agent a unified reference for Postgres-related tasks. If you use SkillHub to manage skills, you can install it from the official page:
https://www.skillhub.cn/skills/user_3c6cb52e/postgres-optimization-sh-g3z1h6