From 483a500ad036168dc703208f3857e3b609db49ca Mon Sep 17 00:00:00 2001 From: Hayato Kuroda Date: Fri, 2 Feb 2024 09:31:16 +0000 Subject: [PATCH v15 4/6] Check whether the target is really standby --- src/bin/pg_basebackup/pg_createsubscriber.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c index 135bb3e111..9530b11816 100644 --- a/src/bin/pg_basebackup/pg_createsubscriber.c +++ b/src/bin/pg_basebackup/pg_createsubscriber.c @@ -842,6 +842,21 @@ check_subscriber(LogicalRepInfo *dbinfo) if (conn == NULL) exit(1); + /* The target server must be a standby */ + res = PQexec(conn, "SELECT pg_catalog.pg_is_in_recovery()"); + + if (PQresultStatus(res) != PGRES_TUPLES_OK) + { + pg_log_error("could not obtain recovery progress"); + return false; + } + + if (strcmp(PQgetvalue(res, 0, 0), "t") != 0) + { + pg_log_error("The target server was not a standby"); + return false; + } + /* * Subscriptions can only be created by roles that have the privileges of * pg_create_subscription role and CREATE privileges on the specified -- 2.43.0