Show inline comments from pg_hba lines in the pg_hba_file_rules view

From: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Show inline comments from pg_hba lines in the pg_hba_file_rules view
Date: 2023-08-31 22:01:37
Message-ID: 3fec6550-93b0-b542-b203-b0054aaee83b@uni-muenster.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Often we make changes in the pg_hba.conf and leave a #comment there,
just in case we forget why the change was done. To avoid having to open
the configuration file every time just to check the comments, it would
be quite nice to have the option to read these comments in the
pg_hba_file_rules view. Something like adding it in the end of the line
and wrapping it with characters like "", '', {}, [], etc

For instance, this pg_hba.conf ...

# TYPE  DATABASE        USER   ADDRESS         METHOD
local   all             all                    trust [foo]
host    all             all    127.0.0.1/32    trust
host    all             all    ::1/128         trust [bar]
local   replication     all                    trust
host    replication     all    127.0.0.1/32    trust
hostssl replication     all    ::1/128         cert map=abc [this will
fail :)]

... could be displayed like this

postgres=# SELECT type, database, user_name, address, comment, error
FROM pg_hba_file_rules ;
  type   |   database    | user_name |  address  | comment      | error
---------+---------------+-----------+-----------+-------------------+-----------------------------------------------------
 local   | {all}         | {all}     |           | foo               |
 host    | {all}         | {all}     | 127.0.0.1 |                   |
 host    | {all}         | {all}     | ::1       | bar               |
 local   | {replication} | {all}     | |                   |
 host    | {replication} | {all}     | 127.0.0.1 |                   |
 hostssl | {replication} | {all}     | ::1       | this will fail :) |
hostssl record cannot match because SSL is disabled
(6 rows)

I wrote a very quick&dirty PoC (attached) but before going any further I
would like to ask if there is a better way to read these comments using
SQL - or if it makes sense at all ;-)

Any feedback is much appreciated. Thanks!

Jim

Attachment Content-Type Size
hba-comments.diff text/x-patch 2.9 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Melanie Plageman 2023-08-31 22:29:29 Re: Eliminate redundant tuple visibility check in vacuum
Previous Message Daniel Gustafsson 2023-08-31 21:34:53 Re: Reducing connection overhead in pg_upgrade compat check phase