v22-0009-prohibit-to-reuse-publications.patch
application/octet-stream
Filename: v22-0009-prohibit-to-reuse-publications.patch
Type: application/octet-stream
Part: 8
Message:
RE: speed up a logical replica setup
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v22-0009
Subject: prohibit to reuse publications
| File | + | − |
|---|---|---|
| src/bin/pg_basebackup/pg_createsubscriber.c | 12 | 26 |
From b01c9e1d815a60748515566ecd7414f704e8712f Mon Sep 17 00:00:00 2001
From: Hayato Kuroda <kuroda.hayato@fujitsu.com>
Date: Mon, 19 Feb 2024 04:32:35 +0000
Subject: [PATCH v22 09/11] 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