agora inbox for pgsql-committers@postgresql.org
help / color / mirror / Atom feedpgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup(
4+ messages / 3 participants
[nested] [flat]
* pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup(
@ 2026-01-05 17:56 Alexander Korotkov <akorotkov@postgresql.org>
0 siblings, 0 replies; 4+ messages in thread
From: Alexander Korotkov @ 2026-01-05 17:56 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup()
When the standby is passed as a PostgreSQL::Test::Cluster instance,
use the WAIT FOR LSN command on the standby server to implement
wait_for_catchup() for replay, write, and flush modes. This is more
efficient than polling pg_stat_replication on the upstream, as the
WAIT FOR LSN command uses a latch-based wakeup mechanism.
The optimization applies when:
- The standby is passed as a Cluster object (not just a name string)
- The mode is 'replay', 'write', or 'flush' (not 'sent')
- The standby is in recovery
For 'sent' mode, when the standby is passed as a string (e.g., a
subscription name for logical replication), or when the standby has
been promoted, the function falls back to the original polling-based
approach using pg_stat_replication on the upstream.
Discussion: https://postgr.es/m/CABPTF7UiArgW-sXj9CNwRzUhYOQrevLzkYcgBydmX5oDes1sjg%40mail.gmail.com
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de>
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/f30848cb05d4d63e1a5a2d6a9d72604f3b63370d
Modified Files
--------------
src/test/perl/PostgreSQL/Test/Cluster.pm | 59 +++++++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup(
@ 2026-04-06 19:47 Alexander Korotkov <akorotkov@postgresql.org>
2026-04-07 11:50 ` Re: pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup( Peter Eisentraut <peter@eisentraut.org>
0 siblings, 1 reply; 4+ messages in thread
From: Alexander Korotkov @ 2026-04-06 19:47 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup()
When the standby is passed as a PostgreSQL::Test::Cluster instance,
use the WAIT FOR LSN command on the standby server to implement
wait_for_catchup() for replay, write, and flush modes. This is more
efficient than polling pg_stat_replication on the upstream, as the
WAIT FOR LSN command uses a latch-based wakeup mechanism.
The optimization applies when:
- The standby is passed as a Cluster object (not just a name string)
- The mode is 'replay', 'write', or 'flush' (not 'sent')
Rather than pre-checking pg_is_in_recovery() on the standby (which
would add an extra round-trip on every call), we issue WAIT FOR LSN
directly and handle the 'not in recovery' result as a signal to fall
back to polling.
For 'sent' mode, when the standby is passed as a string (e.g., a
subscription name for logical replication), when the standby has been
promoted, or when WAIT FOR LSN is interrupted by a recovery conflict,
the function falls back to the original polling-based approach using
pg_stat_replication on the upstream. The recovery conflict fallback
is necessary because some conflicts are unavoidable - for example,
ResolveRecoveryConflictWithTablespace() kills all backends
unconditionally, regardless of what they are doing.
The recovery conflict detection matches the English error message
"conflict with recovery", which is reliable because the test suite
runs with LC_MESSAGES=C.
Discussion: https://postgr.es/m/CABPTF7UiArgW-sXj9CNwRzUhYOQrevLzkYcgBydmX5oDes1sjg%40mail.gmail.com
Author: Xuneng Zhou <xunengzhou@gmail.com>
Reviewed-by: Alexander Korotkov <aekorotkov@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de>
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/7e8aeb9e483db48500987da8981a70b491b7844c
Modified Files
--------------
src/test/perl/PostgreSQL/Test/Cluster.pm | 108 ++++++++++++++++++++++++++++---
1 file changed, 100 insertions(+), 8 deletions(-)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup(
2026-04-06 19:47 pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup( Alexander Korotkov <akorotkov@postgresql.org>
@ 2026-04-07 11:50 ` Peter Eisentraut <peter@eisentraut.org>
2026-04-07 13:07 ` Re: pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup( Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 4+ messages in thread
From: Peter Eisentraut @ 2026-04-07 11:50 UTC (permalink / raw)
To: Alexander Korotkov <akorotkov@postgresql.org>; pgsql-committers@lists.postgresql.org
On 06.04.26 21:47, Alexander Korotkov wrote:
> Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup()
This change appears to have made the "make check-world" run
significantly slower. In some of my testing, this changed the total run
time from about 3min 30s to 4min 30s. (Obviously, the absolute numbers
will vary, but it's about a 25% increase.)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup(
2026-04-06 19:47 pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup( Alexander Korotkov <akorotkov@postgresql.org>
2026-04-07 11:50 ` Re: pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup( Peter Eisentraut <peter@eisentraut.org>
@ 2026-04-07 13:07 ` Andres Freund <andres@anarazel.de>
0 siblings, 0 replies; 4+ messages in thread
From: Andres Freund @ 2026-04-07 13:07 UTC (permalink / raw)
To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Alexander Korotkov <akorotkov@postgresql.org>; pgsql-committers@lists.postgresql.org
On 2026-04-07 13:50:03 +0200, Peter Eisentraut wrote:
> On 06.04.26 21:47, Alexander Korotkov wrote:
> > Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup()
>
> This change appears to have made the "make check-world" run significantly
> slower. In some of my testing, this changed the total run time from about
> 3min 30s to 4min 30s. (Obviously, the absolute numbers will vary, but it's
> about a 25% increase.)
Analyzed below https://postgr.es/m/1957514.1775526774%40sss.pgh.pa.us
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2026-04-07 13:07 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-01-05 17:56 pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup( Alexander Korotkov <akorotkov@postgresql.org>
2026-04-06 19:47 pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup( Alexander Korotkov <akorotkov@postgresql.org>
2026-04-07 11:50 ` Peter Eisentraut <peter@eisentraut.org>
2026-04-07 13:07 ` Andres Freund <andres@anarazel.de>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox