pg_basebackup-write-dbname.v0001.patch
text/x-patch
Filename: pg_basebackup-write-dbname.v0001.patch
Type: text/x-patch
Part: 0
Patch
Format: unified
Series: patch v1
| File | + | − |
|---|---|---|
| src/fe_utils/recovery_gen.c | 5 | 1 |
| src/include/fe_utils/recovery_gen.h | 6 | 0 |
diff --git a/src/fe_utils/recovery_gen.c b/src/fe_utils/recovery_gen.c
index 2585f11939..de463f3956 100644
--- a/src/fe_utils/recovery_gen.c
+++ b/src/fe_utils/recovery_gen.c
@@ -49,12 +49,16 @@ GenerateRecoveryConfig(PGconn *pgconn, char *replication_slot)
{
/* Omit empty settings and those libpqwalreceiver overrides. */
if (strcmp(opt->keyword, "replication") == 0 ||
- strcmp(opt->keyword, "dbname") == 0 ||
strcmp(opt->keyword, "fallback_application_name") == 0 ||
(opt->val == NULL) ||
(opt->val != NULL && opt->val[0] == '\0'))
continue;
+ /* Omit "dbname" in PostgreSQL 16 and earlier. */
+ if (strcmp(opt->keyword, "dbname") == 0 &&
+ PQserverVersion(pgconn) < MINIMUM_VERSION_FOR_DBNAME_PARAM)
+ continue;
+
/* Separate key-value pairs with spaces */
if (conninfo_buf.len != 0)
appendPQExpBufferChar(&conninfo_buf, ' ');
diff --git a/src/include/fe_utils/recovery_gen.h b/src/include/fe_utils/recovery_gen.h
index ca2c4800d0..740d90c9d8 100644
--- a/src/include/fe_utils/recovery_gen.h
+++ b/src/include/fe_utils/recovery_gen.h
@@ -20,6 +20,12 @@
*/
#define MINIMUM_VERSION_FOR_RECOVERY_GUC 120000
+/*
+ * from version 17, there is a use-case for adding the dbname parameter
+ * to the generated "primary_conninfo" value
+ */
+#define MINIMUM_VERSION_FOR_DBNAME_PARAM 170000
+
extern PQExpBuffer GenerateRecoveryConfig(PGconn *pgconn,
char *replication_slot);
extern void WriteRecoveryConfig(PGconn *pgconn, char *target_dir,