terminating connection due to administrator command
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.
- 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
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 command
expected output
FATAL: terminating connection due to administrator command server closed the connection unexpectedly
Fix
Reconnect and retry the operation
WHEN 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 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.
✕ Call pg_terminate_backend on all idle connections in a loop as a routine cleanup
Disrupts legitimate idle-in-transaction sessions and forces unnecessary reconnects; use idle_in_transaction_session_timeout instead for automatic cleanup.
src/backend/tcop/postgres.c — ProcessInterrupts()
Server Signalling Functions ↗Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev