Scrivio Interview library
DebuggingFoundations7 min read · updated 13 November 2026

A PostgreSQL streaming replica was stopped for two days during a hardware repair. When it was started again, its log showed: FATAL: could not receive data from WAL stream: ERROR: requested WAL segment 000000010000004A000000C3 has already been removed.

What does this error mean, how do you get the replica back, and which settings decide how long a follower can be away?

The error means the primary has already recycled WAL segments the replica still needs: there was no replication slot holding them, and wal_keep_size covered far less than two days of writes. If WAL archiving is configured, we set restore_command on the replica so it fetches the missing segments from the archive and then resumes streaming; otherwise we rebuild it from a fresh base backup. How long a follower may be away is decided by wal_keep_size, by replication slots, by max_slot_wal_keep_size, which caps a slot's retention, and by the WAL archive.

Why this question is asked

Every team that runs PostgreSQL replicas meets this error sooner or later, usually after maintenance that took longer than planned. Interviewers ask about it because the fix is easy to look up but the trade-off behind it, keeping WAL for a replica versus protecting the primary's disk, is a real design decision. In this answer, we will recap how a standby streams WAL, read the error, get the replica back in two ways, and then go through the settings that decide how long a follower can be away, including the MySQL equivalent.

1A Quick Recap: How a Standby Streams WAL

PostgreSQL writes every change to the write-ahead log (WAL) before changing data files. The WAL lives in 16 MB segment files in pg_wal, with names like 000000010000004A000000C3: the first eight hex digits are the timeline, the rest encode the position. A streaming replica connects to the primary, says which position it has replayed, and the primary's WAL sender process reads segments from pg_wal and sends them.

After each checkpoint, the primary no longer needs old segments for its own crash recovery, so it removes or recycles them. Nothing in that decision automatically considers a replica that is switched off. It only keeps extra segments if a setting or a slot tells it to.

2Reading the Error

The message says that the replica asked for segment 000000010000004A000000C3, because that is where it stopped two days ago, and the primary replied that the segment has already been removed. The replica cannot skip it: every later change depends on the earlier ones being applied. So streaming cannot resume, and the replica will retry and fail forever.

Putting numbers on it makes the cause obvious. Suppose the primary writes about 30 GB of WAL per day. Two days of downtime means the replica needs 60 GB of WAL. If wal_keep_size was set to 1 GB, the primary kept only about 48 minutes of writes for standbys. The replica's gap was gone long before it came back.

3Getting the Replica Back

There are two paths, and which one we take depends on whether the WAL still exists anywhere. If the primary archives WAL, through archive_command or an archive_library such as a backup tool writing to object storage, the missing segments are in the archive. The replica can read them from there with restore_command, replay up to the present, and then switch back to streaming on its own.

Java
# postgresql.conf on the replica, using the archive written by the primary
restore_command = 'pgbackrest --stanza=main archive-get %f "%p"'
# or a plain copy: restore_command = 'cp /mnt/wal_archive/%f "%p"'
# restart the replica; in the log:
# LOG: restored log file "000000010000004A000000C3" from archive
# LOG: restored log file "000000010000004A000000C4" from archive
# ...
# LOG: started streaming WAL from primary at 4B/5A000000 on timeline 1
Step throughBringing a replica back after a long absence
  1. Replica asks for 4A/C3primary answers: segment already removed
  2. Is WAL archiving configured?
    YesSet restore_commandNoRebuild with pg_basebackup
  3. Replay segments from the archiveuntil the archive has no newer segment
  4. Resume streaming from the primarynow asking for a recent position
  5. Add monitoring for the next timeslot lag and archive age

5 steps in order. Play them, or step through them one at a time.

Notice that the standby moves between sources by itself: it replays from the archive while segments are there, and when the archive runs out it tries streaming again, which now works because it asks for a recent position the primary still has.

If there is no archive, the WAL is gone for good and the replica's data directory is useless as a replica. We rebuild it from a fresh base backup with pg_basebackup, this time creating a replication slot, which brings us to the settings.

4Which Settings Decide How Long a Follower Can Be Away

wal_keep_size tells the primary to keep at least that much WAL for standbys, regardless of who needs it. It is simple and safe for the primary's disk, but it is a fixed budget: with 30 GB of WAL per day, 1 GB covers under an hour and 64 GB covers about two days.

