Обсуждение: pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup(

Поиск
Список
Период
Сортировка

pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup(

От
Alexander Korotkov
Дата:
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(-)


Re: pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup(

От
Peter Eisentraut
Дата:
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.)




Re: pgsql: Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup(

От
Andres Freund
Дата:
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