From f085fbef4ecd31aed470d858e57e9ea3b8014493 Mon Sep 17 00:00:00 2001 From: Euler Taveira Date: Fri, 24 May 2024 14:18:15 -0300 Subject: [PATCH 3/4] Remove replication slot check on primary It used to check if the replication slot exists and is active on primary. This check might fail on slow hosts because the replication slot might not be active at the time of this check. The current code obtains the replication slot name from the primary_slot_name on standby and assumes the replication slot exists and is active on primary. If it doesn't exist, this tool will log an error and continue. --- src/bin/pg_basebackup/pg_createsubscriber.c | 53 ++------------------- 1 file changed, 5 insertions(+), 48 deletions(-) diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c index b42160c6c6..6d5127c45e 100644 --- a/src/bin/pg_basebackup/pg_createsubscriber.c +++ b/src/bin/pg_basebackup/pg_createsubscriber.c @@ -880,47 +880,6 @@ check_publisher(const struct LogicalRepInfo *dbinfo) pg_log_debug("publisher: max_wal_senders: %d", max_walsenders); pg_log_debug("publisher: current wal senders: %d", cur_walsenders); - /* - * If standby sets primary_slot_name, check if this replication slot is in - * use on primary for WAL retention purposes. This replication slot has no - * use after the transformation, hence, it will be removed at the end of - * this process. - */ - if (primary_slot_name) - { - PQExpBuffer str = createPQExpBuffer(); - char *psn_esc = PQescapeLiteral(conn, primary_slot_name, strlen(primary_slot_name)); - - appendPQExpBuffer(str, - "SELECT 1 FROM pg_catalog.pg_replication_slots " - "WHERE active AND slot_name = %s", - psn_esc); - - pg_free(psn_esc); - - pg_log_debug("command is: %s", str->data); - - res = PQexec(conn, str->data); - if (PQresultStatus(res) != PGRES_TUPLES_OK) - { - pg_log_error("could not obtain replication slot information: %s", - PQresultErrorMessage(res)); - disconnect_database(conn, true); - } - - if (PQntuples(res) != 1) - { - pg_log_error("could not obtain replication slot information: got %d rows, expected %d row", - PQntuples(res), 1); - disconnect_database(conn, true); - } - else - pg_log_info("primary has replication slot \"%s\"", - primary_slot_name); - - PQclear(res); - } - disconnect_database(conn, false); if (strcmp(wal_level, "logical") != 0) @@ -2105,12 +2064,7 @@ main(int argc, char **argv) /* Check if the standby server is ready for logical replication */ check_subscriber(dbinfo); - /* - * Check if the primary server is ready for logical replication. This - * routine checks if a replication slot is in use on primary so it relies - * on check_subscriber() to obtain the primary_slot_name. That's why it is - * called after it. - */ + /* Check if the primary server is ready for logical replication */ check_publisher(dbinfo); /* @@ -2152,7 +2106,10 @@ main(int argc, char **argv) */ setup_subscriber(dbinfo, consistent_lsn); - /* Remove primary_slot_name if it exists on primary */ + /* + * Remove primary_slot_name if it exists on primary. This replication slot + * has no use after the transformation. + */ drop_primary_replication_slot(dbinfo, primary_slot_name); /* Remove failover replication slots if it exists on subscriber */ -- 2.30.2