52 runbooks across 22 operational domains

The PostgreSQL Cookbook

Full-incident runbooks for the failures single error pages can't cover — replication lag, autovacuum bloat, lock storms, failovers. Each one a complete diagnose → fix → verify playbook.

52recipes
22domains
14–18PG versions covered
Step-by-stepdiagnose → fix → verify

★ Recently added

Showing 52 of 52 recipes
Performance & Tuning

PostgreSQL Crash Due to OOM Kill

⚠️ Symptoms All active connections drop simultaneously with no individual query error — clients see disconnect errors (connection reset, FATAL: terminating connection…

5 steps ~20 min Diagnose → Fix → Verify
Locking & Concurrency

Advisory Lock Leakage — Dangling Locks

⚠️ Symptoms One or more application threads hang at the point where they call pg_advisory_lock — not on a database query, but…

5 steps ~15 min Diagnose → Fix → Verify
Performance & Tuning

Unused Indexes Consuming Space

Disk usage on a table is far larger than the data warrants; write throughput is lower than expected on a write-heavy table;…

5 steps ~10 min Diagnose → Fix → Verify
Schema & Constraints

Foreign Key Violation Adding Constraint With Orphans

A schema migration or ALTER TABLE ... ADD CONSTRAINT ... FOREIGN KEY statement fails with SQLSTATE 23503 and the message "violates foreign…

5 steps ~15 min Diagnose → Fix → Verify
Connections & Pooling

Pgbouncer Pool Exhaustion

Clients see connection acquisition or query latency spikes while the database CPU and lock graphs stay calm. The number of waiting application…

5 steps ~20 min Diagnose → Fix → Verify
Schema & Constraints

Relation Does Not Exist Search Path

An unqualified statement such as SELECT ... FROM orders raises 42P01 relation "orders" does not exist, while the exact same statement works…

5 steps ~10 min Diagnose → Fix → Verify
Data Types & Coercion

Date Time Field Value Out Of Range On Load

An INSERT ... SELECT that casts a text column to date stops with 'ERROR: date/time field value out of range: "25/01/2025"' and…

5 steps ~15 min Diagnose → Fix → Verify
Query Planning & Statistics

Stale Statistics Bad Query Plan

One specific query -- frequently a reporting or join query that touches a recently loaded table -- becomes dramatically slower with no…

5 steps ~15 min Diagnose → Fix → Verify
Performance & Tuning

Index Not Being Used

A query you expected to be fast is slow; EXPLAIN shows Seq Scan (often Parallel Seq Scan) with a Filter line instead…

5 steps ~15 min Diagnose → Fix → Verify
Storage & Data Integrity

Collation Version Mismatch Indexes Silently

Connections and queries that touch a text collation start logging a collation version mismatch WARNING -- often right after an apt/yum upgrade,…

5 steps ~30 min Diagnose → Fix → Verify
Replication & HA

Replication Lag Growing

Read queries routed to the standby return old data / miss recently-committed rows; pg_stat_replication.replay_lag on the primary keeps climbing (seconds,…

5 steps ~25 min Diagnose → Fix → Verify
Durability & Recovery

Unlogged Table Data Loss After Crash

After an unclean restart -- an OOM kill, a power loss, a kubelet SIGKILL, a `docker kill`, a crashed node -- one…

5 steps ~15 min Diagnose → Fix → Verify
Configuration & Tuning

Checkpoints Occurring Too Frequently

The log line 'checkpoints are occurring too frequently (N seconds apart)' with the HINT 'Consider increasing the configuration parameter "max_wal_size"',…

5 steps ~15 min Diagnose → Fix → Verify
Replication & HA

Replication Slot Wal Bloat

pg_wal grows without bound and disk usage climbs steadily; checkpoints complete but reclaim nothing. pg_replication_slots shows a slot with active = false…

5 steps ~20 min Diagnose → Fix → Verify
Query Performance

Jsonb Query Slow Without Gin Index

A jsonb filter is functionally correct but reads far more of the table than the result size justifies, and its latency scales…

5 steps ~15 min Diagnose → Fix → Verify
Schema & Indexing

Unindexed Foreign Key Slow Delete

A DELETE on a small parent table, or an UPDATE that changes its primary key, is unexpectedly slow and contended even though…

5 steps ~15 min Diagnose → Fix → Verify
Connections & Resource Limits

Connection Exhaustion

The application suddenly cannot get new connections; healthy queries on existing connections still work, but anything that opens a fresh connection fails…

5 steps ~15 min Diagnose → Fix → Verify
Maintenance & Vacuum

Table Bloat Dead Tuples

pg_relation_size / \dt+ shows a table far larger than the live data justifies (e.g. 40 MB for 200,000 small rows). Sequential scans…

5 steps ~15 min Diagnose → Fix → Verify
Concurrency & Locking

Deadlock Detected

An application transaction fails intermittently and abruptly with 'ERROR: deadlock detected' (SQLSTATE 40P01), usually under concurrency and usually on…

5 steps ~15 min Diagnose → Fix → Verify
Queries & Computation

Division By Zero In Rate Calculation

A previously reliable rate/ratio query or UPDATE suddenly fails with 22012 division_by_zero. The failure is all-or-nothing: because one statement computes…

5 steps ~15 min Diagnose → Fix → Verify
Maintenance & Autovacuum

Transaction Id Wraparound Risk

Writes still work and the server is quiet -- there is no 'must be vacuumed within N transactions' warning yet, which is…

5 steps ~20 min Diagnose → Fix → Verify
Schema & Data Types

Integer Primary Key Sequence Exhaustion

Writes to one table -- always the inserts, never the reads -- begin failing all at once with no deploy and no…

5 steps ~20 min Diagnose → Fix → Verify
Schema & Constraints

Not Null Constraint Add Column Contains Null Values

ALTER TABLE ... ALTER COLUMN ... SET NOT NULL fails with SQLSTATE 23502 and the message "column ... of relation ... contains…

5 steps ~15 min Diagnose → Fix → Verify
Maintenance & Vacuum

Tables Not Being Autovacuumed

Growing table/index bloat; queries slowing as dead tuples accumulate; pg_stat_user_tables shows a high n_dead_tup with last_autovacuum NULL (or very old)…

5 steps ~20 min Diagnose → Fix → Verify
Query Performance

Generic Plan Nested Loop Explosion

A parameterized query has wildly bimodal latency: fast (sub-millisecond to low-millisecond) for almost every bind value, then suddenly catastrophic --…

5 steps ~20 min Diagnose → Fix → Verify
Data Integrity

Duplicate Key From Out Of Sync Sequence

Inserts into a recently restored or bulk-loaded table fail with 'ERROR: duplicate key value violates unique constraint "_pkey"' and a DETAIL line…

5 steps ~15 min Diagnose → Fix → Verify
Schema & Constraints

Check Constraint Add Violated By Some Row

A CREATE/ALTER migration or a hand-run ALTER TABLE ... ADD CONSTRAINT ... CHECK (...) aborts with SQLSTATE 23514 and the message 'check…

5 steps ~15 min Diagnose → Fix → Verify
Data Types & Coercion

Function Round Double Precision Does Not Exist

Calling round (or another function) with two arguments on a floating-point value raises 'function round(double precision, integer) does not exist', with…

5 steps ~10 min Diagnose → Fix → Verify
Performance & Tuning

Find Your Slowest Queries With Pg Stat Statements

Elevated CPU or I/O with no single obvious culprit; p95 latency creeping up; a dashboard showing the database busy but no long-running…

5 steps ~10 min Diagnose → Fix → Verify
Concurrency & Locking

Table Level Lock Blocking Ddl Alter Table

A schema migration -- often a trivial-looking ALTER TABLE ... ADD COLUMN -- 'hangs', and within seconds the application in front of…

5 steps ~15 min Diagnose → Fix → Verify
Locking & Concurrency

Serialization Failure Error Could Not Serialize

Transactions under SERIALIZABLE isolation intermittently fail with 'ERROR: could not serialize access ...'; the failure appears only under concurrency and…

5 steps ~20 min Diagnose → Fix → Verify
Data Types & Coercion

Integer Out Of Range Arithmetic Overflow

An UPDATE, INSERT, SELECT, or aggregate that multiplies (or adds) integer values fails with SQLSTATE 22003 and 'integer out of range'. The…

5 steps ~15 min Diagnose → Fix → Verify
Maintenance & Autovacuum

Transaction Id Wraparound Approaching

Writes still work but every commit and the server log carry a rising-volume WARNING: 'database "postgres" must be vacuumed within 27484380 transactions',…

5 steps ~20 min Diagnose → Fix → Verify
Schema & Indexing

Add Index Concurrently Recover From Failed Cic

A CREATE INDEX CONCURRENTLY or CREATE UNIQUE INDEX CONCURRENTLY command ends with an ERROR rather than CREATE INDEX -- for a unique…

5 steps ~15 min Diagnose → Fix → Verify
Schema & Constraints

Column Does Not Exist Quoted Identifier Case

A query that looks obviously correct returns 'column "" does not exist', where the name in the message is the lowercased form…

5 steps ~10 min Diagnose → Fix → Verify
Queries & Computation

Subquery Returned More Than One Row

A SELECT, UPDATE, or INSERT that embeds a scalar subquery -- (SELECT ...) used where one value is expected, such as a…

5 steps ~15 min Diagnose → Fix → Verify
Query Performance

Work Mem External Sort Spill

A query that sorts, DISTINCTs, or hash-aggregates a large set is far slower than the row count suggests and generates heavy temporary-file…

5 steps ~15 min Diagnose → Fix → Verify
Schema & Constraints

Exclusion Constraint Conflicts With Existing Rows

Two related failures, both SQLSTATE 23P01. At schema-change time, ALTER TABLE ... ADD CONSTRAINT ... EXCLUDE ... fails with 'could not create…

5 steps ~20 min Diagnose → Fix → Verify
Performance

Disk Based Sort Spill

A specific query is much slower than its row count suggests, and slows further under concurrency. The data volume's free space drops…

5 steps ~15 min Diagnose → Fix → Verify
Maintenance

Long Transaction Blocking Vacuum

n_dead_tup for one or more tables stays high and climbs even though last_vacuum / last_autovacuum are recent. VACUUM completes 'successfully' but reclaims…

5 steps ~20 min Diagnose → Fix → Verify
Schema & Data Types

Value Too Long Varchar Truncation

An INSERT or UPDATE that used to succeed now fails with 'ERROR: value too long for type character varying(N)' and SQLSTATE 22001,…

5 steps ~10 min Diagnose → Fix → Verify
Configuration & Tuning

Statement Timeout Cancels Long Query

A statement that ran fine before now fails with SQLSTATE 57014 and the message 'canceling statement due to statement timeout'. It typically…

5 steps ~10 min Diagnose → Fix → Verify
Storage & Data Integrity

Pg Control File Corrupt

The whole instance is down and will not start. The postmaster log shows a single line at the top: 'FATAL: incorrect checksum…

5 steps ~20 min Diagnose → Fix → Verify
Data Types & Coercion

Value Too Long For Character Varying On Narrowing

A column narrowing (ALTER ... TYPE varchar(n) or char(n)), an INSERT/UPDATE, or a load into a width-limited column fails with SQLSTATE 22001…

5 steps ~15 min Diagnose → Fix → Verify
Schema & Constraints

Duplicate Key Creating Unique Index With Duplicate Rows

CREATE UNIQUE INDEX, ALTER TABLE ... ADD CONSTRAINT ... UNIQUE, or ALTER TABLE ... ADD PRIMARY KEY fails with SQLSTATE 23505 and…

5 steps ~15 min Diagnose → Fix → Verify
Transactions & Concurrency

Current Transaction Is Aborted Cascade

After one statement fails inside a transaction, every following statement returns 'current transaction is aborted, commands ignored until end of…

5 steps ~15 min Diagnose → Fix → Verify
Performance & Tuning

Index Bloat Identifying Candidates For Reindex

An index is much larger on disk than the table's live row count justifies; index-only and range scans are slower than they…

5 steps ~15 min Diagnose → Fix → Verify
Locking & Concurrency

Diagnosing A Blocked Query Queue

A group of identical or related queries all hang at once; pg_stat_activity shows several backends with wait_event_type = 'Lock' and state =…

5 steps ~20 min Diagnose → Fix → Verify
Storage & Data Integrity

Data File Corruption

A specific query errors out instantly with 'invalid page in block N of relation base//' and keeps erroring on every retry; the…

5 steps ~25 min Diagnose → Fix → Verify
Connections & Resource Limits

Idle In Transaction Sessions Accumulating

Connection count climbs and never falls back; new connections eventually fail with 'too many clients already'. pg_stat_activity shows many backends stuck…

5 steps ~15 min Diagnose → Fix → Verify
Data Types & Coercion

Invalid Input Syntax For Type Integer On Load

An ETL/import step, a column type change (ALTER ... TYPE integer USING ...), or an ad-hoc INSERT ... SELECT that casts text…

5 steps ~15 min Diagnose → Fix → Verify
Maintenance & Autovacuum

Multixact Wraparound Approaching

Writes still work but the server log and new-multixact creation carry a WARNING: 'database "postgres" must be vacuumed before 7483648 more MultiXactIds…

5 steps ~25 min Diagnose → Fix → Verify
Sev-1 Pro

Read any recipe free. Unlock the executed proof with Pro.

Every recipe gives you the diagnose-fix-verify arc for free. Pro adds the executed verification, catalog audits, and the cloud-provider notes for RDS, Azure & Cloud SQL.

  • The full verification step for every recipe — executed, not described.
  • Catalog & log queries that surface every at-risk object up front.
  • Cross-version gotchas across PostgreSQL 14–18.
  • Exactly where each symptom surfaces on managed Postgres.
$24.99/mo
or $199/yr — two months free
Unlock Pro
Cancel anytime · 14-day refund