Hi all, I recently hit an error with our streaming replication setup:
2025-07-14 11:52:59.361 CST,"replicator","",728458,"10.9.9.74:35724",68747f1b.b1d8a,1,"START_REPLICATION",2025-07-14 11:52:59 CST,3/0,0,ERROR,58P01,"requested WAL segment 00000001000000000000000C has already been removed",,,,,,"START_REPLICATION 0/C000000 TIMELINE 1",,,"standby","walsender",,0 It appears the requested WAL segment 00000001000000000000000C had already been archived, and I confirmed its presence in the archive directory. However, when the standby tried to request this file, the primary only searched for it in pg_wal and didn't check the archive directory. I had to manually copy the segment into pg_wal to get streaming replication working again. My question is: Can we make the primary automatically search the archive if restore_command is set? I found that Fujii Masao also requested this feature [1], but it seems there wasn't a consensus. I've attached a script to reproduce this issue. [1] https://www.postgresql.org/message-id/AANLkTinN%3DxsPOoaXzVFSp1OkfMDAB1f_d-F91xjEZDV8%40mail.gmail.com -- Regards, Japin Li
#!/bin/bash rm -rf /tmp/pgdata{1,2} /tmp/archive{1,2} mkdir -p /tmp/archive{1,2} initdb -k /tmp/pgdata1 cat <<EOF >>/tmp/pgdata1/postgresql.auto.conf listen_addresses = 'localhost' port = '9967' archive_mode = 'on' archive_command = 'cp %p /tmp/archive1/%f' restore_command = 'cp /tmp/archive1/%f %p' EOF pg_ctl -l 1.log -D /tmp/pgdata1 start pg_basebackup -h localhost -p 9967 -R -Fp -Xs -P -D /tmp/pgdata2 cat <<EOF >>/tmp/pgdata2/postgresql.auto.conf port = '9968' archive_command = 'cp %p /tmp/archive2/%f' restore_command = 'cp /tmp/archive2/%f %p' EOF pg_ctl -l 2.log -D /tmp/pgdata2 start psql postgres -p 9967 -xc 'SELECT * FROM pg_stat_replication' pgbench -i -s 10 -h localhost -p 9967 postgres pg_ctl -l 2.log -D /tmp/pgdata2 stop pg_ctl -l 1.log -D /tmp/pgdata1 stop pg_ctl -l 1.log -D /tmp/pgdata1 start pg_ctl -l 2.log -D /tmp/pgdata2 start psql postgres -p 9967 -xc 'SELECT * FROM pg_stat_replication'