pgsql: Allow pg_receivewal to stream from a slot's restart LSN

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Allow pg_receivewal to stream from a slot's restart LSN
Date: 2021-10-26 00:47:44
Message-ID: E1mfAcy-0003sC-Kh@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Allow pg_receivewal to stream from a slot's restart LSN

Prior to this patch, when running pg_receivewal, the streaming start
point would be the current location of the archives if anything is
found in the local directory where WAL segments are written, and
pg_receivewal would fall back to the current WAL flush location if there
are no archives, as of the result of an IDENTIFY_SYSTEM command.

If for some reason the WAL files from pg_receivewal were moved, it is
better to try a restart where we left at, which is the replication
slot's restart_lsn instead of skipping right to the current flush
location, to avoid holes in the WAL backed up. This commit changes
pg_receivewal to use the following sequence of methods to determine the
starting streaming LSN:
- Scan the local archives.
- Use the slot's restart_lsn, if supported by the backend and if a slot
is defined.
- Fallback to the current flush LSN as reported by IDENTIFY_SYSTEM.

To keep compatibility with older server versions, we only attempt to use
READ_REPLICATION_SLOT if the backend version is at least 15, and
fallback to the older behavior of streaming from the current flush
LSN if the command is not supported.

Some TAP tests are added to cover this feature.

Author: Ronan Dunklau
Reviewed-by: Kyotaro Horiguchi, Michael Paquier, Bharath Rupireddy
Discussion: https://postgr.es/m/18708360.4lzOvYHigE@aivenronan

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f61e1dd2cee6b1a1da75c2bb0ca3bc72f18748c1

Modified Files
--------------
doc/src/sgml/ref/pg_receivewal.sgml | 11 ++++
src/bin/pg_basebackup/pg_receivewal.c | 31 ++++++++-
src/bin/pg_basebackup/streamutil.c | 97 ++++++++++++++++++++++++++++
src/bin/pg_basebackup/streamutil.h | 3 +
src/bin/pg_basebackup/t/020_pg_receivewal.pl | 53 ++++++++++++++-
5 files changed, 191 insertions(+), 4 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2021-10-26 01:19:53 Re: pgsql: Remove unused wait events.
Previous Message Thomas Munro 2021-10-26 00:16:18 pgsql: Reject huge_pages=on if shared_memory_type=sysv.