Diagnostic Queries
Symptoms
The session was forcibly terminated by an administrator (or by pg_terminate_backend()), or as part of a server operation. PostgreSQL raises SQLSTATE 57P01 (admin_shutdown) and the connection closes.
- Unlike a cancel, the whole connection is dropped.
- Often issued to clear a stuck or idle-in-transaction session.
- The client must reconnect.
What the server log shows
FATAL: terminating connection due to administrator command
Why PostgreSQL raises this — what the manual says
Section 9.28.2 Server Signaling Functions:
“Terminates the session whose backend process has the specified process ID.”
A terminate request signals the target backend to exit. The backend rolls back any open transaction and closes the connection, reporting 57P01 to the client. This also occurs during certain shutdown/restart scenarios.
Common causes
- An admin ran
pg_terminate_backend(pid). - A connection killed for being idle-in-transaction too long.
- Server restart/failover dropping existing sessions.
How to fix it
- Reconnect and retry; make the application resilient to dropped connections.
- Investigate why the session was terminated (long idle, blocking others).
- Use connection pooling that transparently re-establishes sessions.
Related & next steps
Reference: PostgreSQL 18 Section 9.28 “System Administration Functions”.
Thanks — noted. This helps keep the database accurate.