The PostgreSQL administration field guideField notes · Runbooks · Free certification

Operational runbook · Quick reference

Writes are blocked

Map the lock chain, find the root transaction, and choose the least damaging way to restore progress.

blocked writeslock timeoutDDL stuckidle in transaction

Prerequisites

  • Confirm the target cluster, database, PostgreSQL major version, and your read-only access to the required statistics views.
  • Record the current user impact, incident owner, UTC timestamp, and a baseline before running diagnostics.

Safety boundary

Start with read-only observations. Do not restart, terminate, delete, fail over, or change configuration until ownership, blast radius, and an approved recovery path are explicit.

Establish impact

  1. Identify whether the blocked work is user traffic, maintenance, deployment DDL, or a background job.
  2. Measure the number and age of waiters and whether the queue is still growing.
  3. Locate the root blocker before cancelling any waiter.

Gather evidence

Diagnostic query

Map blocked sessions to blocker PIDs

Show each blocked backend, its blockers, and the ages needed to establish ownership and impact.

SELECT
  waiting.pid AS waiting_pid,
  pg_blocking_pids(waiting.pid) AS blocking_pids,
  waiting.application_name,
  now() - waiting.query_start AS waiting_for,
  now() - waiting.xact_start AS transaction_age,
  left(waiting.query, 160) AS waiting_query
FROM pg_stat_activity AS waiting
WHERE cardinality(pg_blocking_pids(waiting.pid)) > 0
ORDER BY waiting_for DESC;
low observation cost

Interpret the evidence

  • A blocker doing useful work may only need time; an abandoned idle transaction needs application ownership and a controlled rollback decision.
  • DDL near the front of a lock queue can make later compatible traffic wait behind it.

Take the safest useful action

  1. Contact the owner of the root transaction and determine rollback consequences.
  2. Use `pg_cancel_backend` when cancelling the current statement is sufficient; reserve termination for sessions whose transaction must be rolled back.
  3. Remove or postpone lock-heavy deployment work and add explicit lock timeouts before retrying.

Verification

  1. Repeat the baseline observation over a known interval and confirm that the measured queue or risk is moving in the intended direction.
  2. Verify the user-facing objective and every affected replica or dependency before closing or handing over the incident.

Rollback

Record the original state and rollback owner before acting. If verification worsens or the objective is missed, reverse only the bounded change, confirm the baseline is restored, and escalate with the before-and-after evidence.

Escalate when

  • Escalate before terminating a transaction that owns business-critical writes or when the blocking chain involves prepared transactions.

Study the underlying system

Refresh the assessed operating model

Version and review

Compatible versions
PostgreSQL 1618
Content version
2026.08
Reviewed
2026-08-04

Catalog columns, wait events, and operational controls can vary by PostgreSQL major version, extensions, and orchestration layer. Verify commands against the deployed version.

Sources