SQLSTATE 57P01 — admin_shutdown: FATAL terminating connection due to administrator command
! Symptoms Free
Conditions:
- Application errors:
FATAL: terminating connection due to administrator command - PostgreSQL log shows
LOG: connection received from ... terminated by administrator command - A DBA recently ran
pg_terminate_backend()orpg_ctl stop - Or a monitoring script with a broad filter killed sessions
1 Environment & reproduce Free
Difficulty: Beginner | PostgreSQL versions: 12, 13, 14, 15, 16, 17
? Root cause Free
pg_terminate_backend()sendsSIGTERM— the session getsFATAL: terminating connection due to administrator commandand the transaction is rolled back.pg_cancel_backend()is softer — sendsSIGINT, cancels only the current statement, connection stays open. Prefer this for active queries.- A DBA using
WHERE state = 'idle'kills ALL idle connections including healthy PgBouncer server-side connections — PgBouncer then reconnects, causing a connection storm. pg_ctl stop -m fastterminates all connections immediately. Use maintenance windows and notify applications first.pg_ctl stop -m smartwaits for all connections to finish — safer but may wait indefinitely.
Use pg_cancel_backend() instead of pg_terminate_backend() for active queries. Only terminate specific PIDs after manual review. Set idle_in_transaction_session_timeout to auto-kill stuck sessions without manual intervention.
2 Diagnose Free
RESULT-- Check who has pg_signal_backend privilege (can terminate connections): SELECT rolname, rolsuper FROM pg_roles WHERE rolsuper = true OR pg_has_role(rolname, 'pg_signal_backend', 'MEMBER') ORDER BY rolname; -- Check recent connection terminations in log: -- grep "terminating connection" $PGDATA/pg_log/postgresql-$(date +%Y-%m-%d).log -- Safe way to terminate only truly idle/stuck sessions: SELECT pid, usename, state, now() - query_start AS duration FROM pg_stat_activity WHERE state = 'idle in transaction' AND query_start < now() - INTERVAL '10 minutes' AND usename != 'postgres'; -- never kill postgres sessions blindly
🔒 Diagnose deeper Pro
Find every latent occurrence before it ships
The steps above clear this incident. Pro adds the executed, verified depth that stops the whole class of bug across your fleet.
- ✓Catalog & log queries that surface every at-risk object before a migration ships.
- ✓Inspect-without-running tricks (
\gdescand friends). - ✓Exactly where the log line surfaces on RDS, Azure & Cloud SQL.
- ✓Cross-version gotchas, verified on PostgreSQL 14–18.
Every Pro query on this site is executed against real PostgreSQL and verified — we never publish an untested snippet.
Already a member? Log in
3 Recovery & verify Free
Use pg_cancel_backend() instead of pg_terminate_backend() for active queries. Only terminate specific PIDs after manual review. Set idle_in_transaction_session_timeout to auto-kill stuck sessions without manual intervention.