Diagnostic Queries
Symptoms
A connection attempt arrived while the server was shutting down. PostgreSQL refuses new connections with SQLSTATE 57P03 (cannot_connect_now).
- Seen during smart/fast shutdown or restart.
- Existing sessions may be finishing or being terminated.
- Transient until the server stops or restarts.
What the server log shows
FATAL: the database system is shutting down
Why PostgreSQL raises this — what the manual says
Section 18.5 Shutting Down the Server:
“The server disallows new connections and sends all existing server processes SIGTERM, which will cause them to abort their current transactions and exit promptly.”
Once shutdown begins, the postmaster stops accepting new connections so it can drain or terminate existing ones and stop cleanly. New attempts during this window are rejected with 57P03.
Common causes
- An operator initiated shutdown or restart.
- Automated maintenance/deploy restarting the server.
- Failover or orchestration stopping the instance.
How to fix it
- Retry after the restart completes; use exponential backoff.
- Coordinate deploys so clients expect brief unavailability.
- Front the database with a pooler that handles reconnects gracefully.
Related & next steps
Reference: PostgreSQL 18 Section 19.3 “Shutting Down the Server”.
Thanks — noted. This helps keep the database accurate.