Thread

  1. Hooks or another better way to track session objects

    Roman Khapov <rkhapov@yandex-team.ru> — 2025-06-24T09:40:37Z

      
        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.