Add support event triggers on authenticated login
authorAlexander Korotkov <[email protected]>
Mon, 16 Oct 2023 00:16:55 +0000 (03:16 +0300)
committerAlexander Korotkov <[email protected]>
Mon, 16 Oct 2023 00:18:22 +0000 (03:18 +0300)
commite83d1b0c40ccda8955f1245087f0697652c4df86
treea71713272ad1fef3a8e331f0321ed82237f65dbc
parentc558e6fd92ffeb85d5f52e32ccbcf8a5b5eb7bf3
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
25 files changed:
doc/src/sgml/bki.sgml
doc/src/sgml/catalogs.sgml
doc/src/sgml/ecpg.sgml
doc/src/sgml/event-trigger.sgml
src/backend/commands/dbcommands.c
src/backend/commands/event_trigger.c
src/backend/storage/lmgr/lmgr.c
src/backend/tcop/postgres.c
src/backend/utils/cache/evtcache.c
src/backend/utils/init/globals.c
src/backend/utils/init/postinit.c
src/bin/pg_dump/pg_dump.c
src/bin/psql/tab-complete.c
src/include/catalog/catversion.h
src/include/catalog/pg_database.dat
src/include/catalog/pg_database.h
src/include/commands/event_trigger.h
src/include/miscadmin.h
src/include/storage/lmgr.h
src/include/tcop/cmdtaglist.h
src/include/utils/evtcache.h
src/test/authentication/t/005_login_trigger.pl [new file with mode: 0644]
src/test/recovery/t/001_stream_rep.pl
src/test/regress/expected/event_trigger.out
src/test/regress/sql/event_trigger.sql