pgsql: Modularize log_connections output

Started by Melanie Plagemanover 1 year ago5 messagescomitters
Jump to latest
#1Melanie Plageman
melanieplageman@gmail.com

Modularize log_connections output

Convert the boolean log_connections GUC into a list GUC comprised of the
connection aspects to log.

This gives users more control over the volume and kind of connection
logging.

The current log_connections options are 'receipt', 'authentication', and
'authorization'. The empty string disables all connection logging. 'all'
enables all available connection logging.

For backwards compatibility, the most common values for the
log_connections boolean are still supported (on, off, 1, 0, true, false,
yes, no). Note that previously supported substrings of on, off, true,
false, yes, and no are no longer supported.

Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Fujii Masao <masao.fujii@oss.nttdata.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: /messages/by-id/flat/CAAKRu_b_smAHK0ZjrnL5GRxnAVWujEXQWpLXYzGbmpcZd3nLYw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9219093cab2607f34ac70612a65430a9c519157f

Modified Files
--------------
doc/src/sgml/config.sgml | 82 ++++++++++++-
src/backend/libpq/auth.c | 9 +-
src/backend/postmaster/postmaster.c | 1 -
src/backend/tcop/backend_startup.c | 161 +++++++++++++++++++++++++-
src/backend/utils/init/postinit.c | 3 +-
src/backend/utils/misc/guc_tables.c | 21 ++--
src/backend/utils/misc/postgresql.conf.sample | 8 +-
src/include/postmaster/postmaster.h | 1 -
src/include/tcop/backend_startup.h | 29 +++++
src/include/utils/guc_hooks.h | 2 +
src/test/authentication/t/001_password.pl | 38 ++++++
src/tools/pgindent/typedefs.list | 1 +
12 files changed, 331 insertions(+), 25 deletions(-)

#2Daniel Westermann (DWE)
daniel.westermann@dbi-services.com
In reply to: Melanie Plageman (#1)
Re: pgsql: Modularize log_connections output

Hi,

great, thanks for this. One question:

The current log_connections options are 'receipt', 'authentication', and
'authorization'. The empty string disables all connection logging. 'all'
enables all available connection logging.

... shouldn't this be added to tab completion as well?

postgres=# alter system set log_connections TO DEFAULT

postgres=# alter system set log_disconnections TO
0 1 DEFAULT FALSE NO OFF ON TRUE YES
postgres=# alter system set log_disconnections TO

Regards
Daniel

#3Melanie Plageman
melanieplageman@gmail.com
In reply to: Daniel Westermann (DWE) (#2)
Re: pgsql: Modularize log_connections output

Thanks for taking a look!

On Wed, Mar 12, 2025 at 11:50 AM Daniel Westermann (DWE)
<daniel.westermann@dbi-services.com> wrote:

great, thanks for this. One question:

The current log_connections options are 'receipt', 'authentication', and
'authorization'. The empty string disables all connection logging. 'all'
enables all available connection logging.

... shouldn't this be added to tab completion as well?

postgres=# alter system set log_connections TO DEFAULT

Because it is now a string GUC, there isn't a facility for tab
completion. Enum and boolean GUCs have a defined set of options which
can be provided as options for tab completion. Because string GUCs
don't have to have a set of defined options, they don't have tab
completion (AFAIK). For example, you couldn't have a defined set of
options for log_line_prefix.

There are a subset of the string GUCs that do have predefined options
which they validate in their check hooks. Many of these are GUCs which
can accept some combination of options -- so they don't fit well into
the enum GUC type (for example, debug_io_direct).

While writing this feature, I did consider if we should add a new GUC
type PGC_SET [1]/messages/by-id/CAAKRu_a5-7sUP+Q6YD5emQYS1w7ffBDUNf-NMbcxR-dpOdGehw@mail.gmail.com which would back GUCs that accept any subset of a
predefined set of options. This would allow us to have tab completion.
I didn't end up doing this because I felt tab completion was the only
advantage it would provide this patch and it would be a big code
change, but it is definitely something to consider in the future.

- Melanie

[1]: /messages/by-id/CAAKRu_a5-7sUP+Q6YD5emQYS1w7ffBDUNf-NMbcxR-dpOdGehw@mail.gmail.com

#4Daniel Gustafsson
daniel@yesql.se
In reply to: Melanie Plageman (#3)
Re: pgsql: Modularize log_connections output

On 12 Mar 2025, at 17:07, Melanie Plageman <melanieplageman@gmail.com> wrote:

Thanks for taking a look!

On Wed, Mar 12, 2025 at 11:50 AM Daniel Westermann (DWE)
<daniel.westermann@dbi-services.com> wrote:

great, thanks for this. One question:

The current log_connections options are 'receipt', 'authentication', and
'authorization'. The empty string disables all connection logging. 'all'
enables all available connection logging.

... shouldn't this be added to tab completion as well?

postgres=# alter system set log_connections TO DEFAULT

Because it is now a string GUC, there isn't a facility for tab
completion.

This GUC also cannot be changed within a session which makes tab completion
less useful.

--
Daniel Gustafsson

#5Daniel Westermann (DWE)
daniel.westermann@dbi-services.com
In reply to: Daniel Gustafsson (#4)
Re: pgsql: Modularize log_connections output

Hi,

On Wed, Mar 12, 2025 at 11:50 AM Daniel Westermann (DWE)
<daniel.westermann@dbi-services.com> wrote:

great, thanks for this. One question:

The current log_connections options are 'receipt', 'authentication', and

'authorization'. The empty string disables all connection logging. 'all'
enables all available connection logging.

... shouldn't this be added to tab completion as well?

postgres=# alter system set log_connections TO DEFAULT

Because it is now a string GUC, there isn't a facility for tab
completion.

Thank you both for the explanations.

Regards
Daniel