pgsql: Add support event triggers on authenticated login

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add support event triggers on authenticated login
Date: 2023-10-16 00:18:33
Message-ID: E1qsBJZ-000l5A-FT@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Add support event triggers on authenticated login

This commit introduces trigger on login event, allowing to fire some actions
right on the user connection. This can be useful for logging or connection
check purposes as well as for some personalization of environment. Usage
details are described in the documentation included, but shortly usage is
the same as for other triggers: create function returning event_trigger and
then create event trigger on login event.

In order to prevent the connection time overhead when there are no triggers
the commit introduces pg_database.dathasloginevt flag, which indicates database
has active login triggers. This flag is set by CREATE/ALTER EVENT TRIGGER
command, and unset at connection time when no active triggers found.

Author: Konstantin Knizhnik, Mikhail Gribkov
Discussion: https://postgr.es/m/0d46d29f-4558-3af9-9c85-7774e14a7709%40postgrespro.ru
Reviewed-by: Pavel Stehule, Takayuki Tsunakawa, Greg Nancarrow, Ivan Panchenko
Reviewed-by: Daniel Gustafsson, Teodor Sigaev, Robert Haas, Andres Freund
Reviewed-by: Tom Lane, Andrey Sokolov, Zhihong Yu, Sergey Shinderuk
Reviewed-by: Gregory Stark, Nikita Malakhov, Ted Yu

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e83d1b0c40ccda8955f1245087f0697652c4df86

Modified Files
--------------
doc/src/sgml/bki.sgml | 2 +-
doc/src/sgml/catalogs.sgml | 13 ++
doc/src/sgml/ecpg.sgml | 2 +
doc/src/sgml/event-trigger.sgml | 94 ++++++++++++
src/backend/commands/dbcommands.c | 17 ++-
src/backend/commands/event_trigger.c | 179 +++++++++++++++++++++--
src/backend/storage/lmgr/lmgr.c | 38 +++++
src/backend/tcop/postgres.c | 4 +
src/backend/utils/cache/evtcache.c | 2 +
src/backend/utils/init/globals.c | 2 +
src/backend/utils/init/postinit.c | 1 +
src/bin/pg_dump/pg_dump.c | 5 +
src/bin/psql/tab-complete.c | 4 +-
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_database.dat | 2 +-
src/include/catalog/pg_database.h | 3 +
src/include/commands/event_trigger.h | 1 +
src/include/miscadmin.h | 2 +
src/include/storage/lmgr.h | 2 +
src/include/tcop/cmdtaglist.h | 1 +
src/include/utils/evtcache.h | 3 +-
src/test/authentication/t/005_login_trigger.pl | 189 +++++++++++++++++++++++++
src/test/recovery/t/001_stream_rep.pl | 26 ++++
src/test/regress/expected/event_trigger.out | 45 ++++++
src/test/regress/sql/event_trigger.sql | 26 ++++
25 files changed, 644 insertions(+), 21 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Thomas Munro 2023-10-16 00:33:16 pgsql: Fix comment from commit 22655aa231.
Previous Message Noah Misch 2023-10-15 22:06:00 Re: pgsql: Dissociate btequalimage() from interval_ops, ending its deduplic

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2023-10-16 00:28:43 Re: interval_scale not work as expected?
Previous Message jian he 2023-10-16 00:00:00 interval_scale not work as expected?