Add cleanup parsing contexts for pg_hba and pg_ident files

Started by Tofig Aliev2 months ago4 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliesbuild failedCI history

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t253134_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t253134_1 && git checkout t253134_1

Patchset v1 (message #1) is on t253134_1

Jump to latest
#1Tofig Aliev
t.aliev@postgrespro.ru

Hi, hackers!

Background processes calling load_hba()/load_ident() may see
undefined behavior because PostmasterContext is already gone.
This patch adds proper context cleanup to prevent this issue.

regards,
Tofig Aliev

Attachments:

t253134_1
0001-Add-cleanup-parsing-contexts-for-pg_hba-and-pg_ident.patchtext/x-diff; name=0001-Add-cleanup-parsing-contexts-for-pg_hba-and-pg_ident.patchDownload+25-5
#2Michael Paquier
michael@paquier.xyz
In reply to: Tofig Aliev (#1)
Re: Add cleanup parsing contexts for pg_hba and pg_ident files

On Tue, Jul 21, 2026 at 02:41:08PM +0700, Tofig Aliev wrote:

Background processes calling load_hba()/load_ident() may see
undefined behavior because PostmasterContext is already gone.
This patch adds proper context cleanup to prevent this issue.

Why would you want to do that? I don't necessarily object to a change
like that, just wondering why somebody would be interesting in calling
these APIs from a bgworker context.
--
Michael

#3Tofig Aliev
t.aliev@postgrespro.ru
In reply to: Michael Paquier (#2)
Re: Add cleanup parsing contexts for pg_hba and pg_ident files

Michael Paquier писал(а) 2026-07-21 14:54:

On Tue, Jul 21, 2026 at 02:41:08PM +0700, Tofig Aliev wrote:

Background processes calling load_hba()/load_ident() may see
undefined behavior because PostmasterContext is already gone.
This patch adds proper context cleanup to prevent this issue.

Why would you want to do that? I don't necessarily object to a change
like that, just wondering why somebody would be interesting in calling
these APIs from a bgworker context.
--
Michael

Michael, thank you for your answer.

This fix simply enables background processes to load pg_hba and pg_ident
files safely, without undefined behavior. This also includes processes
loaded through shared_preload_libraries, whose logic can be very
diverse.

regards,
Tofig Aliev

#4Andreas Karlsson
andreas.karlsson@percona.com
In reply to: Michael Paquier (#2)
Re: Add cleanup parsing contexts for pg_hba and pg_ident files

On 7/21/26 9:54 AM, Michael Paquier wrote:

On Tue, Jul 21, 2026 at 02:41:08PM +0700, Tofig Aliev wrote:

Background processes calling load_hba()/load_ident() may see
undefined behavior because PostmasterContext is already gone.
This patch adds proper context cleanup to prevent this issue.

Why would you want to do that? I don't necessarily object to a change
like that, just wondering why somebody would be interesting in calling
these APIs from a bgworker context.

I could imagine it could be useful if someone would want to implement
another frontend protocol, e.g. for emulating MongoDB, but still would
want to enforce the rules from the HBA file but as I have never tried to
build such a system I am not sure.

Andreas