Re: Hooks for session start and end, take two
Mike Palmiotto <mike.palmiotto@crunchydata.com>
From: Mike Palmiotto <mike.palmiotto@crunchydata.com>
To: Andres Freund <andres@anarazel.de>
Cc: Fabrízio de Royes Mello <fabriziomello@gmail.com>, Michael Paquier <michael@paquier.xyz>, Fujii Masao <masao.fujii@gmail.com>, legrand legrand <legrand_legrand@hotmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, Alvaro Herrera <alvherre@2ndquadrant.com>, Pgsql Hackers <pgsql-hackers@postgresql.org>
Date: 2019-10-03T15:39:33Z
Lists: pgsql-hackers
On Thu, Oct 3, 2019 at 11:09 AM Andres Freund <andres@anarazel.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@mail.gmail.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
Commits
-
Add hooks for session start and session end, take two
- e788bd924c19 13.0 landed