Hooks or another better way to track session objects

From: Roman Khapov <rkhapov(at)yandex-team(dot)ru>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Hooks or another better way to track session objects
Date: 2025-06-24 09:40:37
Message-ID: 82741750755647@mail.yandex-team.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers



Hi all!
 

I am working on a new type of pooling mechanism for Postgres


connection managers. In this mode, the client connection is


detached from server between transactions only if no temporary


objects were created in that session


(temporary tables, prepared statements, and advisory locks).
 

Currently, I am exploring ways to notify the connection manager


when any of these session-level objects are created or existing.


I got next ideas:


- send a status info byte in RFQ package, but that requires a


 protocol changes, so this option should be discarded, I suppose


- create an extension, that executes elog(NOTIFY, "some message") or


 sends dedicated package with smth like pq_putemptymessage('O') in new


 hook, that is called before RFQ sending (see POC patch in attachments)


- create an extension, that executes the same things as in option above,


 but uses more specialized hooks. For temporary tables I can use


 ProcessUtility_hook that already exists. For prepared statements and


 advisory locks I wasn't able to find a suitable hooks, so I add a hook


 before sending ParseComplete message and in LockAcquire end


 (see another POC patch in attachments)
 

I would appreciate any feedback on the general idea, advices on a clean way


to implement such notifications, and comments on the attached POC patches.


If you have ideas, experience with similar tasks, or suggestions for a


better (or more canonical) Postgres way to approach this, please let me know.
 

Thanks!

 

----

Best regards,

Roman Khapov.

 

Attachment Content-Type Size
unknown_filename text/html 3.1 KB
0001-dummy-hooks-for-parse-complete-and-lock-acquired.patch text/x-diff 3.2 KB
0001-dummy-RFQ-hook-impl.patch text/x-diff 1.6 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2025-06-24 09:42:46 Re: pg18: Virtual generated columns are not (yet) safe when superuser selects from them
Previous Message Nisha Moond 2025-06-24 09:37:28 Re: Logical Replication of sequences