[oauth] Per connection auth hooks in libpq

From: Andreas Karlsson <andreas(at)proxel(dot)se>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com>
Subject: [oauth] Per connection auth hooks in libpq
Date: 2026-02-26 23:35:31
Message-ID: 19f9da27-295d-4194-b38c-8e5142dfae4b@proxel.se
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

When implementing OAuth support in the PostgreSQL driver for Ruby[1] the
main pain point I ran into was that the PQauthDataHook is global which
does not work well at all given how Ruby supports multiple sub-instances
of the Ruby runtime (so called Ractors) plus that if you would load e.g.
Python and Ruby into the same process and both would use libpq they
would have to fight over the global hook.

So attached is a proof of concept patch which implements a
per-connection hook. It is just a rough patch to start a discussion. If
people like it I can clean it up and add tests and documentation.

Notes

1. See these two PRs: one which uses a per-runtime map and one which
uses a per-PGConn hash map. I am not a fan of either.

- https://github.com/ged/ruby-pg/pull/693
- https://github.com/ged/ruby-pg/pull/700

--
Andreas Karlsson
Percona

Attachment Content-Type Size
v1-0001-PoC-Add-support-for-per-connection-OAuth-hooks-to.patch text/x-patch 6.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Champion 2026-02-27 00:42:43 Re: [oauth] Per connection auth hooks in libpq
Previous Message Chao Li 2026-02-26 23:21:01 Re: typo in alter_table.sgml (was: Re: pgsql: Allow ALTER COLUMN SET EXPRESSION on virtual columns with CHECK)