57P01FATALTier 2 — Caution✅ HIGH confidenceterminating connection due to administrator command
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
- 1pg_terminate_backend(pid) was called explicitly by a superuser
- 2The Postgres server is shutting down (SIGTERM or pg_ctl stop)
- 3idle_in_transaction_session_timeout fired and was configured to terminate rather than just cancel
- 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.
-- From an admin session:
SELECT pg_terminate_backend(12345); -- sends SIGTERM to backend 12345
-- The victim session receives:
-- FATAL: terminating connection due to administrator commandFix 1: Reconnect and retry the operation
When the termination was unintentional or a one-time event.
-- 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 openWhy 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
🔗 Related errors
📄 Reference pages