Download

terminating connection due to administrator command

The server ended your session on purpose: someone or something called pg_terminate_backend() on it, or the server is shutting down or restarting. Your open transaction was rolled back. Reconnect and retry, then check the server log to see which it was.

PostgreSQL error 57P01· Tested on PostgreSQL 18.6· Updated 11 October 2026

FATAL:  terminating connection due to administrator command

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:

  1. Another session ran pg_terminate_backend(<pid>) on yours. That needs membership in your session’s role, the pg_signal_backend role, or superuser.
  2. 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

  1. A person or script ended the session: a DBA clearing idle or blocking connections, a monitoring job, a “Terminate” button in an admin tool.
  2. DROP DATABASE … WITH (FORCE) on the database you were connected to, which terminates its sessions first.
  3. 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.
  4. 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.

Inlet: a database client for the Mac

One native app for PostgreSQL, MySQL, SQL Server, SQLite, MongoDB and Redis. It explains errors where they happen, holds your edits until you save them, and keeps production read-only until you say so.

Version 0.1.0 · macOS 26 Tahoe or later · Apple silicon and Intel