mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-13 09:57:02 +08:00
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
This commit is contained in:
@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user