RE: Have pg_basebackup write "dbname" in "primary_conninfo"?
От | Hayato Kuroda (Fujitsu) |
---|---|
Тема | RE: Have pg_basebackup write "dbname" in "primary_conninfo"? |
Дата | |
Msg-id | TYCPR01MB120773490B5DA550460066AD3F5572@TYCPR01MB12077.jpnprd01.prod.outlook.com обсуждение исходный текст |
Ответ на | Re: Have pg_basebackup write "dbname" in "primary_conninfo"? (Robert Haas <robertmhaas@gmail.com>) |
Ответы |
Re: Have pg_basebackup write "dbname" in "primary_conninfo"?
|
Список | pgsql-hackers |
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/
Вложения
В списке pgsql-hackers по дате отправления: