Skip to content

Commit 03b08c8

Browse files
author
Amit Kapila
committed
pg_createsubscriber: Fix an unpredictable recovery wait time.
The problem is that the tool is using the LSN returned by pg_create_logical_replication_slot() as recovery_target_lsn. This LSN is ahead of the current WAL position and the recovery waits until the publisher writes a WAL record to reach the target and ends the recovery. On idle systems, this wait time is unpredictable and could lead to failure in promoting the subscriber. To avoid that, insert a harmless WAL record. Reported-by: Alexander Lakhin and Tom Lane Diagnosed-by: Hayato Kuroda Author: Euler Taveira Reviewed-by: Hayato Kuroda, Amit Kapila Backpatch-through: 17 Discussion: https://postgr.es/m/2377319.1719766794%40sss.pgh.pa.us Discussion: https://postgr.es/m/CA+TgmoYcY+Wb67NAwaHT7MvxCSeV86oSc+va9hHKaasE42ukyw@mail.gmail.com
1 parent c19615f commit 03b08c8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/bin/pg_basebackup/pg_createsubscriber.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,28 @@ setup_publisher(struct LogicalRepInfo *dbinfo)
778778
else
779779
exit(1);
780780

781+
/*
782+
* Since we are using the LSN returned by the last replication slot as
783+
* recovery_target_lsn, this LSN is ahead of the current WAL position
784+
* and the recovery waits until the publisher writes a WAL record to
785+
* reach the target and ends the recovery. On idle systems, this wait
786+
* time is unpredictable and could lead to failure in promoting the
787+
* subscriber. To avoid that, insert a harmless WAL record.
788+
*/
789+
if (i == num_dbs - 1 && !dry_run)
790+
{
791+
PGresult *res;
792+
793+
res = PQexec(conn, "SELECT pg_log_standby_snapshot()");
794+
if (PQresultStatus(res) != PGRES_TUPLES_OK)
795+
{
796+
pg_log_error("could not write an additional WAL record: %s",
797+
PQresultErrorMessage(res));
798+
disconnect_database(conn, true);
799+
}
800+
PQclear(res);
801+
}
802+
781803
disconnect_database(conn, false);
782804
}
783805

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy