Dear Robert, > > Just FYI - here is an extreme case. And note that I have applied proposed > > patch. > > > > When `pg_basebackup -D data_N2 -R` is used: > > ``` > > primary_conninfo = 'user=hayato ... dbname=hayato ... > > ``` > > > > But when `pg_basebackup -d "" -D data_N2 -R` is used: > > ``` > > primary_conninfo = 'user=hayato ... dbname=replication > > ``` > > It seems like maybe somebody should look into why this is happening, > and perhaps fix it.
I think this caused from below part [1] in GetConnection(). If both dbname and connection_string are the NULL, we will enter the else part and NULL would be substituted - {"dbnmae", NULL} key-value pair is generated only here. Then, in PQconnectdbParams()->PQconnectStartParams->pqConnectOptions2(), the strange part would be found and replaced to the username [2]. I think if both the connection string and the dbname are NULL, it should be considered as the physical replication connection. here is a patch to fix it. After the application, below two examples can output "dbname=replication". You can also confirm. ``` pg_basebackup -D data_N2 -U postgres pg_basebackup -D data_N2 -R -v -> primary_conninfo = 'user=postgres ... dbname=replication ... ``` [1] ``` else { keywords = pg_malloc0((argcount + 1) * sizeof(*keywords)); values = pg_malloc0((argcount + 1) * sizeof(*values)); keywords[i] = "dbname"; values[i] = dbname; i++; } ``` [2] ``` /* * If database name was not given, default it to equal user name */ if (conn->dbName == NULL || conn->dbName[0] == '\0') { free(conn->dbName); conn->dbName = strdup(conn->pguser); if (!conn->dbName) goto oom_error; } ``` Best Regards, Hayato Kuroda FUJITSU LIMITED https://www.fujitsu.com/
diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c index 56d1b15951..aea1ccba36 100644 --- a/src/bin/pg_basebackup/streamutil.c +++ b/src/bin/pg_basebackup/streamutil.c @@ -119,7 +119,7 @@ GetConnection(void) keywords = pg_malloc0((argcount + 1) * sizeof(*keywords)); values = pg_malloc0((argcount + 1) * sizeof(*values)); keywords[i] = "dbname"; - values[i] = dbname; + values[i] = dbname == NULL ? "replication" : dbname; i++; }