pgsql: Fix temporary WAL receiver slot handling on timeline switches

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix temporary WAL receiver slot handling on timeline switches
Date: 2026-08-27 16:18:42
Message-ID: E1wzcoK-00000002MgY-40FX@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix temporary WAL receiver slot handling on timeline switches

Previously, when wal_receiver_create_temp_slot was enabled, a timeline
switch could cause the walreceiver to try to create the same temporary
replication slot again on the same connection. The slot had already been
created before the first streaming attempt and still existed, so the
second creation attempt failed with a FATAL error such as
"could not create replication slot ...".

The walreceiver would later be restarted and streaming replication could
continue, so this did not permanently break replication. Nevertheless,
the unexpected failure is a bug and should be fixed.

Fix this by tracking whether the temporary replication slot has already
been created for the lifetime of the walreceiver and skipping subsequent
creation attempts. Also copy the retained slot name to shared memory on
each streaming attempt, since RequestXLogStreaming() clears it when
streaming is restarted without a configured primary slot. This also
keeps pg_stat_wal_receiver.slot_name populated after timeline switches.

Backpatch to all supported versions.

Author: ChangAo Chen <cca5507(at)qq(dot)com>
Reviewed-by: Quan Zongliang <quanzongliang(at)yeah(dot)net>
Reviewed-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Discussion: https://postgr.es/m/tencent_628FDAF814231923BC8E8357BBBC50F94207@qq.com
Backpatch-through: 14

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2bf6144b4e8f806f9a6934a5af3999c65b3504ff

Modified Files
--------------
src/backend/replication/walreceiver.c | 23 +++++++++++-----
src/test/recovery/t/004_timeline_switch.pl | 43 ++++++++++++++++++++++++++++++
2 files changed, 59 insertions(+), 7 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-08-27 16:18:53 pgsql: Fix temporary WAL receiver slot handling on timeline switches
Previous Message Fujii Masao 2026-08-27 16:18:31 pgsql: Fix temporary WAL receiver slot handling on timeline switches