PostgreSQL Field Guide
Production operationsProduction operations

Production operations

Operate PostgreSQL from explicit objectives, recoverability, and observability

Define objectives first

ObjectiveQuestion
RPOHow much data can be lost?
RTOHow quickly must service return?
CapacityWhat are peak connections and data/WAL/backup growth?
AvailabilityWhich failures auto-fail over, and which require judgment?
SecurityWho can connect, read which data, and perform which changes?

“High availability” and “we have backups” are not verifiable without targets.

Minimal daily view

SELECT now(), version();

SELECT state, count(*)
FROM pg_stat_activity
GROUP BY state
ORDER BY state;

SELECT datname, age(datfrozenxid)
FROM pg_database
ORDER BY age(datfrozenxid) DESC;

SELECT
  num_timed,
  num_requested,
  num_done,
  buffers_written,
  write_time,
  sync_time
FROM pg_stat_checkpointer;

SELECT buffers_clean, maxwritten_clean, buffers_alloc
FROM pg_stat_bgwriter;

Since PostgreSQL 17, checkpoint statistics live in pg_stat_checkpointer; background-writer statistics remain in pg_stat_bgwriter. See the PostgreSQL 18 cumulative statistics views for the field definitions.

Also monitor disk, WAL generation/archive, replication lag, backup state, transaction age, lock waits, query latency, autovacuum, and pool saturation. Thresholds come from this system's baseline.

Change discipline

  1. Measure lock and duration on representative data.
  2. Document rollback and the point of irreversibility.
  3. Set lock_timeout so a migration does not wait indefinitely then acquire a disruptive lock.
  4. Observe locks, WAL, replication lag, and errors during execution.
  5. Verify with queries and business signals.

Production DDL is not done when the command succeeds. It is an observable, interruptible, verified release.

Last updated on

On this page