From e546989a269d5d73d283901aadcfda8c6d98e87b Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Thu, 24 Oct 2024 14:40:23 +0300 Subject: Add 'no_error' argument to pg_wal_replay_wait() This argument allow skipping throwing an error. Instead, the result status can be obtained using pg_wal_replay_wait_status() function. Catversion is bumped. Reported-by: Michael Paquier Discussion: https://postgr.es/m/ZtUF17gF0pNpwZDI%40paquier.xyz Reviewed-by: Pavel Borisov --- doc/src/sgml/func.sgml | 56 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 834d0548cfc..7912fb711d3 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -28989,12 +28989,15 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset - Recovery Synchronization Procedure + Recovery Synchronization Procedure and Function - Procedure + Procedure or Function + + + Type Description @@ -29010,8 +29013,11 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset pg_wal_replay_wait ( target_lsn pg_lsn, - timeout bigint DEFAULT 0) - void + timeout bigint DEFAULT 0, + no_error bool DEFAULT false) + + + Procedure Waits until recovery replays target_lsn. @@ -29022,7 +29028,30 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset procedure waits until target_lsn is reached or the specified timeout has elapsed. On timeout, or if the server is promoted before - target_lsn is reached, an error is emitted. + target_lsn is reached, an error is emitted, + as soon as no_error is false. + If no_error is set to true, then the procedure + doesn't throw errors. The last result status could be read + with pg_wal_replay_wait_status. + + + + + + + pg_wal_replay_wait_status + + pg_wal_replay_wait_status () + text + + + Function + + + Returns the last result status for + pg_wal_replay_wait procedure. The possible + values are success, timeout, + and not in recovery. @@ -29044,7 +29073,8 @@ postgres=# SELECT '0/0'::pg_lsn + pd.segment_number * ps.setting::int + :offset pg_wal_replay_wait should be called on standby. If a user calls pg_wal_replay_wait on primary, it - will error out. However, if pg_wal_replay_wait is + will error out as soon as no_error is false. + However, if pg_wal_replay_wait is called on primary promoted from standby and target_lsn was already replayed, then pg_wal_replay_wait just exits immediately. @@ -29090,6 +29120,20 @@ postgres=# CALL pg_wal_replay_wait('0/306EE20', 100); ERROR: timed out while waiting for target LSN 0/306EE20 to be replayed; current replay LSN 0/306EA60 + The same example uses pg_wal_replay_wait with + no_error set to true. In this case, the result + status must be read with pg_wal_replay_wait_status. + + +postgres=# CALL pg_wal_replay_wait('0/306EE20', 100, true); +CALL +postgres=# SELECT pg_wal_replay_wait_status(); + pg_wal_replay_wait_status +--------------------------- + timeout +(1 row) + + -- cgit v1.2.3