Agent skill
postgresql
PostgreSQL DBA skill for schema design review, indexing, query tuning (EXPLAIN/ANALYZE), vacuum/autovacuum, concurrency/locking, partitioning, backup/restore, replication/HA, and safe migrations. Use for tasks like diagnosing slow queries, designing indexes and constraints, and operating Postgres in production.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/postgresql-muzhicaomingwang-ai-ideas
SKILL.md
postgresql
Use this skill for PostgreSQL 相关设计、性能与运维(DBA)任务。
Defaults / assumptions to confirm
- Postgres version
- Deployment: managed vs self-hosted, single instance vs HA
- Connection pooler: pgbouncer?
- Workload: OLTP vs OLAP, write-heavy vs read-heavy
Workflow
- Understand workload and query paths
- Core tables, top queries, read/write ratio, growth rate.
- Latency SLO and peak hours.
- Schema review
- Primary key strategy (string IDs vs bigint; be explicit about external IDs).
- Types:
TIMESTAMPTZfor time,NUMERICvsBIGINTvsDECIMALtrade-offs. - Constraints:
NOT NULL,CHECK,UNIQUEwhere needed. - JSONB usage: keep structure stable; consider normalization vs JSONB.
- Comments: require
COMMENT ON TABLE/COLUMNfor long-lived schemas.
- Index design
- Add indexes for WHERE/JOIN/ORDER BY patterns.
- Composite indexes aligned with left-prefix.
- Partial indexes for sparse predicates.
GINfor JSONB/array search;btree_gin/pg_trgmif used.- Avoid redundant indexes and over-indexing on write-heavy tables.
- Query tuning
- Use
EXPLAIN (ANALYZE, BUFFERS)to validate plans. - Watch for seq scans, bad estimates, bloated tables, missing stats.
- Consider query rewrites, better predicates, and covering indexes.
- Concurrency and locking
- Inspect lock contention; avoid long transactions.
- Use appropriate isolation; detect deadlocks and hot rows.
- Maintenance (vacuum / bloat)
- Ensure autovacuum is effective; tune thresholds per table if needed.
- Monitor bloat and
n_dead_tup; useVACUUM (ANALYZE)and reindex when justified.
- Partitioning & scaling
- Partition only when there is pruning benefit and operational plan.
- Time-based partitions for append-only logs; ensure indexes per partition.
- Consider sharding only with strong requirements and stable shard key.
- Operations
- Backups: base backup + WAL archiving; restore drills; retention.
- Replication: streaming replication, lag monitoring, failover runbook.
- Migrations: safe rollout steps, lock-time considerations, backout plan.
Outputs
- Index/constraint plan (query → index/constraint → impact/tradeoff).
- Migration plan (DDL, rollout sequence, verification, rollback).
- Performance report (evidence, root cause, fixes, metrics to monitor).
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?