Re: [PATCH] Add inline comments to the pg_hba_file_rules view

From: Jim Jones <jim(dot)jones(at)uni-muenster(dot)de>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, David Zhang <david(dot)zhang(at)highgo(dot)ca>
Subject: Re: [PATCH] Add inline comments to the pg_hba_file_rules view
Date: 2023-09-19 22:29:27
Message-ID: 51f69957-8420-8858-70fc-566ad20ee080@uni-muenster.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Michael

On 16.09.23 06:18, Michael Paquier wrote:
> That was the idea. I forgot about strpos(), but if you do that, do we
> actually need a function in core to achieve that?
I guess it depends who you ask :) I personally think it would be a good
addition to the view, as it would provide a more comprehensive look into
the hba file. Yes, the fact that it could possibly be written in SQL
sounds silly, but it's IMHO still relevant to have it by default.
> There are a few fancy cases with the SQL function you have sent,
> actually.. strpos() would grep the first '#' character, ignoring
> quoted areas.

Yes, you're totally right. I didn't take into account any token
surrounded by double quotes containing #.

v3 attached addresses this issue.

From the following hba:

 host db jim 192.168.10.1/32 md5 # foo
 host db jim 192.168.10.2/32 md5 #bar
 host db jim 192.168.10.3/32 md5 #     #foo#
 host "a#db" "a#user" 192.168.10.4/32 md5 # fancy #hba entry

We can get these records from the view:

 SELECT type, database, user_name, address, comment
 FROM pg_hba_file_rules
 WHERE address ~~ '192.168.10.%';

 type | database | user_name | address    |     comment
------+----------+-----------+--------------+------------------
 host | {db}     | {jim}     | 192.168.10.1 | foo
 host | {db}     | {jim}     | 192.168.10.2 | bar
 host | {db}     | {jim}     | 192.168.10.3 | #foo#
 host | {a#db}   | {a#user}  | 192.168.10.4 | fancy #hba entry

I am still struggling to find a way to enable this function in separated
path without having to read the conf file multiple times, or writing too
much redundant code. How many other conf files do you think would profit
from this feature?

Jim

Attachment Content-Type Size
v3-0001-Add-inline-comments-to-the-pg_hba_file_rules-view.patch text/x-patch 11.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2023-09-19 22:59:53 Re: [PATCH] Add native windows on arm64 support
Previous Message Robert Haas 2023-09-19 21:08:02 Re: Disabling Heap-Only Tuples