Skip to content
CloudOps
Newsletter
All prompts
AI for Postgres Difficulty: Intermediate ClaudeChatGPTCursor

Postgres postgresql.conf Workload Tuning Prompt

Get a reviewed postgresql.conf tuning plan for your specific hardware and workload — memory, WAL/checkpoint, planner, and autovacuum settings explained one by one, with how to verify each took effect.

Target user
DBAs and SREs tuning a Postgres instance for a known workload
Difficulty
Intermediate
Tools
Claude, ChatGPT, Cursor

The prompt

You are a senior PostgreSQL DBA who tunes postgresql.conf from first principles for the
hardware and workload in front of you. You never paste a generic config; you reason each
setting from RAM, cores, storage, and the read/write mix, and you explain the trade-off.

I will paste:
- Hardware: total RAM, CPU cores, storage type (NVMe/SSD/network), and whether Postgres
  shares the box: [HARDWARE]
- Workload: OLTP vs analytics vs mixed, read/write ratio, peak concurrent connections,
  typical query shapes, dataset size vs RAM: [WORKLOAD]
- Postgres version and current relevant settings: [VERSION / CURRENT SETTINGS]
- Any symptoms (checkpoint spikes, OOMs, slow analytics, high I/O): [SYMPTOMS]

Produce a tuning plan, grouped and reasoned:

1. **Memory** — shared_buffers (from total RAM, accounting for OS cache), effective_cache_size
   (planner hint, not an allocation), and work_mem — and crucially that work_mem is PER sort/
   hash PER query, so total exposure ≈ work_mem × concurrent operations; size it against peak
   connections, not in isolation. maintenance_work_mem for index builds/vacuum.

2. **WAL & checkpoints** — wal_buffers, max_wal_size / min_wal_size and
   checkpoint_completion_target to spread checkpoint I/O and avoid write spikes; relate to
   the write rate and the symptoms.

3. **Planner & storage** — random_page_cost (lower for SSD/NVMe vs spinning disk),
   effective_io_concurrency, default_statistics_target for skewed columns, and
   max_parallel_workers_per_gather for analytics.

4. **Autovacuum & connections** — sane autovacuum_max_workers / cost settings for the write
   rate, max_connections vs a pooler, and which settings need a reload (SIGHUP) vs a restart.

For each setting: the recommended value, the reasoning, the trade-off, and how to verify
(SHOW <setting>, pg_stat_bgwriter for checkpoints, pg_stat_database, log_checkpoints).

Output format: a table [setting | current | recommended | why | reload or restart], grouped
by area, plus a short post-change validation checklist.

Guardrails: apply changes one group at a time and measure before the next — never paste a
whole new config blind. Several settings (shared_buffers, max_connections) require a restart;
schedule it. work_mem set too high can OOM the box under concurrency — size against peak
load. Test on staging with representative load before prod, and keep the human approving each
change.

Why this prompt works

Generic “tuned” configs are a trap: a value that helps a 4-core box with NVMe can OOM a shared host or starve an analytics workload. This prompt refuses the copy-paste and ties every setting back to the RAM, cores, storage, and read/write mix you actually have, so the recommendations are defensible rather than cargo-culted.

It also catches the single most dangerous misconception — that work_mem is a global budget. Because it’s allocated per sort and hash per query, a value that looks reasonable in isolation multiplies across concurrency and can take the machine down. Forcing the model to size memory against peak connections, and to spread checkpoint I/O rather than let it spike, addresses the settings that most often cause real incidents.

Grouping changes with explicit verification (SHOW, pg_stat_bgwriter, log_checkpoints) and a reload-versus-restart column turns the plan into a controlled rollout. The guardrails — one group at a time, staging first, restart windows scheduled — keep a human measuring and approving each step instead of applying a wholesale config and hoping.

Related prompts

Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week