audit-pg-config
Audit Postgres server config — shared_buffers, work_mem, max_connections vs pgbouncer pool, autovacuum tuning, WAL retention.
- License 许可
- MIT
- 最近更新
- 2026-10-29
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- audit-pg-config
- description
- Audit Postgres server config — shared_buffers, work_mem, max_connections vs pgbouncer pool, autovacuum tuning, WAL retention.
03 SKILL.md 正文
audit-pg-config
Sanity-check a Postgres config against the workload. Output: parameter-by-parameter findings + concrete change suggestions.
Mode: analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked [TBD] or [VERIFY], never filled in.
When to use
- A Postgres instance is slow, OOMing, bloating, or lagging replicas and the config is a suspect.
- Before a traffic step-up, or after migrating to a new host / managed tier.
Inputs
- The effective settings — not the config file you think is deployed:
SELECT name, setting, unit, source FROM pg_settings WHERE source <> 'default';plusSELECT version();. - Host RAM and CPU, whether a pooler (pgbouncer) sits in front, the workload shape (OLTP / analytics / mixed), and whether it is managed (RDS/Aurora/Cloud SQL/Azure — some parameters are fixed or set through parameter groups).
- Missing an input? Say which finding it blocks and continue with the rest; don't guess RAM or workload.
Read-only. Gather with SELECT/SHOW only. Never run ALTER SYSTEM, change a parameter group, or reload/restart — recommend; the owner applies.
Procedure
- Memory.
shared_buffers— 25% of RAM is a common starting point; over 40% and you start fighting the OS page cache.work_mem— per-operation, per-connection.work_mem × max_connections × parallel_workerscan OOM a host. Lean on the smaller side; raise per-session for ETL.maintenance_work_mem— for autovacuum + CREATE INDEX. 1-2GB on hosts with > 32GB RAM is reasonable.
- Connections.
max_connections— high values (> 200) waste memory; pair withpgbouncerintransactionmode and let the bouncer hold the pool.- Hard floor: enough headroom for
pg_stat_statements, monitoring agents, and admin sessions.
- WAL + checkpoints.
wal_compression = on— cheap CPU for less WAL bytes (helps replicas).max_wal_size/min_wal_size— too small triggers checkpoints too often (latency spikes).checkpoint_completion_target = 0.9— spreads checkpoint IO over time.
- Autovacuum.
autovacuum_vacuum_scale_factor— default 0.2 means vacuum kicks in at 20% dead tuples; large tables benefit from a much lower per-table setting (e.g. 0.05).autovacuum_max_workers— raise above the default 3 for many-tabled clusters.autovacuum_analyze_scale_factor— analyze runs less than vacuum; on hot tables, tune down.
- Statistics.
default_statistics_target— 100 is the default; 500-1000 for skew-y joins where the planner makes bad row-estimates.track_io_timing = on— needed forpg_stat_statementsto show meaningful IO numbers.
- Replication.
hot_standby_feedback = onif long-running replica reads exist (prevents query cancellations on the replica — at the cost of bloat on the primary while those queries run).wal_keep_size(PG 13+) replaceswal_keep_segments; ensure replicas can catch up without falling off.- Replication slots retain WAL until consumed — an abandoned slot fills the disk. Set
max_slot_wal_keep_size(PG 13+) and checkpg_replication_slotsfor inactive slots.
- Logging.
log_min_duration_statement = '500ms'(or workload-specific). Cheaper than waiting for a customer ticket.log_lock_waits = on— diagnose lock-storm incidents.
Output
audit-pg-config
Host: db.refund-prod
Version: 16.3
RAM: 64GB
Memory
✓ shared_buffers = 16GB (25% of RAM).
✗ work_mem = 256MB; with max_connections=300 worst-case 75GB. Lower to 64MB
(per-session bump for ETL).
Connections
✗ max_connections = 300 without a pgbouncer. Add pgbouncer in transaction mode;
drop max_connections to ~120.
Autovacuum
✓ autovacuum on.
⚠ refunds table dead-tuple ratio 38% (per pg_stat_user_tables). Per-table
autovacuum_vacuum_scale_factor = 0.05; consider HOT-only tuning.
WAL
✓ max_wal_size = 4GB.
Logging
✗ log_min_duration_statement = -1 (off). Recommend 500ms.
Recommendation: 4 changes; mem + connections are the highest leverage.
Anti-patterns to avoid
- Raising
max_connectionswithoutpgbouncer. Linear memory cost per backend. - Turning autovacuum off "for now". You will not turn it back on; bloat will eat you.
- Setting
fsync = offon production. Data loss on crash. - Cargo-culted
shared_buffers = 4GBon a 256GB host. Match the workload, not the wiki.
Related skills
polymath-database:postgres-performance— runtime tuning frompg_stat_*evidence (bloat, HOT, index types, locks, pooling); this skill audits the settings, that one diagnoses the workload.polymath-database:db-performance-triage— start there when the bottleneck isn't known.
04 同仓库更多 Skills
runbook
Write or refresh an operational runbook for an alert/symptom; structured as TL;DR + Pre-checks + Steps + Verification + Rollback + Escalation.
rfc
Draft a lightweight design RFC to docs/rfcs/<slug>.md; Summary, Motivation, Detailed design, Drawbacks, Alternatives, Unresolved questions. A proposal to debate, not a recorded decision (adr).
editorial-pass
Review and tighten prose in a Markdown artifact for a target tone (terse, formal, friendly) without dropping information; preserve quotations and load-bearing constraints.
architecture-review-facilitation
Run an architecture review as a process — entry criteria, reviewer checklist, decision log, and follow-up actions — pairing the design artifact with a red-team pass.
architecture-doc
Write a C4-style architecture document; System Context + Containers (+ Components when interesting) with mermaid diagrams. Describes structure, not a decision (adr) or proposal (rfc).
adr
Write an Architecture Decision Record (Michael Nygard format) to docs/adrs/NNNN-<slug>.md; frontmatter validated by the ADR artifact schema. Records a made decision, not a proposal to debate (rfc).