mirror of
https://github.com/postgres/postgres.git
synced 2025-09-11 00:12:06 +03:00
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
This commit is contained in:
@@ -57,6 +57,6 @@
|
||||
*/
|
||||
|
||||
/* yyyymmddN */
|
||||
#define CATALOG_VERSION_NO 202310141
|
||||
#define CATALOG_VERSION_NO 202310161
|
||||
|
||||
#endif
|
||||
|
@@ -16,7 +16,7 @@
|
||||
descr => 'default template for new databases',
|
||||
datname => 'template1', encoding => 'ENCODING',
|
||||
datlocprovider => 'LOCALE_PROVIDER', datistemplate => 't',
|
||||
datallowconn => 't', datconnlimit => '-1', datfrozenxid => '0',
|
||||
datallowconn => 't', dathasloginevt => 'f', datconnlimit => '-1', datfrozenxid => '0',
|
||||
datminmxid => '1', dattablespace => 'pg_default', datcollate => 'LC_COLLATE',
|
||||
datctype => 'LC_CTYPE', daticulocale => 'ICU_LOCALE',
|
||||
daticurules => 'ICU_RULES', datacl => '_null_' },
|
||||
|
@@ -49,6 +49,9 @@ CATALOG(pg_database,1262,DatabaseRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID
|
||||
/* new connections allowed? */
|
||||
bool datallowconn;
|
||||
|
||||
/* database has login event triggers? */
|
||||
bool dathasloginevt;
|
||||
|
||||
/*
|
||||
* Max connections allowed. Negative values have special meaning, see
|
||||
* DATCONNLIMIT_* defines below.
|
||||
|
@@ -56,6 +56,7 @@ extern void EventTriggerDDLCommandStart(Node *parsetree);
|
||||
extern void EventTriggerDDLCommandEnd(Node *parsetree);
|
||||
extern void EventTriggerSQLDrop(Node *parsetree);
|
||||
extern void EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason);
|
||||
extern void EventTriggerOnLogin(void);
|
||||
|
||||
extern bool EventTriggerBeginCompleteQuery(void);
|
||||
extern void EventTriggerEndCompleteQuery(void);
|
||||
|
@@ -203,6 +203,8 @@ extern PGDLLIMPORT Oid MyDatabaseId;
|
||||
|
||||
extern PGDLLIMPORT Oid MyDatabaseTableSpace;
|
||||
|
||||
extern PGDLLIMPORT bool MyDatabaseHasLoginEventTriggers;
|
||||
|
||||
/*
|
||||
* Date/Time Configuration
|
||||
*
|
||||
|
@@ -99,6 +99,8 @@ extern void UnlockDatabaseObject(Oid classid, Oid objid, uint16 objsubid,
|
||||
/* Lock a shared-across-databases object (other than a relation) */
|
||||
extern void LockSharedObject(Oid classid, Oid objid, uint16 objsubid,
|
||||
LOCKMODE lockmode);
|
||||
extern bool ConditionalLockSharedObject(Oid classid, Oid objid, uint16 objsubid,
|
||||
LOCKMODE lockmode);
|
||||
extern void UnlockSharedObject(Oid classid, Oid objid, uint16 objsubid,
|
||||
LOCKMODE lockmode);
|
||||
|
||||
|
@@ -186,6 +186,7 @@ PG_CMDTAG(CMDTAG_INSERT, "INSERT", false, false, true)
|
||||
PG_CMDTAG(CMDTAG_LISTEN, "LISTEN", false, false, false)
|
||||
PG_CMDTAG(CMDTAG_LOAD, "LOAD", false, false, false)
|
||||
PG_CMDTAG(CMDTAG_LOCK_TABLE, "LOCK TABLE", false, false, false)
|
||||
PG_CMDTAG(CMDTAG_LOGIN, "LOGIN", true, false, false)
|
||||
PG_CMDTAG(CMDTAG_MERGE, "MERGE", false, false, true)
|
||||
PG_CMDTAG(CMDTAG_MOVE, "MOVE", false, false, true)
|
||||
PG_CMDTAG(CMDTAG_NOTIFY, "NOTIFY", false, false, false)
|
||||
|
@@ -22,7 +22,8 @@ typedef enum
|
||||
EVT_DDLCommandStart,
|
||||
EVT_DDLCommandEnd,
|
||||
EVT_SQLDrop,
|
||||
EVT_TableRewrite
|
||||
EVT_TableRewrite,
|
||||
EVT_Login,
|
||||
} EventTriggerEvent;
|
||||
|
||||
typedef struct
|
||||
|
Reference in New Issue
Block a user