pg_createsubscriber: Remove replication slot check on primary
authorPeter Eisentraut <[email protected]>
Mon, 17 Jun 2024 08:48:17 +0000 (10:48 +0200)
committerPeter Eisentraut <[email protected]>
Mon, 17 Jun 2024 08:48:17 +0000 (10:48 +0200)
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.

Author: Euler Taveira <[email protected]>
Reviewed-by: Hayato Kuroda <[email protected]>
Discussion: https://www.postgresql.org/message-id/776c5cac-5ef5-4001-b1bc-5b698bc0c62a%40app.fastmail.com

src/bin/pg_basebackup/pg_createsubscriber.c

index f62f34b1a765ce89869f5c0a9ac3e9e14209feb1..fcb05ec656af00f48381d8fd944688c80313e9ba 100644 (file)
@@ -879,47 +879,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)
@@ -2061,12 +2020,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);
 
    /*