Re: Hooks for session start and end, take two

From: Mike Palmiotto <mike(dot)palmiotto(at)crunchydata(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Fabrízio de Royes Mello <fabriziomello(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, legrand legrand <legrand_legrand(at)hotmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Hooks for session start and end, take two
Date: 2019-10-03 15:39:33
Message-ID: CAMN686FXCPBMi-Bj=b9py2XKaV=iZVUXcTrwZEFmPodOxxWWEg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Oct 3, 2019 at 11:09 AM Andres Freund <andres(at)anarazel(dot)de> wrote:
>
> <snip>
> I think what would need to be designed is something more like
> RegisterXactCallback():
>
> /*
> * start- and end-of-transaction callbacks for dynamically loaded modules
> */
> typedef enum
> {
> XACT_EVENT_COMMIT,
> XACT_EVENT_PARALLEL_COMMIT,
> XACT_EVENT_ABORT,
> XACT_EVENT_PARALLEL_ABORT,
> XACT_EVENT_PREPARE,
> XACT_EVENT_PRE_COMMIT,
> XACT_EVENT_PARALLEL_PRE_COMMIT,
> XACT_EVENT_PRE_PREPARE
> } XactEvent;
>
> typedef void (*XactCallback) (XactEvent event, void *arg);
>
> extern void RegisterXactCallback(XactCallback callback, void *arg);
> extern void UnregisterXactCallback(XactCallback callback, void *arg);
>
>
> which would be called at various parts of a processes lifetime. Maybe
> something like:
>
> 1) shortly after process creation
> 2) shortly after shared memory attach
> 3) after database connection has been established
> 4) after database writes are possible (this excludes database-less walsenders)
> 5a) before closing database connection due to fatal error
> (with a note saying that no writes are ever allowed)
> 5b) before closing database connection due to normal exit
> (with a note saying that errors better be handled, and that no
> transaction may escape)
> 6) before shared memory detach
> 7) before final exit

This suggestion really resonates with me, as I had considered
something similar in the process centralization patchset (CF entry
linked upthread and discussion here:
https://www.postgresql.org/message-id/flat/CAMN686FE0OdZKp9YPO=htC6LnA6aW4r-+jq=3Q5RAoFQgW8EtA(at)mail(dot)gmail(dot)com).
It would be possible to build such a mechanism into that existing
architecture rather easily. Has anyone had a chance to review that
work?

Thanks,
--
Mike Palmiotto
https://crunchydata.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2019-10-03 15:51:41 Re: Transparent Data Encryption (TDE) and encrypted files
Previous Message Tomas Vondra 2019-10-03 15:24:37 Re: Regarding extension