From e66878760f87687c072a3ff902cba3bfed298b15 Mon Sep 17 00:00:00 2001 From: Hayato Kuroda Date: Wed, 3 Jul 2024 04:53:26 +0000 Subject: [PATCH v2 1/3] emit dummy message while setting up the publisher --- src/bin/pg_basebackup/pg_createsubscriber.c | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c index 21dd50f808..499f26cf38 100644 --- a/src/bin/pg_basebackup/pg_createsubscriber.c +++ b/src/bin/pg_basebackup/pg_createsubscriber.c @@ -781,6 +781,32 @@ setup_publisher(struct LogicalRepInfo *dbinfo) disconnect_database(conn, false); } + /* + * pg_create_logical_replication_slot () returns the end of the + * RUNNING_XACT record. If we use the returned value as recovery_target_lsn + * as-is, however, we must wait for additional WAL generation because the + * parameter requires that the replicated WAL overtake a certain point. + * Insert a dummy WAL record to avoid unnecessary waits. + */ + if (!dry_run) + { + PGconn *conn; + PGresult *res = NULL; + + conn = connect_database(dbinfo[0].pubconninfo, true); + + /* Insert dummy data to WAL to move forward the WAL record */ + res = PQexec(conn, + "SELECT pg_catalog.pg_logical_emit_message(true, 'pg_createsubscriber', 'dummy data', true);"); + + if (PQresultStatus(res) != PGRES_TUPLES_OK) + { + pg_log_error("could not run CHECKPOINT: %s", + PQresultErrorMessage(res)); + disconnect_database(conn, true); + } + } + return lsn; } -- 2.43.0