PG
PRO
57P01FATALTier 2 — Caution✅ HIGH confidence

terminating connection due to administrator command

Category: Operator InterventionVersions: All Postgres versions

What this means

An administrator called pg_terminate_backend() or issued a server shutdown, causing the backend to terminate the client connection. The current transaction is rolled back and the connection is closed.

Why it happens

  1. 1pg_terminate_backend(pid) was called explicitly by a superuser
  2. 2The Postgres server is shutting down (SIGTERM or pg_ctl stop)
  3. 3idle_in_transaction_session_timeout fired and was configured to terminate rather than just cancel
  4. 4A connection pool manager forcibly closed a backend that was idle too long

How to reproduce

An administrator terminates a backend session from another connection.

trigger — this will ERROR
-- From an admin session:
SELECT pg_terminate_backend(12345); -- sends SIGTERM to backend 12345

-- The victim session receives:
-- FATAL: terminating connection due to administrator command
FATAL: terminating connection due to administrator command server closed the connection unexpectedly

Fix 1: Reconnect and retry the operation

When the termination was unintentional or a one-time event.

fix
-- Application should catch SQLSTATE 57P01 and reconnect.
-- Before terminating active sessions, prefer pg_cancel_backend() for non-destructive cancellation:
SELECT pg_cancel_backend(12345); -- cancels current query, leaves connection open

Why this works

pg_cancel_backend() sends SIGINT to the backend, which cancels the current query and returns the connection to idle state. pg_terminate_backend() sends SIGTERM, which closes the connection entirely. Using cancel instead of terminate is less disruptive.

What not to do

Call pg_terminate_backend on all idle connections in a loop as a routine cleanup

Why it's wrong: Disrupts legitimate idle-in-transaction sessions and forces unnecessary reconnects; use idle_in_transaction_session_timeout instead for automatic cleanup.

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

📚 Feature docs: https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-ADMIN-SIGNAL

🔧 Source ref: src/backend/tcop/postgres.c — ProcessInterrupts()

📖 Further reading: Server Signalling Functions

Confidence assessment

✅ HIGH confidence

Well-documented and stable. The signal-handling pathway is consistent across all versions. Edge case: on Windows, Postgres uses named pipes for signalling rather than POSIX signals, but the observable behaviour from the client is identical.

See also

📄 Reference pages

pg_terminate_backendpg_cancel_backendServer Signalling
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →