aboutsummaryrefslogtreecommitdiff
path: root/src/fe_utils
diff options
context:
space:
mode:
authorAmit Kapila <akapila@postgresql.org>2024-03-21 10:48:59 +0530
committerAmit Kapila <akapila@postgresql.org>2024-03-21 10:50:33 +0530
commita145f424d5248a09d766e8cb503b999290cb3b31 (patch)
treec78c1df755ced2b228c5d1c4a4b18fa67ba16c95 /src/fe_utils
parent30e144287a72529c9cd9fd6b07fe96eb8a1e270e (diff)
downloadpostgresql-a145f424d5248a09d766e8cb503b999290cb3b31.tar.gz
postgresql-a145f424d5248a09d766e8cb503b999290cb3b31.zip
Allow dbname to be written as part of connstring via pg_basebackup's -R option.
Commit cca97ce6a665 allowed dbname in pg_basebackup connstring and in this commit we allow it to be written in postgresql.auto.conf when -R option is used. The database name in the connection string will be used by the logical replication slot synchronization on standby. The dbname will be recorded only if specified explicitly in the connection string or environment variable. Masahiko Sawada hasn't reviewed the code in detail but endorsed the idea. Author: Vignesh C, Kuroda Hayato Reviewed-by: Amit Kapila Discussion: https://postgr.es/m/CAB8KJ=hdKdg+UeXhReeHpHA6N6v3e0qFF+ZsPFHk9_ThWKf=2A@mail.gmail.com
Diffstat (limited to 'src/fe_utils')
-rw-r--r--src/fe_utils/recovery_gen.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/fe_utils/recovery_gen.c b/src/fe_utils/recovery_gen.c
index 63c78c986c7..733982a82f7 100644
--- a/src/fe_utils/recovery_gen.c
+++ b/src/fe_utils/recovery_gen.c
@@ -18,9 +18,14 @@ static char *escape_quotes(const char *src);
/*
* Write recovery configuration contents into a fresh PQExpBuffer, and
* return it.
+ *
+ * This accepts the dbname which will be appended to the primary_conninfo.
+ * The dbname will be ignored by walreciever process but slotsync worker uses
+ * it to connect to the primary server.
*/
PQExpBuffer
-GenerateRecoveryConfig(PGconn *pgconn, const char *replication_slot)
+GenerateRecoveryConfig(PGconn *pgconn, const char *replication_slot,
+ char *dbname)
{
PQconninfoOption *connOptions;
PQExpBufferData conninfo_buf;
@@ -66,6 +71,20 @@ GenerateRecoveryConfig(PGconn *pgconn, const char *replication_slot)
appendPQExpBuffer(&conninfo_buf, "%s=", opt->keyword);
appendConnStrVal(&conninfo_buf, opt->val);
}
+
+ if (dbname)
+ {
+ /*
+ * If dbname is specified in the connection, append the dbname. This
+ * will be used later for logical replication slot synchronization.
+ */
+ if (conninfo_buf.len != 0)
+ appendPQExpBufferChar(&conninfo_buf, ' ');
+
+ appendPQExpBuffer(&conninfo_buf, "%s=", "dbname");
+ appendConnStrVal(&conninfo_buf, dbname);
+ }
+
if (PQExpBufferDataBroken(conninfo_buf))
pg_fatal("out of memory");