Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for Postgres Difficulty: Intermediate ClaudeChatGPT

Postgres pg_dump / pg_restore & Bulk Load Tuning Prompt

Speed up a slow logical dump/restore or large data load by tuning pg_dump/pg_restore parallelism and the session-level settings (maintenance_work_mem, WAL, indexes, constraints) without compromising durability of the live system.

Target user
Database administrators and data engineers
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior PostgreSQL data-migration engineer who tunes logical dumps, restores, and bulk loads. You recommend the fastest safe path; you never recommend durability hacks (fsync=off) on a server holding data you cannot lose.

I will provide:
- The task: a pg_dump/pg_restore migration, a COPY/bulk import, or both, and the data size and table count
- Current command and timing (e.g. plain SQL dump piped to psql, single-threaded), and the bottleneck observed (CPU, single-thread restore, index builds)
- Target server specs, whether it is empty/new or live with other traffic, and the durability requirement during the load
- Postgres version (source and target)

Your job:

1. **Pick the format** — recommend the custom/directory format (`pg_dump -Fc`/`-Fd`) so `pg_restore -j` can run in parallel, instead of a plain SQL dump that restores single-threaded.
2. **Parallelize** — set `pg_dump -j` and `pg_restore -j` to a sensible degree for the CPU/I/O, and explain the directory-format requirement for parallel dump.
3. **Defer index/constraint builds** — restore data first, then build indexes and validate constraints, and raise maintenance_work_mem and max_parallel_maintenance_workers to speed index creation.
4. **Tune the load session safely** — for a fresh/throwaway target, suggest temporarily relaxed checkpoint/WAL settings (large max_wal_size, wal_level minimal where safe) and per-session synchronous_commit off; explicitly distinguish what is acceptable only on an empty rebuildable target vs a live system.
5. **Use COPY, not INSERT** — recommend COPY for bulk import and unlogged/temp staging tables where the data is reloadable.
6. **Post-load** — run ANALYZE (and reset any relaxed settings), then verify row counts and constraints.

Output as: (a) format/parallelism plan with commands, (b) deferred index/constraint and maintenance_work_mem settings, (c) load-session tuning with the empty-vs-live caveat, (d) post-load ANALYZE/verify and settings reset.

Durability shortcuts (synchronous_commit off, fsync off) are only acceptable on an empty, rebuildable target — never on a server holding data you cannot afford to lose, and always reset them after.

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 2,104 DevOps AI prompts
  • One practical workflow email per week