Re: Have pg_basebackup write "dbname" in "primary_conninfo"?
Masahiko Sawada <sawada.mshk@gmail.com>
From: Masahiko Sawada <sawada.mshk@gmail.com>
To: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Cc: vignesh C <vignesh21@gmail.com>, Amit Kapila <amit.kapila16@gmail.com>, Robert Haas <robertmhaas@gmail.com>,
Ian Lawrence Barwick <barwick@gmail.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2024-03-20T14:25:22Z
Lists: pgsql-hackers
On Tue, Mar 19, 2024 at 8:48 PM Hayato Kuroda (Fujitsu) <kuroda.hayato@fujitsu.com> wrote: > > Dear Sawada-san, > > Thanks for giving comments! > > > This behavior makes sense to me. But do we want to handle the case of > > using environment variables too? > > Yeah, v5 does not consider which libpq parameters are specified by environment > variables. Such a variable should be used when the dbname is not expressly written > in the connection string. > Such a path was added in the v6 patch. If the dbname is not determined after > parsing the connection string, we call PQconndefaults() to get settings from > environment variables and service files [1], then start to search dbname again. > Below shows an example. Thank you for updating the patch! > > ``` > PGPORT=5431 PGUSER=kuroda PGDATABASE=postgres pg_basebackup -D data_N2 -R -v > -> > primary_conninfo = 'user=kuroda ... port=5431 ... dbname=postgres ... ' > ``` > > > IIUC, > > > > pg_basebackup -D tmp -d "user=masahiko dbname=test_db" > > > > is equivalent to: > > > > PGDATABASE="user=masahiko dbname=test_db" pg_basebackup -D tmp > > The case won't work. I think You assumed that expanded_dbname like > PQconnectdbParams() [2] can be used for enviroment variables, but it is not correct > - it won't parse as connection string again. > > In the libpq layer, connection parameters are parsed in PQconnectStartParams()->conninfo_array_parse(). > When expand_dbname is specified, the entry "dbname" is firstly checked and > parsed its value. They are done at fe-connect.c:5846. > > The environment variables are checked and parsed in conninfo_add_defaults(), which > is called from conninfo_array_parse(). However, it is done at fe-connect.c:5956 - the > expand_dbname has already been done at that time. This means there is no chance > that PGDATABASE is parsed as an expanded style. > Thank you for pointing it out. I tested the use of PGDATABASE with pg_basebackup and somehow missed the fact you explained. Regards, -- Masahiko Sawada Amazon Web Services: https://aws.amazon.com
Commits
-
Allow dbname to be written as part of connstring via pg_basebackup's -R option.
- a145f424d524 17.0 landed
-
Allow dbname in pg_basebackup/pg_receivewal connstring
- cca97ce6a665 17.0 cited