RE: Hooks for session start and end, take two

From: "tsunakawa(dot)takay(at)fujitsu(dot)com" <tsunakawa(dot)takay(at)fujitsu(dot)com>
To: 'Michael Paquier' <michael(at)paquier(dot)xyz>
Cc: 'Andres Freund' <andres(at)anarazel(dot)de>, 'Fujii Masao' <masao(dot)fujii(at)gmail(dot)com>, 'Fabrízio de Royes Mello' <fabriziomello(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-12-20 02:45:26
Message-ID: OSAPR01MB507373499CCCEA00EAE79875FE2D0@OSAPR01MB5073.jpnprd01.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

From: Michael Paquier <michael(at)paquier(dot)xyz>
> Adding extra custom logging information, or plug that information
> elsewhere than Postgres. I have use cases for that when it comes to
> store external telemetry data or audit things for events happening
> specifically in Postgres.
>
> Well, hook authors can do a lot of stupid things.. Anyway it looks
> that the end hook is out of scope as far as the discussion has gone
> based on the lack of facility, and that there is still interest for
> the start hook.

I've got interested in this. What's the current status of this patch? The CF entry shows it was committed.

https://commitfest.postgresql.org/25/2251/

But I understood not, because the relevant code doesn't appear in HEAD, and Git log shows that it was reverted. Am I correct?

I'm thinking of using this feature to address an issue raised by a user who is considering migrating from Oracle. Oracle caches SQL execution plans in shared memory and enables any session to use them. He wants to hide the plan creation time from end users after database restart (perhaps the plan creation is slow.) To do that in Oracle, he runs possible SQL statements in a session solely for warm-up before resuming service for end users. Then, later new sessions of end users can use the cached execution plans.

Ideally, PostgreSQL should be able to share query plans among sessions without user intervention. But I guess it would be difficult. Instead, with this session start hook and the connection pooling, individual sessions can run possible SQL statements using PREPARE and EXECUTE once (forcing generic plans) at session start.

BTW, the user interface of the feature is unduly difficult for my use case and the use cases you mentioned. I think users should be able to use the feature only with SQL, without creating extensions. That also allows the use of this feature in DBaaS. How about creating a new event trigger type, connect trigger, after Oracle's logon trigger?

CREATE EVENT TRIGGER mytrigger
AFTER CONNECT [ON mydatabase]
EXECUTE {PROCEDURE | FUNCTION} myproc();

If some hacker wants to do what SQL can't, he can specify a UDF in C.

Regards
Takayuki Tsunakawa

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2019-12-20 02:48:13 Re: Is querying SPITupleTable with SQL possible?
Previous Message Bruce Momjian 2019-12-20 02:34:33 Re: Proposal: Global Index