Incident Response

PostgreSQL FATAL: the database system is starting up (and "in recovery mode")

PostgreSQL is alive but still replaying WAL, so it refuses new sessions. Here is what each startup message means in each version, how to see how long recovery will take, and why restarting it again usually makes things worse.

· 13 min read · AG Data Team

FATAL: the database system is starting up means the PostgreSQL server process is running, but it is not ready for normal sessions yet. Almost always it is replaying WAL: after a crash, after an unclean shutdown, or on a standby that has not caught up enough to serve reads. The server refuses the connection with SQLSTATE 57P03 (cannot_connect_now). Nothing is lost. The question is how long the replay will take and whether anything stops it.

$ psql -h db1 -U app appdb
psql: error: connection to server at "db1" (10.0.0.11), port 5432 failed:
FATAL:  the database system is starting up

Which message means what

All of these come from the connection startup code and depend on the state of the postmaster (postmaster.c). The wording changed between versions, which is why two servers in the same incident can show different texts.

Step 1: read the server log, not the client error

The client message tells you only that you have to wait. The server log tells you why and for how long. A normal crash recovery looks like this:

LOG:  database system was interrupted; last known up at 2026-11-24 07:58:12 UTC
LOG:  database system was not properly shut down; automatic recovery in progress
LOG:  redo starts at 3A/7C0012F8
LOG:  redo in progress, elapsed time: 10.01 s, current LSN: 3A/9F2210C0
LOG:  redo in progress, elapsed time: 20.01 s, current LSN: 3A/C4A81D48
LOG:  redo done at 3B/10F3E2A0 system usage: ...
LOG:  database system is ready to accept connections

The redo in progress lines appear on PostgreSQL 15 and later. They come from log_startup_progress_interval, which defaults to 10 seconds (release notes). Compare current LSN between two lines to get the replay speed, and compare it with the end of WAL to estimate the time left. On older versions you only get redo starts and, at the end, redo done.

If you see in recovery mode, scroll up to find the crash itself:

LOG:  server process (PID 48211) was terminated by signal 9: Killed
LOG:  terminating any other active server processes
LOG:  all server processes terminated; reinitializing

A backend killed by signal 9 is very often the Linux OOM killer. See our article on terminated by signal 9: Killed. Because restart_after_crash is on by default, PostgreSQL restarts by itself, and crash recovery follows. If the cause is still there, you get a loop: crash, recovery, crash again.

Step 2: check the cluster state from outside

pg_controldata reads the control file directly and works even when no one can connect:

$ sudo -u postgres pg_controldata /var/lib/postgresql/18/main | \
    grep -E 'cluster state|REDO location|Latest checkpoint location|Time of latest checkpoint'
Database cluster state:               in crash recovery
Latest checkpoint location:           3A/7D44A1B0
Latest checkpoint's REDO location:    3A/7C0012F8
Time of latest checkpoint:            Tue 24 Nov 2026 07:56:40 UTC

in crash recovery and in archive recovery mean replay is running. in production means the server finished recovery. For health checks, pg_isready returns exit code 1 when the server rejects connections, for example during startup, and 2 when there is no response at all:

$ pg_isready -h db1 -p 5432
db1:5432 - rejecting connections
$ echo $?
1

Exit code 1 means "alive, wait". Exit code 2 means "not running or not reachable". Your monitoring and your failover tool should treat them differently.

Do not restart a server that is in recovery. Each restart throws away the replay progress since the last checkpoint or restartpoint, and the next start replays that WAL again. In our experience, the most common way a 10-minute recovery becomes an hour is someone, or some automation, restarting the service every few minutes because it "is not responding".

Step 3: if it does not progress

  1. The LSN is moving but slowly. Replay is limited by storage. Watch the disk with iostat. You can only wait, or fail over to a replica if you have one.
  2. The log shows nothing for a long time before redo starts. Before crash recovery, PostgreSQL syncs all files in the data directory. The default recovery_init_sync_method is fsync, which opens every file. With hundreds of thousands of files this takes a long time. On Linux, syncfs (available since PostgreSQL 14) syncs whole file systems instead.
  3. A standby says "consistent recovery state has not been yet reached" for a long time. It needs more WAL. Check that primary_conninfo or restore_command works and that the required WAL still exists on the primary or in the archive.
  4. The server crashes again during recovery. Look for the reason in the log: no disk space for WAL, corrupt files, or the same memory problem. Fix that first. Restarting it again will not help.

What changes on large databases

On a small test instance, crash recovery takes seconds and nobody notices this message. On a busy multi-terabyte server, it can take a long time, and the same settings that make normal operation fast make recovery slow:

Key takeaways

PostgreSQL Errors Recovery High Availability
Work with us

Database stuck in recovery right now?

We help teams through long PostgreSQL crash recoveries and standby rebuilds, and tune checkpoints and failover so the next outage is minutes, not hours.

Get in touch More from the blog