PG
PRO
57P03FATALTier 3 — Handle with care✅ HIGH confidence

the database system is starting up

Category: Operator InterventionVersions: All Postgres versions

🔴 Production Risk Error

If 57P03 persists for an unusually long time (many minutes), it may indicate that WAL recovery is processing a large backlog or is stuck on a corrupt WAL segment. Monitor pg_last_wal_replay_lsn() progress and check server logs for recovery errors.

What this means

A client attempted to connect while Postgres is still in the startup/recovery phase and is not yet ready to accept connections. This is normal during server start or WAL replay after a crash and typically resolves on its own within seconds to minutes.

Why it happens

  1. 1Postgres server was just started and is still initialising shared memory or running startup checks
  2. 2Postgres is replaying WAL after an unclean shutdown (crash recovery)
  3. 3A standby replica is in recovery mode and has not reached a consistent state yet
  4. 4A pg_upgrade or pg_resetwal operation is in progress

How to reproduce

A connection is attempted immediately after server start before recovery is complete.

trigger — this will ERROR
-- Cannot be triggered by SQL; occurs at connection time.
-- Check recovery status once connected:
SELECT pg_is_in_recovery();
SELECT pg_last_wal_replay_lsn();
FATAL: the database system is starting up

Fix 1: Wait and retry the connection

Always — this is a transient condition that resolves when startup completes.

fix
-- Application retry logic: poll pg_isready or attempt connection with backoff.
-- From the command line:
-- pg_isready -h localhost -p 5432
-- Returns exit code 0 when the server is ready to accept connections.

Why this works

During startup the postmaster goes through several phases (shared memory init, WAL recovery, checkpoint). It only starts accepting client connections after the startup process exits and the postmaster enters its main loop. pg_isready probes the connection without completing the startup protocol, making it safe to poll.

What not to do

Immediately force-kill and restart Postgres when seeing 57P03

Why it's wrong: Interrupts WAL recovery, potentially leaving the database in a corrupt state that requires a more complex recovery.

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

📚 Feature docs: https://www.postgresql.org/docs/current/app-pg-isready.html

🔧 Source ref: src/backend/postmaster/postmaster.c — ServerLoop()

📖 Further reading: pg_isready

📖 Further reading: Backup and Recovery

Confidence assessment

✅ HIGH confidence

Well-documented and highly stable. The startup sequence has been consistent across all major versions. The pg_isready tool is the standard way to probe readiness in automation and container health checks.

See also

⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →