From 34540c6c40b6367f78aa710fe3a9c56ee5489738 Mon Sep 17 00:00:00 2001 From: Hayato Kuroda Date: Mon, 19 Feb 2024 04:32:35 +0000 Subject: [PATCH v24 09/18] prohibit to reuse publications --- src/bin/pg_basebackup/pg_createsubscriber.c | 38 +++++++-------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c index f10e8002c6..e88b29ea3e 100644 --- a/src/bin/pg_basebackup/pg_createsubscriber.c +++ b/src/bin/pg_basebackup/pg_createsubscriber.c @@ -1264,7 +1264,7 @@ create_publication(PGconn *conn, LogicalRepInfo *dbinfo) /* Check if the publication needs to be created */ appendPQExpBuffer(str, - "SELECT puballtables FROM pg_catalog.pg_publication " + "SELECT count(1) FROM pg_catalog.pg_publication " "WHERE pubname = '%s'", dbinfo->pubname); res = PQexec(conn, str->data); @@ -1275,34 +1275,20 @@ create_publication(PGconn *conn, LogicalRepInfo *dbinfo) PQresultErrorMessage(res)); } - if (PQntuples(res) == 1) + if (atoi(PQgetvalue(res, 0, 0)) == 1) { /* - * If publication name already exists and puballtables is true, let's - * use it. A previous run of pg_createsubscriber must have created - * this publication. Bail out. + * Unfortunately, if it reaches this code path, it will always + * fail (unless you decide to change the existing publication + * name). That's bad but it is very unlikely that the user will + * choose a name with pg_createsubscriber_ prefix followed by the + * exact database oid in which puballtables is false. */ - if (strcmp(PQgetvalue(res, 0, 0), "t") == 0) - { - pg_log_info("publication \"%s\" already exists", dbinfo->pubname); - return; - } - else - { - /* - * Unfortunately, if it reaches this code path, it will always - * fail (unless you decide to change the existing publication - * name). That's bad but it is very unlikely that the user will - * choose a name with pg_createsubscriber_ prefix followed by the - * exact database oid in which puballtables is false. - */ - pg_log_error("publication \"%s\" does not replicate changes for all tables", - dbinfo->pubname); - pg_log_error_hint("Consider renaming this publication."); - PQclear(res); - PQfinish(conn); - exit(1); - } + pg_log_error("publication \"%s\" already exists", dbinfo->pubname); + pg_log_error_hint("Consider renaming this publication."); + PQclear(res); + PQfinish(conn); + exit(1); } PQclear(res); -- 2.43.0