// PostgreSQL error reference

PostgreSQL 57P01: terminating connection due to administrator

The server ended this session: an administrator called pg_terminate_backend, or the server is shutting down. Reconnect and retry.

SQLSTATE
57P01
Name
admin_shutdown
Category
Operator Intervention
Error message
terminating connection due to administrator command

What it means

57P01 (admin_shutdown) is sent as a FATAL error just before the server closes the connection. It happens when someone runs pg_terminate_backend() on the session, when the server is stopped with a fast shutdown, or when a managed service restarts or fails over the instance.

Any transaction that was in progress on the session is rolled back. The client's next use of the connection fails, so pools should discard it and open a new one.

Common causes

  • An administrator or a script ran pg_terminate_backend(pid), for example to clear idle sessions or locks.
  • The server is shutting down or restarting (pg_ctl stop -m fast, maintenance, upgrade).
  • A managed PostgreSQL service failed over or applied maintenance.

How to fix it

  1. Reconnect and, if the work was in a transaction, run the whole transaction again.

  2. Configure the connection pool to test connections or retry once on a new connection after this error.

  3. If sessions are being terminated unexpectedly, check the server log and any jobs that call pg_terminate_backend.

    SELECT pid, usename, query FROM pg_stat_activity WHERE query ILIKE '%pg_terminate_backend%';

Related errors

The code and message text are from the PostgreSQL documentation, Appendix A: PostgreSQL Error Codes. Browse the full PostgreSQL error list or search every database error.

// fewer errors, faster fixes

Work on PostgreSQL in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for PostgreSQL and the other databases you use.