diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c index be679ebdff..8afaf7a12b 100644 --- a/src/bin/pg_basebackup/pg_createsubscriber.c +++ b/src/bin/pg_basebackup/pg_createsubscriber.c @@ -782,6 +782,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; }