From 95001dba4ed9c60d699338f3dc85ce836fe7d702 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Mon, 16 Sep 2024 21:35:06 +0300 Subject: [PATCH v2 2/2] Ensure standby promotion point in 043_wal_replay_wait.pl This commit ensures standby will be promoted at least at the primary insert LSN we have just observed. We use pg_switch_wal() to force the insert LSN to be written then wait for standby to catchup. Reported-by: Alexander Lakhin Discussion: https://postgr.es/m/1d7b08f2-64a2-77fb-c666-c9a74c68eeda%40gmail.com --- doc/src/sgml/func.sgml | 2 +- src/backend/access/transam/xlog.c | 2 +- src/test/recovery/t/043_wal_replay_wait.pl | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 84eb3a45eea..6f75bd0c7d2 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -29076,7 +29076,7 @@ postgres=# SELECT * FROM movie WHERE genre = 'Drama'; (0 rows) - It may also happen that target lsn is not achieved + It may also happen that target lsn is not reached within the timeout. In that case the error is thrown. diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index e96aa4d1cb1..853ab06812b 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -6168,7 +6168,7 @@ StartupXLOG(void) /* * Wake up all waiters for replay LSN. They need to report an error that - * recovery was ended before achieving the target LSN. + * recovery was ended before reaching the target LSN. */ WaitLSNSetLatches(InvalidXLogRecPtr); diff --git a/src/test/recovery/t/043_wal_replay_wait.pl b/src/test/recovery/t/043_wal_replay_wait.pl index b4801635d53..0b5f6e388e4 100644 --- a/src/test/recovery/t/043_wal_replay_wait.pl +++ b/src/test/recovery/t/043_wal_replay_wait.pl @@ -177,6 +177,12 @@ $psql_session->query_until( CALL pg_wal_replay_wait('${lsn4}'); ]); +# Make sure standby will be promoted at least at the primary insert LSN we +# have just observed. Use pg_switch_wal() to force the insert LSN to be +# written then wait for standby to catchup. +$node_primary->safe_psql('postgres', 'SELECT pg_switch_wal();'); +$node_primary->wait_for_catchup($node_standby); + $log_offset = -s $node_standby->logfile; $node_standby->promote; $node_standby->wait_for_log('recovery is not in progress', $log_offset); -- 2.39.5 (Apple Git-154)