A physical replication slot is different in kind. The primary records the oldest position the slot's replica has not yet confirmed, and keeps every segment from there. The replica can be away for any length of time and still catch up, which would have prevented this incident. But there is a catch: if the replica never comes back, the primary keeps WAL forever, pg_wal grows until the disk is full, and a primary with a full WAL disk stops accepting writes.

max_slot_wal_keep_size bounds that risk. When a slot falls further behind than this size, the primary invalidates the slot and frees the WAL, which turns a full disk on the primary into a lost replica that needs rebuilding. That is almost always the better failure. Recent PostgreSQL versions also add a timeout for idle slots; check your version. Finally, the WAL archive extends the window further, limited only by how long we keep archived files.

Java
-- on the primary
ALTER SYSTEM SET max_slot_wal_keep_size = '200GB'; -- about six days at 30 GB per day
SELECT pg_reload_conf();
SELECT slot_name, active, wal_status,
pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS behind
FROM pg_replication_slots;
-- replica3 | f | extended | 58 GB -> alert: inactive and growing

The wal_status column moves from reserved to extended and then unreserved as a slot approaches the limit, and becomes lost once it is invalidated. Alerting on the bytes behind for inactive slots tells us about a dying replica long before it threatens the primary.

5The Same Trade-Off in MySQL

MySQL has the same problem with different names. The primary keeps binary logs for binlog_expire_logs_seconds, 30 days by default, and purges older ones. A replica that comes back and needs a purged binlog stops with an error saying the source has purged required binary logs, and it must be cloned again, for example with the clone plugin. MySQL has no slot equivalent that holds logs for a particular replica, so the retention period is the whole contract, and on busy servers that keep binlogs for less than 30 days to save disk, a long maintenance window can exceed it.

6Follow-up questions

What happens to the primary if a slot's replica never comes back?

Without a limit, the primary keeps every WAL segment from the slot's restart position, pg_wal grows by the whole write volume every day, and eventually the disk fills. When PostgreSQL cannot write WAL it stops accepting writes and may shut down, which is an outage of the primary caused by a replica that no longer exists. With max_slot_wal_keep_size set, the slot is invalidated instead, its wal_status becomes lost and the WAL is freed. Either way, an abandoned slot should be dropped with pg_drop_replication_slot once we know the replica is gone.

Should every replica have a slot?

For replicas we intend to keep, yes, together with max_slot_wal_keep_size and monitoring. It is the only way to survive long outages without an archive. For throwaway replicas, a slot is a liability, because forgetting to drop it can fill the primary's disk.

Is an archive a replacement for slots?

It is a complement. An archive also serves point-in-time recovery and lets replicas catch up from cheap storage instead of the primary's disk. Slots make streaming robust for short outages without reading from the archive.

7Conclusion

In this answer, we saw that the error means the primary recycled WAL the replica still needed, because nothing told it to keep two days of segments. With a WAL archive, restore_command lets the replica catch up and then stream again; without one, it must be rebuilt from a new base backup. wal_keep_size keeps a fixed amount, a replication slot keeps everything the replica has not confirmed, and max_slot_wal_keep_size protects the primary's disk from slots that never return. MySQL makes the same trade-off with binlog_expire_logs_seconds.

What to say in the interviewAbout 90 seconds aloud

Open with

The error means the replica asked the primary for a WAL segment, the one where it stopped two days ago, and the primary had already removed it. The primary recycles WAL after checkpoints, and nothing told it to keep more: there was no replication slot, and wal_keep_size was probably a gigabyte or so, which on a busy database covers less than an hour, not two days.

Then, if they want more

The replica cannot skip WAL, so it will never catch up on its own. If we archive WAL, I would set restore_command on the replica to fetch segments from the archive. It replays from there and switches back to streaming automatically once it reaches positions the primary still has. Without an archive, I rebuild the replica with pg_basebackup.

To decide how long a follower can be away, there are three tools. wal_keep_size keeps a fixed amount of WAL, so the window is that size divided by the write rate.

A physical replication slot keeps everything the replica has not confirmed, so it can be away indefinitely, but if it never returns the primary's disk fills and the primary stops. So I pair slots with max_slot_wal_keep_size, which invalidates a slot that falls too far behind, and alert on slot lag in bytes.

MySQL has the same trade-off with binlog_expire_logs_seconds, and a replica that needs a purged binlog must be cloned again.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What does this error mean, how do you get the replica back, and which settings decide...": https://scrivio-interview-library.netlify.app/architecture/partitioning-and-replication/9851d93dff/