What it means
FATAL means the server ended the whole session, not only the statement. “Administrator command”
means it was asked to, by a signal rather than an error in your query. There are two ways that
happens:
- Another session ran
pg_terminate_backend(<pid>)on yours. That needs membership in your session’s role, thepg_signal_backendrole, or superuser. - The server is shutting down in “fast” mode, which ends every session this way: a restart,
a configuration change that needs one, a failover,
pg_ctl stop,systemctl stop,docker stop, or a hosted provider’s maintenance.
Whatever your session had not committed is rolled back. The client notices when it next reads from the connection, so you see the message straight away during a running query, or with your next statement if you were idle:
FATAL: terminating connection due to administrator command
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
Over TLS, the last lines read SSL connection has been closed unexpectedly.
Neighbouring codes: 57P02 (terminating connection because of crash of another server process,
see server closed the connection unexpectedly)
and 57P03 (the database system is shutting down, … is starting up), which you get when trying
to connect at the wrong moment.
Common causes
- A person or script ended the session: a DBA clearing idle or blocking connections, a monitoring job, a “Terminate” button in an admin tool.
DROP DATABASE … WITH (FORCE)on the database you were connected to, which terminates its sessions first.- A server restart or failover: planned maintenance, a parameter change that needs a restart, a managed service moving to a new host, a container being stopped or redeployed.
- A pooler or proxy ending server connections it decided were too old or idle.
How to fix it
Reconnect and retry
The session can’t be recovered. Open a new connection and run the work again; anything in the interrupted transaction was rolled back, so a whole-transaction retry is safe. Connection pools should test connections before handing them out, so a dead one is replaced instead of failing your first query.
Find out which it was
The server log says. Each ended session is logged with the statement it was running:
FATAL: terminating connection due to administrator command
STATEMENT: SELECT pg_sleep(30)
A shutdown is announced first, with received fast shutdown request and aborting any active transactions, then the same FATAL line for each session. For a terminate with no shutdown nearby,
look for the pg_terminate_backend call: the log shows it only if statements are logged
(log_statement = 'all', or log_min_duration_statement = 0); otherwise check the tools and jobs
that manage connections.
If something keeps terminating you
Scripts that end idle sessions usually pick them by state and age from pg_stat_activity. Keep your
application’s transactions short and close idle connections from the pool side, so they aren’t the
ones being ended. If the cause is idle_in_transaction_session_timeout instead, the message says so:
see idle-in-transaction timeout.
Reproduce it
On PostgreSQL 18.6, session A runs SELECT pg_sleep(5); with \set VERBOSITY verbose. Session B
ends it:
SELECT pid, pg_terminate_backend(pid)
FROM pg_stat_activity
WHERE application_name = 'seo_err_pg_a' AND usename = 'inlet';
Session A:
FATAL: 57P01: terminating connection due to administrator command
LOCATION: ProcessInterrupts, postgres.c:3354
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
connection to server was lost
A session that was idle when it was terminated got the same message with its next statement. In a
throwaway PostgreSQL 18.6 container, docker stop (a fast shutdown) gave a session running
pg_sleep(30) the same FATAL, and the log showed received fast shutdown request and
aborting any active transactions first. Over TLS, DROP DATABASE shop WITH (FORCE) gave the
session connected to shop:
FATAL: terminating connection due to administrator command
SSL connection has been closed unexpectedly
connection to server was lost
In Inlet
Inlet’s Activity monitor lists the server’s sessions, shows which query blocks which, and can cancel a query or end a session (Pro); a session you end there sees this message. If Inlet’s own session is ended, Inlet shows the server’s error.