PostgreSQL Error 57P01 Admin Shutdown: What to Do
In this article
PostgreSQL error 57P01 (admin_shutdown) means the server is shutting down because an administrator or an automated process sent it a shutdown signal. It is not a corruption error and not a bug in your query: the database is being stopped on purpose, and any connection open at that moment is terminated. The fix is to find out who or what issued the shutdown, restart the service if it was unintended, and make sure your application reconnects cleanly. No configuration change is needed first, but you will want access to the server's logs and the ability to restart the PostgreSQL service.
What You'll Need
- Access to the machine running PostgreSQL (SSH or local terminal), or the managed database console if you use a cloud provider.
- Permission to read the PostgreSQL log file and, if needed, restart the service (typically a superuser or a user with sudo).
- The connection details your application uses, so you can confirm it recovers after the restart.
- Optionally, a way to view the operating system logs (for example journalctl on systemd-based Linux) to see who sent the signal.
Step-by-Step
- Confirm the error is 57P01 and note the timing. Look at the exact message your client or application received. It usually reads FATAL: terminating connection due to administrator command or the database system is shutting down, with SQLSTATE 57P01. Write down the timestamp; you will match it against logs in the next steps.
- Check whether the server is actually down. Try connecting with
psqlor your normal client. If you get a connection refused error, the service is stopped. If you can connect, the shutdown may have been a fast shutdown that already completed and the server restarted, or a single backend was terminated by an administrator. - Read the PostgreSQL log around the timestamp. The log location varies by installation and is set by
log_directoryandlogging_collectorinpostgresql.conf. Common paths include/var/log/postgresql/on Debian and Ubuntu, and the data directory'slogsubfolder on many source builds. Look for lines such as received fast shutdown request, received smart shutdown request, or received SIGTERM. That tells you the shutdown was deliberate rather than a crash. - Identify the source of the signal. On Linux with systemd, run
journalctl -u postgresql --since "10 minutes ago"(the unit name can differ, for examplepostgresql@16-main). Check for a package upgrade, a scheduled maintenance job, a cloud provider's maintenance event, or a person runningpg_ctl stoporsystemctl stop postgresql. On managed services, check the provider's maintenance and event history in its console. - Restart the service if the shutdown was unintended. On systemd systems use
sudo systemctl start postgresql(or the versioned unit name). On other setups usepg_ctl start -D /path/to/dataas the PostgreSQL OS user. Do not delete the postmaster.pid file unless the server refuses to start and you have confirmed no PostgreSQL process is running; deleting it while a server is alive can cause data corruption. - Verify the server accepts connections. Connect with
psql, runSELECT version();and checkpg_isready. Then confirm your application reconnects: most connection pools recover automatically, but some need a restart or a pool reset. - Prevent repeat surprises. If the shutdown came from a maintenance window, schedule application retries around it. If it came from a person or script, document the change process. If it came from the operating system's out-of-memory killer, the log will show a crash rather than a clean shutdown, and you should address memory settings instead.
Common Mistakes
- Assuming the database crashed. 57P01 is a clean administrative shutdown. Treating it as corruption leads people to run recovery tools they do not need.
- Deleting postmaster.pid too early. Only remove it after confirming no PostgreSQL process is running; otherwise a second server can start against the same data directory.
- Restarting repeatedly without reading logs. If a scheduled job or a failing health check keeps stopping the server, restarts will not help until the cause is removed.
- Ignoring application reconnect logic. A server that is back up does not mean your app recovered; stale pooled connections can keep failing until the pool is recycled.
- Confusing a smart shutdown with a fast one. A smart shutdown waits for clients to disconnect, so the server can appear hung for a long time; a fast shutdown terminates connections, which is what produces 57P01 in most clients.
Tips
- Set up log monitoring or alerting on the phrase shutdown request so you learn about maintenance before users do.
- Configure your connection pool with a short connection timeout and a retry policy so brief restarts are invisible to users.
- On managed services, use the provider's maintenance windows and read the event log; you usually cannot prevent the restart, only prepare for it.
- Keep PostgreSQL and its extensions updated through your package manager so planned restarts happen on your schedule.
- If you use
pg_ctlin scripts, preferfastmode for maintenance and avoidimmediateunless you must; immediate shutdown forces recovery on the next start.
Troubleshooting
The server will not start after the shutdown. Read the last lines of the log. A common cause is a stale postmaster.pid after an unclean stop, or a port already in use by another process. Confirm with ps aux | grep postgres and ss -ltnp | grep 5432 before changing anything.
Clients keep getting 57P01 in a loop. Something is repeatedly stopping the server, often a supervisor, a container orchestrator health check, or a cloud maintenance event. Correlate the timestamps with system logs and the orchestrator's event stream.
The application does not reconnect after the restart. Restart the application or reset its connection pool. Check that the connection string uses the correct host and port and that no failover to a replica is in progress.
You see 57P01 only for one session. An administrator may have run pg_terminate_backend() on that session. Check pg_stat_activity history if you log it, and review who has superuser access.
Frequently Asked Questions
Is 57P01 a data corruption error?
No. It indicates an administrative shutdown. Data integrity is preserved by PostgreSQL's shutdown process; corruption would show different errors and usually a crash in the log.
Does 57P01 mean I lost my data?
No. Committed transactions are durable. Uncommitted transactions in the terminated sessions are rolled back, which is normal.
Can I prevent 57P01 entirely?
You cannot prevent an administrator or provider from stopping the server, but you can make applications tolerate it with retries and connection pool recycling.
What is the difference between smart, fast and immediate shutdown?
Smart waits for clients to disconnect, fast terminates connections and shuts down cleanly, and immediate stops without waiting and forces crash recovery on the next start. Fast shutdown is what most clients see as 57P01.
Where is the PostgreSQL log file?
It depends on the installation. Check log_directory and logging_collector in postgresql.conf, or your package's default log path, such as /var/log/postgresql/ on Debian-based systems.
Does 57P01 affect replication?
A shutdown on the primary stops replication until it restarts. Replicas reconnect automatically if configured, but check replication lag after recovery.