PostgreSQL Source Code git master
Loading...
Searching...
No Matches
event_trigger.c File Reference
#include "postgres.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/table.h"
#include "access/xact.h"
#include "catalog/catalog.h"
#include "catalog/dependency.h"
#include "catalog/indexing.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_attrdef.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_auth_members.h"
#include "catalog/pg_database.h"
#include "catalog/pg_event_trigger.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_parameter_acl.h"
#include "catalog/pg_policy.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_tablespace.h"
#include "catalog/pg_trigger.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_type.h"
#include "commands/event_trigger.h"
#include "commands/extension.h"
#include "commands/trigger.h"
#include "funcapi.h"
#include "lib/ilist.h"
#include "miscadmin.h"
#include "parser/parse_func.h"
#include "pgstat.h"
#include "storage/lmgr.h"
#include "tcop/deparse_utility.h"
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/evtcache.h"
#include "utils/fmgroids.h"
#include "utils/fmgrprotos.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
#include "utils/tuplestore.h"
Include dependency graph for event_trigger.c:

Go to the source code of this file.

Data Structures

struct  EventTriggerQueryState
 
struct  SQLDropObject
 

Typedefs

typedef struct EventTriggerQueryState EventTriggerQueryState
 
typedef struct SQLDropObject SQLDropObject
 

Functions

static void AlterEventTriggerOwner_internal (Relation rel, HeapTuple tup, Oid newOwnerId)
 
static void error_duplicate_filter_variable (const char *defname)
 
static Datum filter_list_to_array (List *filterlist)
 
static Oid insert_event_trigger_tuple (const char *trigname, const char *eventname, Oid evtOwner, Oid funcoid, List *taglist)
 
static void validate_ddl_tags (const char *filtervar, List *taglist)
 
static void validate_table_rewrite_tags (const char *filtervar, List *taglist)
 
static void EventTriggerInvoke (List *fn_oid_list, EventTriggerData *trigdata)
 
static bool obtain_object_name_namespace (const ObjectAddress *object, SQLDropObject *obj)
 
static const charstringify_grant_objtype (ObjectType objtype)
 
static const charstringify_adefprivs_objtype (ObjectType objtype)
 
static void SetDatabaseHasLoginEventTriggers (void)
 
Oid CreateEventTrigger (CreateEventTrigStmt *stmt)
 
Oid AlterEventTrigger (AlterEventTrigStmt *stmt)
 
ObjectAddress AlterEventTriggerOwner (const char *name, Oid newOwnerId)
 
void AlterEventTriggerOwner_oid (Oid trigOid, Oid newOwnerId)
 
Oid get_event_trigger_oid (const char *trigname, bool missing_ok)
 
static bool filter_event_trigger (CommandTag tag, EventTriggerCacheItem *item)
 
static CommandTag EventTriggerGetTag (Node *parsetree, EventTriggerEvent event)
 
static ListEventTriggerCommonSetup (Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata, bool unfiltered)
 
void EventTriggerDDLCommandStart (Node *parsetree)
 
void EventTriggerDDLCommandEnd (Node *parsetree)
 
void EventTriggerSQLDrop (Node *parsetree)
 
void EventTriggerOnLogin (void)
 
void EventTriggerTableRewrite (Node *parsetree, Oid tableOid, int reason)
 
bool EventTriggerSupportsObjectType (ObjectType obtype)
 
bool EventTriggerSupportsObject (const ObjectAddress *object)
 
bool EventTriggerBeginCompleteQuery (void)
 
void EventTriggerEndCompleteQuery (void)
 
bool trackDroppedObjectsNeeded (void)
 
void EventTriggerSQLDropAddObject (const ObjectAddress *object, bool original, bool normal)
 
Datum pg_event_trigger_dropped_objects (PG_FUNCTION_ARGS)
 
Datum pg_event_trigger_table_rewrite_oid (PG_FUNCTION_ARGS)
 
Datum pg_event_trigger_table_rewrite_reason (PG_FUNCTION_ARGS)
 
void EventTriggerInhibitCommandCollection (void)
 
void EventTriggerUndoInhibitCommandCollection (void)
 
void EventTriggerCollectSimpleCommand (ObjectAddress address, ObjectAddress secondaryObject, const Node *parsetree)
 
void EventTriggerAlterTableStart (const Node *parsetree)
 
void EventTriggerAlterTableRelid (Oid objectId)
 
void EventTriggerCollectAlterTableSubcmd (const Node *subcmd, ObjectAddress address)
 
void EventTriggerAlterTableEnd (void)
 
void EventTriggerCollectGrant (InternalGrant *istmt)
 
void EventTriggerCollectAlterOpFam (const AlterOpFamilyStmt *stmt, Oid opfamoid, List *operators, List *procedures)
 
void EventTriggerCollectCreateOpClass (const CreateOpClassStmt *stmt, Oid opcoid, List *operators, List *procedures)
 
void EventTriggerCollectAlterTSConfig (const AlterTSConfigurationStmt *stmt, Oid cfgId, Oid *dictIds, int ndicts)
 
void EventTriggerCollectAlterDefPrivs (const AlterDefaultPrivilegesStmt *stmt)
 
Datum pg_event_trigger_ddl_commands (PG_FUNCTION_ARGS)
 

Variables

static EventTriggerQueryStatecurrentEventTriggerState = NULL
 
bool event_triggers = true
 

Typedef Documentation

◆ EventTriggerQueryState

◆ SQLDropObject

Function Documentation

◆ AlterEventTrigger()

Oid AlterEventTrigger ( AlterEventTrigStmt stmt)

Definition at line 428 of file event_trigger.c.

429{
432 Oid trigoid;
434 char tgenabled = stmt->tgenabled;
435
437
439 CStringGetDatum(stmt->trigname));
440 if (!HeapTupleIsValid(tup))
443 errmsg("event trigger \"%s\" does not exist",
444 stmt->trigname)));
445
447 trigoid = evtForm->oid;
448
451 stmt->trigname);
452
453 /* tuple is a copy, so we can modify it below */
454 evtForm->evtenabled = tgenabled;
455
456 CatalogTupleUpdate(tgrel, &tup->t_self, tup);
457
458 /*
459 * Login event triggers have an additional flag in pg_database to enable
460 * faster lookups in hot codepaths. Set the flag unless already True.
461 */
462 if (namestrcmp(&evtForm->evtevent, "login") == 0 &&
463 tgenabled != TRIGGER_DISABLED)
465
467 trigoid, 0);
468
469 /* clean up */
472
473 return trigoid;
474}
@ ACLCHECK_NOT_OWNER
Definition acl.h:186
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition aclchk.c:2672
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition aclchk.c:4133
int errcode(int sqlerrcode)
Definition elog.c:874
#define ERROR
Definition elog.h:39
#define ereport(elevel,...)
Definition elog.h:150
static void SetDatabaseHasLoginEventTriggers(void)
void heap_freetuple(HeapTuple htup)
Definition heaptuple.c:1384
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
#define stmt
void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)
Definition indexing.c:313
#define RowExclusiveLock
Definition lockdefs.h:38
Oid GetUserId(void)
Definition miscinit.c:470
int namestrcmp(Name name, const char *str)
Definition name.c:247
static char * errmsg
#define InvokeObjectPostAlterHook(classId, objectId, subId)
@ OBJECT_EVENT_TRIGGER
END_CATALOG_STRUCT typedef FormData_pg_event_trigger * Form_pg_event_trigger
static Datum CStringGetDatum(const char *X)
Definition postgres.h:370
unsigned int Oid
static int fb(int x)
#define SearchSysCacheCopy1(cacheId, key1)
Definition syscache.h:91
void table_close(Relation relation, LOCKMODE lockmode)
Definition table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition table.c:40
#define TRIGGER_DISABLED
Definition trigger.h:154

References aclcheck_error(), ACLCHECK_NOT_OWNER, CatalogTupleUpdate(), CStringGetDatum(), ereport, errcode(), errmsg, ERROR, fb(), Form_pg_event_trigger, GETSTRUCT(), GetUserId(), heap_freetuple(), HeapTupleIsValid, InvokeObjectPostAlterHook, namestrcmp(), OBJECT_EVENT_TRIGGER, object_ownercheck(), RowExclusiveLock, SearchSysCacheCopy1, SetDatabaseHasLoginEventTriggers(), stmt, table_close(), table_open(), and TRIGGER_DISABLED.

Referenced by standard_ProcessUtility().

◆ AlterEventTriggerOwner()

ObjectAddress AlterEventTriggerOwner ( const char name,
Oid  newOwnerId 
)

Definition at line 480 of file event_trigger.c.

481{
482 Oid evtOid;
485 Relation rel;
486 ObjectAddress address;
487
489
491
492 if (!HeapTupleIsValid(tup))
495 errmsg("event trigger \"%s\" does not exist", name)));
496
498 evtOid = evtForm->oid;
499
501
503
505
507
508 return address;
509}
static void AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
#define ObjectAddressSet(addr, class_id, object_id)
const char * name

References AlterEventTriggerOwner_internal(), CStringGetDatum(), ereport, errcode(), errmsg, ERROR, fb(), Form_pg_event_trigger, GETSTRUCT(), heap_freetuple(), HeapTupleIsValid, name, ObjectAddressSet, RowExclusiveLock, SearchSysCacheCopy1, table_close(), and table_open().

Referenced by ExecAlterOwnerStmt().

◆ AlterEventTriggerOwner_internal()

static void AlterEventTriggerOwner_internal ( Relation  rel,
HeapTuple  tup,
Oid  newOwnerId 
)
static

Definition at line 540 of file event_trigger.c.

541{
543
545
546 if (form->evtowner == newOwnerId)
547 return;
548
551 NameStr(form->evtname));
552
553 /* New owner must be a superuser */
557 errmsg("permission denied to change owner of event trigger \"%s\"",
558 NameStr(form->evtname)),
559 errhint("The owner of an event trigger must be a superuser.")));
560
561 form->evtowner = newOwnerId;
562 CatalogTupleUpdate(rel, &tup->t_self, tup);
563
564 /* Update owner dependency reference */
566 form->oid,
567 newOwnerId);
568
570 form->oid, 0);
571}
#define NameStr(name)
Definition c.h:837
int errhint(const char *fmt,...) pg_attribute_printf(1
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
bool superuser_arg(Oid roleid)
Definition superuser.c:57

References aclcheck_error(), ACLCHECK_NOT_OWNER, CatalogTupleUpdate(), changeDependencyOnOwner(), ereport, errcode(), errhint(), errmsg, ERROR, fb(), Form_pg_event_trigger, GETSTRUCT(), GetUserId(), InvokeObjectPostAlterHook, NameStr, OBJECT_EVENT_TRIGGER, object_ownercheck(), and superuser_arg().

Referenced by AlterEventTriggerOwner(), and AlterEventTriggerOwner_oid().

◆ AlterEventTriggerOwner_oid()

void AlterEventTriggerOwner_oid ( Oid  trigOid,
Oid  newOwnerId 
)

Definition at line 515 of file event_trigger.c.

516{
518 Relation rel;
519
521
523
524 if (!HeapTupleIsValid(tup))
527 errmsg("event trigger with OID %u does not exist", trigOid)));
528
530
532
534}
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252

References AlterEventTriggerOwner_internal(), ereport, errcode(), errmsg, ERROR, fb(), heap_freetuple(), HeapTupleIsValid, ObjectIdGetDatum(), RowExclusiveLock, SearchSysCacheCopy1, table_close(), and table_open().

Referenced by shdepReassignOwned_Owner().

◆ CreateEventTrigger()

Oid CreateEventTrigger ( CreateEventTrigStmt stmt)

Definition at line 125 of file event_trigger.c.

126{
127 HeapTuple tuple;
128 Oid funcoid;
130 Oid evtowner = GetUserId();
131 ListCell *lc;
132 List *tags = NULL;
133
134 /*
135 * It would be nice to allow database owners or even regular users to do
136 * this, but there are obvious privilege escalation risks which would have
137 * to somehow be plugged first.
138 */
139 if (!superuser())
142 errmsg("permission denied to create event trigger \"%s\"",
143 stmt->trigname),
144 errhint("Must be superuser to create an event trigger.")));
145
146 /* Validate event name. */
147 if (strcmp(stmt->eventname, "ddl_command_start") != 0 &&
148 strcmp(stmt->eventname, "ddl_command_end") != 0 &&
149 strcmp(stmt->eventname, "sql_drop") != 0 &&
150 strcmp(stmt->eventname, "login") != 0 &&
151 strcmp(stmt->eventname, "table_rewrite") != 0)
154 errmsg("unrecognized event name \"%s\"",
155 stmt->eventname)));
156
157 /* Validate filter conditions. */
158 foreach(lc, stmt->whenclause)
159 {
160 DefElem *def = (DefElem *) lfirst(lc);
161
162 if (strcmp(def->defname, "tag") == 0)
163 {
164 if (tags != NULL)
166 tags = (List *) def->arg;
167 }
168 else
171 errmsg("unrecognized filter variable \"%s\"", def->defname)));
172 }
173
174 /* Validate tag list, if any. */
175 if ((strcmp(stmt->eventname, "ddl_command_start") == 0 ||
176 strcmp(stmt->eventname, "ddl_command_end") == 0 ||
177 strcmp(stmt->eventname, "sql_drop") == 0)
178 && tags != NULL)
179 validate_ddl_tags("tag", tags);
180 else if (strcmp(stmt->eventname, "table_rewrite") == 0
181 && tags != NULL)
183 else if (strcmp(stmt->eventname, "login") == 0 && tags != NULL)
186 errmsg("tag filtering is not supported for login event triggers")));
187
188 /*
189 * Give user a nice error message if an event trigger of the same name
190 * already exists.
191 */
193 if (HeapTupleIsValid(tuple))
196 errmsg("event trigger \"%s\" already exists",
197 stmt->trigname)));
198
199 /* Find and validate the trigger function. */
200 funcoid = LookupFuncName(stmt->funcname, 0, NULL, false);
205 errmsg("function %s must return type %s",
206 NameListToString(stmt->funcname), "event_trigger")));
207
208 /* Insert catalog entries. */
209 return insert_event_trigger_tuple(stmt->trigname, stmt->eventname,
210 evtowner, funcoid, tags);
211}
static void validate_table_rewrite_tags(const char *filtervar, List *taglist)
static void validate_ddl_tags(const char *filtervar, List *taglist)
static void error_duplicate_filter_variable(const char *defname)
static Oid insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtOwner, Oid funcoid, List *taglist)
Oid get_func_rettype(Oid funcid)
Definition lsyscache.c:1875
char * NameListToString(const List *names)
Definition namespace.c:3666
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
#define lfirst(lc)
Definition pg_list.h:172
#define ERRCODE_DUPLICATE_OBJECT
Definition streamutil.c:30
char * defname
Definition parsenodes.h:857
Node * arg
Definition parsenodes.h:858
Definition pg_list.h:54
bool superuser(void)
Definition superuser.c:47
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:220

References DefElem::arg, CStringGetDatum(), DefElem::defname, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errhint(), errmsg, ERROR, error_duplicate_filter_variable(), fb(), get_func_rettype(), GetUserId(), HeapTupleIsValid, insert_event_trigger_tuple(), lfirst, LookupFuncName(), NameListToString(), SearchSysCache1(), stmt, superuser(), validate_ddl_tags(), and validate_table_rewrite_tags().

Referenced by standard_ProcessUtility().

◆ error_duplicate_filter_variable()

static void error_duplicate_filter_variable ( const char defname)
static

Definition at line 266 of file event_trigger.c.

267{
270 errmsg("filter variable \"%s\" specified more than once",
271 defname)));
272}

References ereport, errcode(), errmsg, ERROR, and fb().

Referenced by CreateEventTrigger().

◆ EventTriggerAlterTableEnd()

void EventTriggerAlterTableEnd ( void  )

Definition at line 1841 of file event_trigger.c.

1842{
1843 CollectedCommand *parent;
1844
1845 /* ignore if event trigger context not set, or collection disabled */
1848 return;
1849
1851
1852 /* If no subcommands, don't collect */
1854 {
1856
1858
1862
1864 }
1865 else
1867
1869}
static EventTriggerQueryState * currentEventTriggerState
List * lappend(List *list, void *datum)
Definition list.c:339
void pfree(void *pointer)
Definition mcxt.c:1616
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
#define NIL
Definition pg_list.h:68
struct CollectedCommand * parent
struct CollectedCommand::@134::@136 alterTable
union CollectedCommand::@134 d
CollectedCommand * currentCommand

References CollectedCommand::alterTable, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, EventTriggerQueryState::currentCommand, currentEventTriggerState, EventTriggerQueryState::cxt, CollectedCommand::d, fb(), lappend(), MemoryContextSwitchTo(), NIL, CollectedCommand::parent, pfree(), and CollectedCommand::subcmds.

Referenced by AlterTableMoveAll(), ProcessUtilityForAlterTable(), and ProcessUtilitySlow().

◆ EventTriggerAlterTableRelid()

◆ EventTriggerAlterTableStart()

void EventTriggerAlterTableStart ( const Node parsetree)

Definition at line 1754 of file event_trigger.c.

1755{
1757 CollectedCommand *command;
1758
1759 /* ignore if event trigger context not set, or collection disabled */
1762 return;
1763
1765
1767
1768 command->type = SCT_AlterTable;
1770
1772 command->d.alterTable.objectId = InvalidOid;
1773 command->d.alterTable.subcmds = NIL;
1774 command->parsetree = copyObject(parsetree);
1775
1778
1780}
@ SCT_AlterTable
bool creating_extension
Definition extension.c:80
#define palloc_object(type)
Definition fe_memutils.h:74
#define copyObject(obj)
Definition nodes.h:232
#define InvalidOid
CollectedCommandType type

References CollectedCommand::alterTable, CollectedCommand::classId, EventTriggerQueryState::commandCollectionInhibited, copyObject, creating_extension, EventTriggerQueryState::currentCommand, currentEventTriggerState, EventTriggerQueryState::cxt, CollectedCommand::d, fb(), CollectedCommand::in_extension, InvalidOid, MemoryContextSwitchTo(), NIL, CollectedCommand::objectId, palloc_object, CollectedCommand::parent, CollectedCommand::parsetree, SCT_AlterTable, CollectedCommand::subcmds, and CollectedCommand::type.

Referenced by AlterTableMoveAll(), ProcessUtilityForAlterTable(), and ProcessUtilitySlow().

◆ EventTriggerBeginCompleteQuery()

bool EventTriggerBeginCompleteQuery ( void  )

Definition at line 1184 of file event_trigger.c.

1185{
1187 MemoryContext cxt;
1188
1189 /*
1190 * Currently, sql_drop, table_rewrite, ddl_command_end events are the only
1191 * reason to have event trigger state at all; so if there are none, don't
1192 * install one.
1193 */
1195 return false;
1196
1198 "event trigger state",
1201 state->cxt = cxt;
1202 slist_init(&(state->SQLDropList));
1203 state->in_sql_drop = false;
1204 state->table_rewrite_oid = InvalidOid;
1205
1206 state->commandCollectionInhibited = currentEventTriggerState ?
1208 state->currentCommand = NULL;
1209 state->commandList = NIL;
1210 state->previous = currentEventTriggerState;
1212
1213 return true;
1214}
bool trackDroppedObjectsNeeded(void)
static void slist_init(slist_head *head)
Definition ilist.h:986
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
MemoryContext TopMemoryContext
Definition mcxt.c:166
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, EventTriggerQueryState::commandCollectionInhibited, currentEventTriggerState, fb(), InvalidOid, MemoryContextAlloc(), NIL, slist_init(), TopMemoryContext, and trackDroppedObjectsNeeded().

Referenced by ProcessUtilitySlow().

◆ EventTriggerCollectAlterDefPrivs()

void EventTriggerCollectAlterDefPrivs ( const AlterDefaultPrivilegesStmt stmt)

Definition at line 2028 of file event_trigger.c.

2029{
2031 CollectedCommand *command;
2032
2033 /* ignore if event trigger context not set, or collection disabled */
2036 return;
2037
2039
2042 command->d.defprivs.objtype = stmt->action->objtype;
2044 command->parsetree = (Node *) copyObject(stmt);
2045
2049}
@ SCT_AlterDefaultPrivileges
#define palloc0_object(type)
Definition fe_memutils.h:75
struct CollectedCommand::@134::@141 defprivs
Definition nodes.h:135

References EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, currentEventTriggerState, EventTriggerQueryState::cxt, CollectedCommand::d, CollectedCommand::defprivs, fb(), CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), CollectedCommand::objtype, palloc0_object, CollectedCommand::parsetree, SCT_AlterDefaultPrivileges, stmt, and CollectedCommand::type.

Referenced by ProcessUtilitySlow().

◆ EventTriggerCollectAlterOpFam()

void EventTriggerCollectAlterOpFam ( const AlterOpFamilyStmt stmt,
Oid  opfamoid,
List operators,
List procedures 
)

Definition at line 1923 of file event_trigger.c.

1925{
1927 CollectedCommand *command;
1928
1929 /* ignore if event trigger context not set, or collection disabled */
1932 return;
1933
1935
1937 command->type = SCT_AlterOpFamily;
1941 command->d.opfam.operators = operators;
1942 command->d.opfam.procedures = procedures;
1943 command->parsetree = (Node *) copyObject(stmt);
1944
1947
1949}
@ SCT_AlterOpFamily
struct CollectedCommand::@134::@138 opfam
ObjectAddress address

References CollectedCommand::address, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, currentEventTriggerState, EventTriggerQueryState::cxt, CollectedCommand::d, fb(), CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), ObjectAddressSet, CollectedCommand::operators, CollectedCommand::opfam, palloc_object, CollectedCommand::parsetree, CollectedCommand::procedures, SCT_AlterOpFamily, stmt, and CollectedCommand::type.

Referenced by AlterOpFamilyAdd(), and AlterOpFamilyDrop().

◆ EventTriggerCollectAlterTableSubcmd()

void EventTriggerCollectAlterTableSubcmd ( const Node subcmd,
ObjectAddress  address 
)

Definition at line 1806 of file event_trigger.c.

1807{
1810
1811 /* ignore if event trigger context not set, or collection disabled */
1814 return;
1815
1819
1821
1823 newsub->address = address;
1824 newsub->parsetree = copyObject(subcmd);
1825
1828
1830}
#define Assert(condition)
Definition c.h:945
#define OidIsValid(objectId)
Definition c.h:860
#define IsA(nodeptr, _type_)
Definition nodes.h:164
static color newsub(struct colormap *cm, color co)
Definition regc_color.c:389

References CollectedCommand::alterTable, Assert, EventTriggerQueryState::commandCollectionInhibited, copyObject, EventTriggerQueryState::currentCommand, currentEventTriggerState, EventTriggerQueryState::cxt, CollectedCommand::d, fb(), IsA, lappend(), MemoryContextSwitchTo(), newsub(), CollectedCommand::objectId, OidIsValid, palloc_object, and CollectedCommand::subcmds.

Referenced by ATExecCmd().

◆ EventTriggerCollectAlterTSConfig()

void EventTriggerCollectAlterTSConfig ( const AlterTSConfigurationStmt stmt,
Oid  cfgId,
Oid dictIds,
int  ndicts 
)

Definition at line 1990 of file event_trigger.c.

1992{
1994 CollectedCommand *command;
1995
1996 /* ignore if event trigger context not set, or collection disabled */
1999 return;
2000
2002
2004 command->type = SCT_AlterTSConfig;
2007 TSConfigRelationId, cfgId);
2008 if (ndicts > 0)
2009 {
2010 command->d.atscfg.dictIds = palloc_array(Oid, ndicts);
2011 memcpy(command->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts);
2012 }
2013 command->d.atscfg.ndicts = ndicts;
2014 command->parsetree = (Node *) copyObject(stmt);
2015
2018
2020}
@ SCT_AlterTSConfig
#define palloc_array(type, count)
Definition fe_memutils.h:76
struct CollectedCommand::@134::@140 atscfg

References CollectedCommand::address, CollectedCommand::atscfg, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, currentEventTriggerState, EventTriggerQueryState::cxt, CollectedCommand::d, CollectedCommand::dictIds, fb(), CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), CollectedCommand::ndicts, ObjectAddressSet, palloc0_object, palloc_array, CollectedCommand::parsetree, SCT_AlterTSConfig, stmt, and CollectedCommand::type.

Referenced by DropConfigurationMapping(), and MakeConfigurationMapping().

◆ EventTriggerCollectCreateOpClass()

void EventTriggerCollectCreateOpClass ( const CreateOpClassStmt stmt,
Oid  opcoid,
List operators,
List procedures 
)

Definition at line 1956 of file event_trigger.c.

1958{
1960 CollectedCommand *command;
1961
1962 /* ignore if event trigger context not set, or collection disabled */
1965 return;
1966
1968
1970 command->type = SCT_CreateOpClass;
1974 command->d.createopc.operators = operators;
1975 command->d.createopc.procedures = procedures;
1976 command->parsetree = (Node *) copyObject(stmt);
1977
1980
1982}
@ SCT_CreateOpClass
struct CollectedCommand::@134::@139 createopc

References CollectedCommand::address, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, CollectedCommand::createopc, creating_extension, currentEventTriggerState, EventTriggerQueryState::cxt, CollectedCommand::d, fb(), CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), ObjectAddressSet, CollectedCommand::operators, palloc0_object, CollectedCommand::parsetree, CollectedCommand::procedures, SCT_CreateOpClass, stmt, and CollectedCommand::type.

Referenced by DefineOpClass().

◆ EventTriggerCollectGrant()

void EventTriggerCollectGrant ( InternalGrant istmt)

Definition at line 1879 of file event_trigger.c.

1880{
1882 CollectedCommand *command;
1884 ListCell *cell;
1885
1886 /* ignore if event trigger context not set, or collection disabled */
1889 return;
1890
1892
1893 /*
1894 * This is tedious, but necessary.
1895 */
1897 memcpy(icopy, istmt, sizeof(InternalGrant));
1898 icopy->objects = list_copy(istmt->objects);
1899 icopy->grantees = list_copy(istmt->grantees);
1900 icopy->col_privs = NIL;
1901 foreach(cell, istmt->col_privs)
1902 icopy->col_privs = lappend(icopy->col_privs, copyObject(lfirst(cell)));
1903
1904 /* Now collect it, using the copied InternalGrant */
1906 command->type = SCT_Grant;
1908 command->d.grant.istmt = icopy;
1909 command->parsetree = NULL;
1910
1913
1915}
@ SCT_Grant
List * list_copy(const List *oldlist)
Definition list.c:1573
InternalGrant * istmt
struct CollectedCommand::@134::@137 grant

References InternalGrant::col_privs, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, currentEventTriggerState, EventTriggerQueryState::cxt, CollectedCommand::d, fb(), CollectedCommand::grant, InternalGrant::grantees, CollectedCommand::in_extension, CollectedCommand::istmt, lappend(), lfirst, list_copy(), MemoryContextSwitchTo(), NIL, InternalGrant::objects, palloc_object, CollectedCommand::parsetree, SCT_Grant, and CollectedCommand::type.

Referenced by ExecGrantStmt_oids().

◆ EventTriggerCollectSimpleCommand()

void EventTriggerCollectSimpleCommand ( ObjectAddress  address,
ObjectAddress  secondaryObject,
const Node parsetree 
)

Definition at line 1716 of file event_trigger.c.

1719{
1721 CollectedCommand *command;
1722
1723 /* ignore if event trigger context not set, or collection disabled */
1726 return;
1727
1729
1731
1732 command->type = SCT_Simple;
1734
1735 command->d.simple.address = address;
1736 command->d.simple.secondaryObject = secondaryObject;
1737 command->parsetree = copyObject(parsetree);
1738
1740 command);
1741
1743}
@ SCT_Simple
struct CollectedCommand::@134::@135 simple
ObjectAddress secondaryObject

References CollectedCommand::address, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, currentEventTriggerState, EventTriggerQueryState::cxt, CollectedCommand::d, fb(), CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), palloc_object, CollectedCommand::parsetree, SCT_Simple, CollectedCommand::secondaryObject, CollectedCommand::simple, and CollectedCommand::type.

Referenced by AlterPublicationOptions(), CreateOpFamily(), CreateSchemaCommand(), ProcessUtilitySlow(), PublicationAddSchemas(), PublicationAddTables(), reindex_index(), and ReindexRelationConcurrently().

◆ EventTriggerCommonSetup()

static List * EventTriggerCommonSetup ( Node parsetree,
EventTriggerEvent  event,
const char eventstr,
EventTriggerData trigdata,
bool  unfiltered 
)
static

Definition at line 639 of file event_trigger.c.

642{
643 CommandTag tag;
645 ListCell *lc;
646 List *runlist = NIL;
647
648 /*
649 * We want the list of command tags for which this procedure is actually
650 * invoked to match up exactly with the list that CREATE EVENT TRIGGER
651 * accepts. This debugging cross-check will throw an error if this
652 * function is invoked for a command tag that CREATE EVENT TRIGGER won't
653 * accept. (Unfortunately, there doesn't seem to be any simple, automated
654 * way to verify that CREATE EVENT TRIGGER doesn't accept extra stuff that
655 * never reaches this control point.)
656 *
657 * If this cross-check fails for you, you probably need to either adjust
658 * standard_ProcessUtility() not to invoke event triggers for the command
659 * type in question, or you need to adjust event_trigger_ok to accept the
660 * relevant command tag.
661 */
662#ifdef USE_ASSERT_CHECKING
663 {
665
666 dbgtag = EventTriggerGetTag(parsetree, event);
667
668 if (event == EVT_DDLCommandStart ||
669 event == EVT_DDLCommandEnd ||
670 event == EVT_SQLDrop ||
671 event == EVT_Login)
672 {
674 elog(ERROR, "unexpected command tag \"%s\"", GetCommandTagName(dbgtag));
675 }
676 else if (event == EVT_TableRewrite)
677 {
679 elog(ERROR, "unexpected command tag \"%s\"", GetCommandTagName(dbgtag));
680 }
681 }
682#endif
683
684 /* Use cache to find triggers for this event; fast exit if none. */
686 if (cachelist == NIL)
687 return NIL;
688
689 /* Get the command tag. */
690 tag = EventTriggerGetTag(parsetree, event);
691
692 /*
693 * Filter list of event triggers by command tag, and copy them into our
694 * memory context. Once we start running the command triggers, or indeed
695 * once we do anything at all that touches the catalogs, an invalidation
696 * might leave cachelist pointing at garbage, so we must do this before we
697 * can do much else.
698 */
699 foreach(lc, cachelist)
700 {
702
703 if (unfiltered || filter_event_trigger(tag, item))
704 {
705 /* We must plan to fire this trigger. */
707 }
708 }
709
710 /* Don't spend any more time on this if no functions to run */
711 if (runlist == NIL)
712 return NIL;
713
714 trigdata->type = T_EventTriggerData;
715 trigdata->event = eventstr;
716 trigdata->parsetree = parsetree;
717 trigdata->tag = tag;
718
719 return runlist;
720}
const char * GetCommandTagName(CommandTag commandTag)
Definition cmdtag.c:47
bool command_tag_event_trigger_ok(CommandTag commandTag)
Definition cmdtag.c:66
bool command_tag_table_rewrite_ok(CommandTag commandTag)
Definition cmdtag.c:72
CommandTag
Definition cmdtag.h:23
#define elog(elevel,...)
Definition elog.h:226
static bool filter_event_trigger(CommandTag tag, EventTriggerCacheItem *item)
static CommandTag EventTriggerGetTag(Node *parsetree, EventTriggerEvent event)
List * EventCacheLookup(EventTriggerEvent event)
Definition evtcache.c:64
@ EVT_SQLDrop
Definition evtcache.h:24
@ EVT_Login
Definition evtcache.h:26
@ EVT_DDLCommandEnd
Definition evtcache.h:23
@ EVT_DDLCommandStart
Definition evtcache.h:22
@ EVT_TableRewrite
Definition evtcache.h:25
List * lappend_oid(List *list, Oid datum)
Definition list.c:375
const char * event

References command_tag_event_trigger_ok(), command_tag_table_rewrite_ok(), elog, ERROR, EventTriggerData::event, EventCacheLookup(), EventTriggerGetTag(), EVT_DDLCommandEnd, EVT_DDLCommandStart, EVT_Login, EVT_SQLDrop, EVT_TableRewrite, fb(), filter_event_trigger(), EventTriggerCacheItem::fnoid, GetCommandTagName(), lappend_oid(), lfirst, NIL, EventTriggerData::parsetree, EventTriggerData::tag, and EventTriggerData::type.

Referenced by EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerOnLogin(), EventTriggerSQLDrop(), and EventTriggerTableRewrite().

◆ EventTriggerDDLCommandEnd()

void EventTriggerDDLCommandEnd ( Node parsetree)

Definition at line 777 of file event_trigger.c.

778{
779 List *runlist;
780 EventTriggerData trigdata;
781
782 /*
783 * See EventTriggerDDLCommandStart for a discussion about why event
784 * triggers are disabled in single user mode or via GUC.
785 */
787 return;
788
789 /*
790 * Also do nothing if our state isn't set up, which it won't be if there
791 * weren't any relevant event triggers at the start of the current DDL
792 * command. This test might therefore seem optional, but it's important
793 * because EventTriggerCommonSetup might find triggers that didn't exist
794 * at the time the command started. Although this function itself
795 * wouldn't crash, the event trigger functions would presumably call
796 * pg_event_trigger_ddl_commands which would fail. Better to do nothing
797 * until the next command.
798 */
800 return;
801
803 EVT_DDLCommandEnd, "ddl_command_end",
804 &trigdata, false);
805 if (runlist == NIL)
806 return;
807
808 /*
809 * Make sure anything the main command did will be visible to the event
810 * triggers.
811 */
813
814 /* Run the triggers. */
815 EventTriggerInvoke(runlist, &trigdata);
816
817 /* Cleanup. */
819}
bool event_triggers
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata, bool unfiltered)
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
bool IsUnderPostmaster
Definition globals.c:120
void list_free(List *list)
Definition list.c:1546
void CommandCounterIncrement(void)
Definition xact.c:1102

References CommandCounterIncrement(), currentEventTriggerState, event_triggers, EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_DDLCommandEnd, fb(), IsUnderPostmaster, list_free(), and NIL.

Referenced by ProcessUtilitySlow().

◆ EventTriggerDDLCommandStart()

void EventTriggerDDLCommandStart ( Node parsetree)

Definition at line 726 of file event_trigger.c.

727{
728 List *runlist;
729 EventTriggerData trigdata;
730
731 /*
732 * Event Triggers are completely disabled in standalone mode. There are
733 * (at least) two reasons for this:
734 *
735 * 1. A sufficiently broken event trigger might not only render the
736 * database unusable, but prevent disabling itself to fix the situation.
737 * In this scenario, restarting in standalone mode provides an escape
738 * hatch.
739 *
740 * 2. BuildEventTriggerCache relies on systable_beginscan_ordered, and
741 * therefore will malfunction if pg_event_trigger's indexes are damaged.
742 * To allow recovery from a damaged index, we need some operating mode
743 * wherein event triggers are disabled. (Or we could implement
744 * heapscan-and-sort logic for that case, but having disaster recovery
745 * scenarios depend on code that's otherwise untested isn't appetizing.)
746 *
747 * Additionally, event triggers can be disabled with a superuser-only GUC
748 * to make fixing database easier as per 1 above.
749 */
751 return;
752
755 "ddl_command_start",
756 &trigdata, false);
757 if (runlist == NIL)
758 return;
759
760 /* Run the triggers. */
761 EventTriggerInvoke(runlist, &trigdata);
762
763 /* Cleanup. */
765
766 /*
767 * Make sure anything the event triggers did will be visible to the main
768 * command.
769 */
771}

References CommandCounterIncrement(), event_triggers, EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_DDLCommandStart, fb(), IsUnderPostmaster, list_free(), and NIL.

Referenced by ProcessUtilitySlow().

◆ EventTriggerEndCompleteQuery()

void EventTriggerEndCompleteQuery ( void  )

Definition at line 1228 of file event_trigger.c.

1229{
1231
1233
1234 /* this avoids the need for retail pfree of SQLDropList items: */
1236
1238}
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:472
struct EventTriggerQueryState * previous

References currentEventTriggerState, EventTriggerQueryState::cxt, fb(), MemoryContextDelete(), and EventTriggerQueryState::previous.

Referenced by ProcessUtilitySlow().

◆ EventTriggerGetTag()

static CommandTag EventTriggerGetTag ( Node parsetree,
EventTriggerEvent  event 
)
static

Definition at line 625 of file event_trigger.c.

626{
627 if (event == EVT_Login)
628 return CMDTAG_LOGIN;
629 else
630 return CreateCommandTag(parsetree);
631}
CommandTag CreateCommandTag(Node *parsetree)
Definition utility.c:2384

References CreateCommandTag(), EVT_Login, and fb().

Referenced by EventTriggerCommonSetup().

◆ EventTriggerInhibitCommandCollection()

void EventTriggerInhibitCommandCollection ( void  )

◆ EventTriggerInvoke()

static void EventTriggerInvoke ( List fn_oid_list,
EventTriggerData trigdata 
)
static

Definition at line 1069 of file event_trigger.c.

1070{
1071 MemoryContext context;
1072 MemoryContext oldcontext;
1073 ListCell *lc;
1074 bool first = true;
1075
1076 /* Guard against stack overflow due to recursive event trigger */
1078
1079 /*
1080 * Let's evaluate event triggers in their own memory context, so that any
1081 * leaks get cleaned up promptly.
1082 */
1084 "event trigger context",
1086 oldcontext = MemoryContextSwitchTo(context);
1087
1088 /* Call each event trigger. */
1089 foreach(lc, fn_oid_list)
1090 {
1091 LOCAL_FCINFO(fcinfo, 0);
1092 Oid fnoid = lfirst_oid(lc);
1093 FmgrInfo flinfo;
1095
1096 elog(DEBUG1, "EventTriggerInvoke %u", fnoid);
1097
1098 /*
1099 * We want each event trigger to be able to see the results of the
1100 * previous event trigger's action. Caller is responsible for any
1101 * command-counter increment that is needed between the event trigger
1102 * and anything else in the transaction.
1103 */
1104 if (first)
1105 first = false;
1106 else
1108
1109 /* Look up the function */
1110 fmgr_info(fnoid, &flinfo);
1111
1112 /* Call the function, passing no arguments but setting a context. */
1113 InitFunctionCallInfoData(*fcinfo, &flinfo, 0,
1114 InvalidOid, (Node *) trigdata, NULL);
1116 FunctionCallInvoke(fcinfo);
1118
1119 /* Reclaim memory. */
1120 MemoryContextReset(context);
1121 }
1122
1123 /* Restore old memory context and delete the temporary one. */
1124 MemoryContextSwitchTo(oldcontext);
1125 MemoryContextDelete(context);
1126}
#define DEBUG1
Definition elog.h:30
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition fmgr.c:129
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition fmgr.h:150
#define LOCAL_FCINFO(name, nargs)
Definition fmgr.h:110
#define FunctionCallInvoke(fcinfo)
Definition fmgr.h:172
void MemoryContextReset(MemoryContext context)
Definition mcxt.c:403
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
#define lfirst_oid(lc)
Definition pg_list.h:174
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
void check_stack_depth(void)
Definition stack_depth.c:95

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, check_stack_depth(), CommandCounterIncrement(), CurrentMemoryContext, DEBUG1, elog, fb(), fmgr_info(), FunctionCallInvoke, InitFunctionCallInfoData, InvalidOid, lfirst_oid, LOCAL_FCINFO, MemoryContextDelete(), MemoryContextReset(), MemoryContextSwitchTo(), pgstat_end_function_usage(), and pgstat_init_function_usage().

Referenced by EventTriggerDDLCommandEnd(), EventTriggerDDLCommandStart(), EventTriggerOnLogin(), EventTriggerSQLDrop(), and EventTriggerTableRewrite().

◆ EventTriggerOnLogin()

void EventTriggerOnLogin ( void  )

Definition at line 898 of file event_trigger.c.

899{
900 List *runlist;
901 EventTriggerData trigdata;
902
903 /*
904 * See EventTriggerDDLCommandStart for a discussion about why event
905 * triggers are disabled in single user mode or via a GUC. We also need a
906 * database connection (some background workers don't have it).
907 */
910 return;
911
914 EVT_Login, "login",
915 &trigdata, false);
916
917 if (runlist != NIL)
918 {
919 /*
920 * Event trigger execution may require an active snapshot.
921 */
923
924 /* Run the triggers. */
925 EventTriggerInvoke(runlist, &trigdata);
926
927 /* Cleanup. */
929
931 }
932
933 /*
934 * There is no active login event trigger, but our
935 * pg_database.dathasloginevt is set. Try to unset this flag. We use the
936 * lock to prevent concurrent SetDatabaseHasLoginEventTriggers(), but we
937 * don't want to hang the connection waiting on the lock. Thus, we are
938 * just trying to acquire the lock conditionally.
939 */
942 {
943 /*
944 * The lock is held. Now we need to recheck that login event triggers
945 * list is still empty. Once the list is empty, we know that even if
946 * there is a backend which concurrently inserts/enables a login event
947 * trigger, it will update pg_database.dathasloginevt *afterwards*.
948 */
950 EVT_Login, "login",
951 &trigdata, true);
952
953 if (runlist == NIL)
954 {
956 HeapTuple tuple;
957 void *state;
959 ScanKeyData key[1];
960
961 /* Fetch a copy of the tuple to scribble on */
962 ScanKeyInit(&key[0],
966
968 NULL, 1, key, &tuple, &state);
969
970 if (!HeapTupleIsValid(tuple))
971 elog(ERROR, "could not find tuple for database %u", MyDatabaseId);
972
973 db = (Form_pg_database) GETSTRUCT(tuple);
974 if (db->dathasloginevt)
975 {
976 db->dathasloginevt = false;
977
978 /*
979 * Do an "in place" update of the pg_database tuple. Doing
980 * this instead of regular updates serves two purposes. First,
981 * that avoids possible waiting on the row-level lock. Second,
982 * that avoids dealing with TOAST.
983 */
985 }
986 else
989 heap_freetuple(tuple);
990 }
991 else
992 {
994 }
995 }
997}
void systable_inplace_update_cancel(void *state)
Definition genam.c:903
void systable_inplace_update_begin(Relation relation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, const ScanKeyData *key, HeapTuple *oldtupcopy, void **state)
Definition genam.c:808
void systable_inplace_update_finish(void *state, HeapTuple tuple)
Definition genam.c:884
bool MyDatabaseHasLoginEventTriggers
Definition globals.c:98
Oid MyDatabaseId
Definition globals.c:94
bool ConditionalLockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1112
#define AccessExclusiveLock
Definition lockdefs.h:43
END_CATALOG_STRUCT typedef FormData_pg_database * Form_pg_database
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition scankey.c:76
Snapshot GetTransactionSnapshot(void)
Definition snapmgr.c:272
void PushActiveSnapshot(Snapshot snapshot)
Definition snapmgr.c:682
void PopActiveSnapshot(void)
Definition snapmgr.c:775
#define BTEqualStrategyNumber
Definition stratnum.h:31
void StartTransactionCommand(void)
Definition xact.c:3081
void CommitTransactionCommand(void)
Definition xact.c:3179

References AccessExclusiveLock, BTEqualStrategyNumber, CommitTransactionCommand(), ConditionalLockSharedObject(), elog, ERROR, event_triggers, EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_Login, fb(), Form_pg_database, GETSTRUCT(), GetTransactionSnapshot(), heap_freetuple(), HeapTupleIsValid, IsUnderPostmaster, list_free(), MyDatabaseHasLoginEventTriggers, MyDatabaseId, NIL, ObjectIdGetDatum(), OidIsValid, PopActiveSnapshot(), PushActiveSnapshot(), RowExclusiveLock, ScanKeyInit(), StartTransactionCommand(), systable_inplace_update_begin(), systable_inplace_update_cancel(), systable_inplace_update_finish(), table_close(), and table_open().

Referenced by PostgresMain().

◆ EventTriggerSQLDrop()

void EventTriggerSQLDrop ( Node parsetree)

Definition at line 825 of file event_trigger.c.

826{
827 List *runlist;
828 EventTriggerData trigdata;
829
830 /*
831 * See EventTriggerDDLCommandStart for a discussion about why event
832 * triggers are disabled in single user mode or via a GUC.
833 */
835 return;
836
837 /*
838 * Use current state to determine whether this event fires at all. If
839 * there are no triggers for the sql_drop event, then we don't have
840 * anything to do here. Note that dropped object collection is disabled
841 * if this is the case, so even if we were to try to run, the list would
842 * be empty.
843 */
846 return;
847
849 EVT_SQLDrop, "sql_drop",
850 &trigdata, false);
851
852 /*
853 * Nothing to do if run list is empty. Note this typically can't happen,
854 * because if there are no sql_drop events, then objects-to-drop wouldn't
855 * have been collected in the first place and we would have quit above.
856 * But it could occur if event triggers were dropped partway through.
857 */
858 if (runlist == NIL)
859 return;
860
861 /*
862 * Make sure anything the main command did will be visible to the event
863 * triggers.
864 */
866
867 /*
868 * Make sure pg_event_trigger_dropped_objects only works when running
869 * these triggers. Use PG_TRY to ensure in_sql_drop is reset even when
870 * one trigger fails. (This is perhaps not necessary, as the currentState
871 * variable will be removed shortly by our caller, but it seems better to
872 * play safe.)
873 */
875
876 /* Run the triggers. */
877 PG_TRY();
878 {
879 EventTriggerInvoke(runlist, &trigdata);
880 }
881 PG_FINALLY();
882 {
884 }
885 PG_END_TRY();
886
887 /* Cleanup. */
889}
#define PG_TRY(...)
Definition elog.h:372
#define PG_END_TRY(...)
Definition elog.h:397
#define PG_FINALLY(...)
Definition elog.h:389
static bool slist_is_empty(const slist_head *head)
Definition ilist.h:995

References CommandCounterIncrement(), currentEventTriggerState, event_triggers, EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_SQLDrop, fb(), EventTriggerQueryState::in_sql_drop, IsUnderPostmaster, list_free(), NIL, PG_END_TRY, PG_FINALLY, PG_TRY, slist_is_empty(), and EventTriggerQueryState::SQLDropList.

Referenced by ProcessUtilitySlow().

◆ EventTriggerSQLDropAddObject()

void EventTriggerSQLDropAddObject ( const ObjectAddress object,
bool  original,
bool  normal 
)

Definition at line 1278 of file event_trigger.c.

1279{
1280 SQLDropObject *obj;
1282
1284 return;
1285
1287
1289
1291 obj->address = *object;
1292 obj->original = original;
1293 obj->normal = normal;
1294
1295 if (object->classId == NamespaceRelationId)
1296 {
1297 /* Special handling is needed for temp namespaces */
1298 if (isTempNamespace(object->objectId))
1299 obj->istemp = true;
1300 else if (isAnyTempNamespace(object->objectId))
1301 {
1302 /* don't report temp schemas except my own */
1303 pfree(obj);
1305 return;
1306 }
1307 obj->objname = get_namespace_name(object->objectId);
1308 }
1309 else if (object->classId == AttrDefaultRelationId)
1310 {
1311 /* We treat a column default as temp if its table is temp */
1313
1315 if (OidIsValid(colobject.objectId))
1316 {
1318 {
1319 pfree(obj);
1321 return;
1322 }
1323 }
1324 }
1325 else if (object->classId == TriggerRelationId)
1326 {
1327 /* Similarly, a trigger is temp if its table is temp */
1328 /* Sadly, there's no lsyscache.c support for trigger objects */
1330 ScanKeyData skey[1];
1332 HeapTuple tuple;
1333 Oid relid;
1334
1335 /* Fetch the trigger's table OID the hard way */
1337 ScanKeyInit(&skey[0],
1340 ObjectIdGetDatum(object->objectId));
1342 NULL, 1, skey);
1343 tuple = systable_getnext(sscan);
1344 if (HeapTupleIsValid(tuple))
1345 relid = ((Form_pg_trigger) GETSTRUCT(tuple))->tgrelid;
1346 else
1347 relid = InvalidOid; /* shouldn't happen */
1350 /* Do nothing if we didn't find the trigger */
1351 if (OidIsValid(relid))
1352 {
1354
1356 relobject.objectId = relid;
1357 /* Arbitrarily set objectSubId nonzero so as not to fill objname */
1358 relobject.objectSubId = 1;
1360 {
1361 pfree(obj);
1363 return;
1364 }
1365 }
1366 }
1367 else if (object->classId == PolicyRelationId)
1368 {
1369 /* Similarly, a policy is temp if its table is temp */
1370 /* Sadly, there's no lsyscache.c support for policy objects */
1372 ScanKeyData skey[1];
1374 HeapTuple tuple;
1375 Oid relid;
1376
1377 /* Fetch the policy's table OID the hard way */
1379 ScanKeyInit(&skey[0],
1382 ObjectIdGetDatum(object->objectId));
1384 NULL, 1, skey);
1385 tuple = systable_getnext(sscan);
1386 if (HeapTupleIsValid(tuple))
1387 relid = ((Form_pg_policy) GETSTRUCT(tuple))->polrelid;
1388 else
1389 relid = InvalidOid; /* shouldn't happen */
1392 /* Do nothing if we didn't find the policy */
1393 if (OidIsValid(relid))
1394 {
1396
1398 relobject.objectId = relid;
1399 /* Arbitrarily set objectSubId nonzero so as not to fill objname */
1400 relobject.objectSubId = 1;
1402 {
1403 pfree(obj);
1405 return;
1406 }
1407 }
1408 }
1409 else
1410 {
1411 /* Generic handling for all other object classes */
1412 if (!obtain_object_name_namespace(object, obj))
1413 {
1414 /* don't report temp objects except my own */
1415 pfree(obj);
1417 return;
1418 }
1419 }
1420
1421 /* object identity, objname and objargs */
1422 obj->objidentity =
1424 false);
1425
1426 /* object type */
1427 obj->objecttype = getObjectTypeDescription(&obj->address, false);
1428
1430
1432}
static bool obtain_object_name_namespace(const ObjectAddress *object, SQLDropObject *obj)
bool EventTriggerSupportsObject(const ObjectAddress *object)
void systable_endscan(SysScanDesc sysscan)
Definition genam.c:603
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition genam.c:514
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition genam.c:388
static void slist_push_head(slist_head *head, slist_node *node)
Definition ilist.h:1006
#define AccessShareLock
Definition lockdefs.h:36
char * get_namespace_name(Oid nspid)
Definition lsyscache.c:3588
bool isTempNamespace(Oid namespaceId)
Definition namespace.c:3721
bool isAnyTempNamespace(Oid namespaceId)
Definition namespace.c:3759
char * getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
ObjectAddress GetAttrDefaultColumnAddress(Oid attrdefoid)
Definition pg_attrdef.c:322
END_CATALOG_STRUCT typedef FormData_pg_policy * Form_pg_policy
Definition pg_policy.h:55
END_CATALOG_STRUCT typedef FormData_pg_trigger * Form_pg_trigger
Definition pg_trigger.h:84
ObjectAddress address
slist_node next
const char * objidentity
const char * objecttype
const char * objname

References AccessShareLock, SQLDropObject::addrargs, SQLDropObject::address, SQLDropObject::addrnames, Assert, BTEqualStrategyNumber, ObjectAddress::classId, currentEventTriggerState, EventTriggerQueryState::cxt, EventTriggerSupportsObject(), fb(), Form_pg_policy, Form_pg_trigger, get_namespace_name(), GetAttrDefaultColumnAddress(), getObjectIdentityParts(), getObjectTypeDescription(), GETSTRUCT(), HeapTupleIsValid, InvalidOid, isAnyTempNamespace(), SQLDropObject::istemp, isTempNamespace(), MemoryContextSwitchTo(), SQLDropObject::next, SQLDropObject::normal, ObjectAddress::objectId, ObjectIdGetDatum(), SQLDropObject::objecttype, SQLDropObject::objidentity, SQLDropObject::objname, obtain_object_name_namespace(), OidIsValid, SQLDropObject::original, palloc0_object, pfree(), ScanKeyInit(), slist_push_head(), EventTriggerQueryState::SQLDropList, systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by deleteObjectsInList(), and DropSubscription().

◆ EventTriggerSupportsObject()

bool EventTriggerSupportsObject ( const ObjectAddress object)

Definition at line 1158 of file event_trigger.c.

1159{
1160 switch (object->classId)
1161 {
1162 case DatabaseRelationId:
1164 case AuthIdRelationId:
1165 case AuthMemRelationId:
1167 /* no support for global objects (except subscriptions) */
1168 return false;
1170 /* no support for event triggers on event triggers */
1171 return false;
1172 default:
1173 return true;
1174 }
1175}

References ObjectAddress::classId, and fb().

Referenced by deleteObjectsInList(), and EventTriggerSQLDropAddObject().

◆ EventTriggerSupportsObjectType()

bool EventTriggerSupportsObjectType ( ObjectType  obtype)

Definition at line 1134 of file event_trigger.c.

1135{
1136 switch (obtype)
1137 {
1138 case OBJECT_DATABASE:
1139 case OBJECT_TABLESPACE:
1140 case OBJECT_ROLE:
1142 /* no support for global objects (except subscriptions) */
1143 return false;
1145 /* no support for event triggers on event triggers */
1146 return false;
1147 default:
1148 return true;
1149 }
1150}
@ OBJECT_TABLESPACE
@ OBJECT_ROLE
@ OBJECT_DATABASE
@ OBJECT_PARAMETER_ACL

References fb(), OBJECT_DATABASE, OBJECT_EVENT_TRIGGER, OBJECT_PARAMETER_ACL, OBJECT_ROLE, and OBJECT_TABLESPACE.

Referenced by ExecGrantStmt_oids(), and standard_ProcessUtility().

◆ EventTriggerTableRewrite()

void EventTriggerTableRewrite ( Node parsetree,
Oid  tableOid,
int  reason 
)

Definition at line 1004 of file event_trigger.c.

1005{
1006 List *runlist;
1007 EventTriggerData trigdata;
1008
1009 /*
1010 * See EventTriggerDDLCommandStart for a discussion about why event
1011 * triggers are disabled in single user mode or via a GUC.
1012 */
1014 return;
1015
1016 /*
1017 * Also do nothing if our state isn't set up, which it won't be if there
1018 * weren't any relevant event triggers at the start of the current DDL
1019 * command. This test might therefore seem optional, but it's
1020 * *necessary*, because EventTriggerCommonSetup might find triggers that
1021 * didn't exist at the time the command started.
1022 */
1024 return;
1025
1026 runlist = EventTriggerCommonSetup(parsetree,
1028 "table_rewrite",
1029 &trigdata, false);
1030 if (runlist == NIL)
1031 return;
1032
1033 /*
1034 * Make sure pg_event_trigger_table_rewrite_oid only works when running
1035 * these triggers. Use PG_TRY to ensure table_rewrite_oid is reset even
1036 * when one trigger fails. (This is perhaps not necessary, as the
1037 * currentState variable will be removed shortly by our caller, but it
1038 * seems better to play safe.)
1039 */
1042
1043 /* Run the triggers. */
1044 PG_TRY();
1045 {
1046 EventTriggerInvoke(runlist, &trigdata);
1047 }
1048 PG_FINALLY();
1049 {
1052 }
1053 PG_END_TRY();
1054
1055 /* Cleanup. */
1057
1058 /*
1059 * Make sure anything the event triggers did will be visible to the main
1060 * command.
1061 */
1063}

References CommandCounterIncrement(), currentEventTriggerState, event_triggers, EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_TableRewrite, fb(), InvalidOid, IsUnderPostmaster, list_free(), NIL, PG_END_TRY, PG_FINALLY, PG_TRY, EventTriggerQueryState::table_rewrite_oid, and EventTriggerQueryState::table_rewrite_reason.

Referenced by ATRewriteTables().

◆ EventTriggerUndoInhibitCommandCollection()

void EventTriggerUndoInhibitCommandCollection ( void  )

Definition at line 1694 of file event_trigger.c.

1695{
1697 return;
1698
1700}

References EventTriggerQueryState::commandCollectionInhibited, and currentEventTriggerState.

Referenced by ProcessUtilitySlow().

◆ filter_event_trigger()

static bool filter_event_trigger ( CommandTag  tag,
EventTriggerCacheItem item 
)
static

Definition at line 599 of file event_trigger.c.

600{
601 /*
602 * Filter by session replication role, knowing that we never see disabled
603 * items down here.
604 */
606 {
607 if (item->enabled == TRIGGER_FIRES_ON_ORIGIN)
608 return false;
609 }
610 else
611 {
613 return false;
614 }
615
616 /* Filter by tags, if any were specified. */
617 if (!bms_is_empty(item->tagset) && !bms_is_member(tag, item->tagset))
618 return false;
619
620 /* if we reach that point, we're not filtering out this item */
621 return true;
622}
bool bms_is_member(int x, const Bitmapset *a)
Definition bitmapset.c:510
#define bms_is_empty(a)
Definition bitmapset.h:118
Bitmapset * tagset
Definition evtcache.h:33
int SessionReplicationRole
Definition trigger.c:65
#define SESSION_REPLICATION_ROLE_REPLICA
Definition trigger.h:143
#define TRIGGER_FIRES_ON_ORIGIN
Definition trigger.h:151
#define TRIGGER_FIRES_ON_REPLICA
Definition trigger.h:153

References bms_is_empty, bms_is_member(), EventTriggerCacheItem::enabled, SESSION_REPLICATION_ROLE_REPLICA, SessionReplicationRole, EventTriggerCacheItem::tagset, TRIGGER_FIRES_ON_ORIGIN, and TRIGGER_FIRES_ON_REPLICA.

Referenced by EventTriggerCommonSetup().

◆ filter_list_to_array()

static Datum filter_list_to_array ( List filterlist)
static

Definition at line 361 of file event_trigger.c.

362{
363 ListCell *lc;
364 Datum *data;
365 int i = 0,
367
368 data = palloc_array(Datum, l);
369
370 foreach(lc, filterlist)
371 {
372 const char *value = strVal(lfirst(lc));
373 char *result,
374 *p;
375
376 result = pstrdup(value);
377 for (p = result; *p; p++)
378 *p = pg_ascii_toupper((unsigned char) *p);
380 pfree(result);
381 }
382
384}
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
static struct @174 value
int i
Definition isn.c:77
char * pstrdup(const char *in)
Definition mcxt.c:1781
const void * data
static int list_length(const List *l)
Definition pg_list.h:152
static unsigned char pg_ascii_toupper(unsigned char ch)
Definition port.h:177
static Datum PointerGetDatum(const void *X)
Definition postgres.h:342
uint64_t Datum
Definition postgres.h:70
#define strVal(v)
Definition value.h:82
text * cstring_to_text(const char *s)
Definition varlena.c:184

References construct_array_builtin(), cstring_to_text(), data, fb(), i, lfirst, list_length(), palloc_array, pfree(), pg_ascii_toupper(), PointerGetDatum(), pstrdup(), strVal, and value.

Referenced by insert_event_trigger_tuple().

◆ get_event_trigger_oid()

Oid get_event_trigger_oid ( const char trigname,
bool  missing_ok 
)

Definition at line 580 of file event_trigger.c.

581{
582 Oid oid;
583
585 CStringGetDatum(trigname));
586 if (!OidIsValid(oid) && !missing_ok)
589 errmsg("event trigger \"%s\" does not exist", trigname)));
590 return oid;
591}
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition syscache.h:109

References CStringGetDatum(), ereport, errcode(), errmsg, ERROR, fb(), GetSysCacheOid1, and OidIsValid.

Referenced by get_object_address_unqualified().

◆ insert_event_trigger_tuple()

static Oid insert_event_trigger_tuple ( const char trigname,
const char eventname,
Oid  evtOwner,
Oid  funcoid,
List taglist 
)
static

Definition at line 278 of file event_trigger.c.

280{
282 Oid trigoid;
283 HeapTuple tuple;
285 bool nulls[Natts_pg_event_trigger];
290
291 /* Open pg_event_trigger. */
293
294 /* Build the new pg_trigger tuple. */
298 memset(nulls, false, sizeof(nulls));
299 namestrcpy(&evtnamedata, trigname);
301 namestrcpy(&evteventdata, eventname);
307 if (taglist == NIL)
308 nulls[Anum_pg_event_trigger_evttags - 1] = true;
309 else
312
313 /* Insert heap tuple. */
314 tuple = heap_form_tuple(tgrel->rd_att, values, nulls);
316 heap_freetuple(tuple);
317
318 /*
319 * Login event triggers have an additional flag in pg_database to enable
320 * faster lookups in hot codepaths. Set the flag unless already True.
321 */
322 if (strcmp(eventname, "login") == 0)
324
325 /* Depend on owner. */
327
328 /* Depend on event trigger function. */
330 myself.objectId = trigoid;
331 myself.objectSubId = 0;
333 referenced.objectId = funcoid;
334 referenced.objectSubId = 0;
336
337 /* Depend on extension, if any. */
339
340 /* Post creation hook for new event trigger */
342
343 /* Close pg_event_trigger. */
345
346 return trigoid;
347}
static Datum values[MAXATTR]
Definition bootstrap.c:188
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition catalog.c:448
@ DEPENDENCY_NORMAL
Definition dependency.h:33
static Datum filter_list_to_array(List *filterlist)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition heaptuple.c:1037
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition indexing.c:233
void namestrcpy(Name name, const char *str)
Definition name.c:233
#define InvokeObjectPostCreateHook(classId, objectId, subId)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition pg_depend.c:47
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition pg_depend.c:195
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
static Datum NameGetDatum(const NameData *X)
Definition postgres.h:393
static Datum CharGetDatum(char X)
Definition postgres.h:132
Definition c.h:832

References CatalogTupleInsert(), CharGetDatum(), DEPENDENCY_NORMAL, fb(), filter_list_to_array(), GetNewOidWithIndex(), heap_form_tuple(), heap_freetuple(), InvokeObjectPostCreateHook, NameGetDatum(), namestrcpy(), NIL, ObjectIdGetDatum(), recordDependencyOn(), recordDependencyOnCurrentExtension(), recordDependencyOnOwner(), RowExclusiveLock, SetDatabaseHasLoginEventTriggers(), table_close(), table_open(), TRIGGER_FIRES_ON_ORIGIN, and values.

Referenced by CreateEventTrigger().

◆ obtain_object_name_namespace()

static bool obtain_object_name_namespace ( const ObjectAddress object,
SQLDropObject obj 
)
static

Definition at line 1441 of file event_trigger.c.

1442{
1443 /*
1444 * Obtain schema names from the object's catalog tuple, if one exists;
1445 * this lets us skip objects in temp schemas. We trust that
1446 * ObjectProperty contains all object classes that can be
1447 * schema-qualified.
1448 *
1449 * Currently, this function does nothing for object classes that are not
1450 * in ObjectProperty, but we might sometime add special cases for that.
1451 */
1452 if (is_objectclass_supported(object->classId))
1453 {
1455 HeapTuple tuple;
1456
1460 object->objectId);
1461
1462 if (tuple)
1463 {
1465 Datum datum;
1466 bool isnull;
1467
1470 {
1471 datum = heap_getattr(tuple, attnum,
1472 RelationGetDescr(catalog), &isnull);
1473 if (!isnull)
1474 {
1476
1478 /* temp objects are only reported if they are my own */
1480 {
1481 obj->schemaname = "pg_temp";
1482 obj->istemp = true;
1483 }
1485 {
1486 /* no need to fill any fields of *obj */
1488 return false;
1489 }
1490 else
1491 {
1493 obj->istemp = false;
1494 }
1495 }
1496 }
1497
1498 if (get_object_namensp_unique(object->classId) &&
1499 object->objectSubId == 0)
1500 {
1503 {
1504 datum = heap_getattr(tuple, attnum,
1505 RelationGetDescr(catalog), &isnull);
1506 if (!isnull)
1507 obj->objname = pstrdup(NameStr(*DatumGetName(datum)));
1508 }
1509 }
1510 }
1511
1513 }
1514
1515 return true;
1516}
int16 AttrNumber
Definition attnum.h:21
#define InvalidAttrNumber
Definition attnum.h:23
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
bool get_object_namensp_unique(Oid class_id)
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
AttrNumber get_object_attnum_oid(Oid class_id)
AttrNumber get_object_attnum_namespace(Oid class_id)
AttrNumber get_object_attnum_name(Oid class_id)
bool is_objectclass_supported(Oid class_id)
int16 attnum
static Name DatumGetName(Datum X)
Definition postgres.h:380
static Oid DatumGetObjectId(Datum X)
Definition postgres.h:242
#define RelationGetDescr(relation)
Definition rel.h:540
const char * schemaname

References AccessShareLock, attnum, ObjectAddress::classId, DatumGetName(), DatumGetObjectId(), fb(), get_catalog_object_by_oid(), get_namespace_name(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_oid(), get_object_namensp_unique(), heap_getattr(), InvalidAttrNumber, is_objectclass_supported(), isAnyTempNamespace(), SQLDropObject::istemp, isTempNamespace(), NameStr, ObjectAddress::objectId, ObjectAddress::objectSubId, SQLDropObject::objname, pstrdup(), RelationGetDescr, SQLDropObject::schemaname, table_close(), and table_open().

Referenced by EventTriggerSQLDropAddObject().

◆ pg_event_trigger_ddl_commands()

Datum pg_event_trigger_ddl_commands ( PG_FUNCTION_ARGS  )

Definition at line 2056 of file event_trigger.c.

2057{
2058 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
2059 ListCell *lc;
2060
2061 /*
2062 * Protect this function from being called out of context
2063 */
2065 ereport(ERROR,
2067 errmsg("%s can only be called in an event trigger function",
2068 "pg_event_trigger_ddl_commands()")));
2069
2070 /* Build tuplestore to hold the result rows */
2071 InitMaterializedSRF(fcinfo, 0);
2072
2074 {
2075 CollectedCommand *cmd = lfirst(lc);
2076 Datum values[9];
2077 bool nulls[9] = {0};
2078 ObjectAddress addr;
2079 int i = 0;
2080
2081 /*
2082 * For IF NOT EXISTS commands that attempt to create an existing
2083 * object, the returned OID is Invalid. Don't return anything.
2084 *
2085 * One might think that a viable alternative would be to look up the
2086 * Oid of the existing object and run the deparse with that. But
2087 * since the parse tree might be different from the one that created
2088 * the object in the first place, we might not end up in a consistent
2089 * state anyway.
2090 */
2091 if (cmd->type == SCT_Simple &&
2093 continue;
2094
2095 switch (cmd->type)
2096 {
2097 case SCT_Simple:
2098 case SCT_AlterTable:
2099 case SCT_AlterOpFamily:
2100 case SCT_CreateOpClass:
2101 case SCT_AlterTSConfig:
2102 {
2103 char *identity;
2104 char *type;
2105 char *schema = NULL;
2106
2107 if (cmd->type == SCT_Simple)
2108 addr = cmd->d.simple.address;
2109 else if (cmd->type == SCT_AlterTable)
2110 ObjectAddressSet(addr,
2111 cmd->d.alterTable.classId,
2112 cmd->d.alterTable.objectId);
2113 else if (cmd->type == SCT_AlterOpFamily)
2114 addr = cmd->d.opfam.address;
2115 else if (cmd->type == SCT_CreateOpClass)
2116 addr = cmd->d.createopc.address;
2117 else if (cmd->type == SCT_AlterTSConfig)
2118 addr = cmd->d.atscfg.address;
2119
2120 /*
2121 * If an object was dropped in the same command we may end
2122 * up in a situation where we generated a message but can
2123 * no longer look for the object information, so skip it
2124 * rather than failing. This can happen for example with
2125 * some subcommand combinations of ALTER TABLE.
2126 */
2127 identity = getObjectIdentity(&addr, true);
2128 if (identity == NULL)
2129 continue;
2130
2131 /* The type can never be NULL. */
2132 type = getObjectTypeDescription(&addr, true);
2133
2134 /*
2135 * Obtain schema name, if any ("pg_temp" if a temp
2136 * object). If the object class is not in the supported
2137 * list here, we assume it's a schema-less object type,
2138 * and thus "schema" remains set to NULL.
2139 */
2141 {
2143
2146 {
2150 bool isnull;
2151
2155 addr.objectId);
2157 elog(ERROR, "cache lookup failed for object %u/%u",
2158 addr.classId, addr.objectId);
2159 schema_oid =
2161 RelationGetDescr(catalog), &isnull));
2162 if (isnull)
2163 elog(ERROR,
2164 "invalid null namespace in object %u/%u/%d",
2165 addr.classId, addr.objectId, addr.objectSubId);
2167
2169 }
2170 }
2171
2172 /* classid */
2173 values[i++] = ObjectIdGetDatum(addr.classId);
2174 /* objid */
2175 values[i++] = ObjectIdGetDatum(addr.objectId);
2176 /* objsubid */
2177 values[i++] = Int32GetDatum(addr.objectSubId);
2178 /* command tag */
2180 /* object_type */
2182 /* schema */
2183 if (schema == NULL)
2184 nulls[i++] = true;
2185 else
2186 values[i++] = CStringGetTextDatum(schema);
2187 /* identity */
2188 values[i++] = CStringGetTextDatum(identity);
2189 /* in_extension */
2190 values[i++] = BoolGetDatum(cmd->in_extension);
2191 /* command */
2192 values[i++] = PointerGetDatum(cmd);
2193 }
2194 break;
2195
2197 /* classid */
2198 nulls[i++] = true;
2199 /* objid */
2200 nulls[i++] = true;
2201 /* objsubid */
2202 nulls[i++] = true;
2203 /* command tag */
2205 /* object_type */
2207 /* schema */
2208 nulls[i++] = true;
2209 /* identity */
2210 nulls[i++] = true;
2211 /* in_extension */
2212 values[i++] = BoolGetDatum(cmd->in_extension);
2213 /* command */
2214 values[i++] = PointerGetDatum(cmd);
2215 break;
2216
2217 case SCT_Grant:
2218 /* classid */
2219 nulls[i++] = true;
2220 /* objid */
2221 nulls[i++] = true;
2222 /* objsubid */
2223 nulls[i++] = true;
2224 /* command tag */
2226 "GRANT" : "REVOKE");
2227 /* object_type */
2229 /* schema */
2230 nulls[i++] = true;
2231 /* identity */
2232 nulls[i++] = true;
2233 /* in_extension */
2234 values[i++] = BoolGetDatum(cmd->in_extension);
2235 /* command */
2236 values[i++] = PointerGetDatum(cmd);
2237 break;
2238 }
2239
2240 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
2241 values, nulls);
2242 }
2243
2245}
#define CStringGetTextDatum(s)
Definition builtins.h:98
static const char * stringify_adefprivs_objtype(ObjectType objtype)
static const char * stringify_grant_objtype(ObjectType objtype)
#define PG_RETURN_VOID()
Definition fmgr.h:350
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition funcapi.c:76
char * get_namespace_name_or_temp(Oid nspid)
Definition lsyscache.c:3612
char * getObjectIdentity(const ObjectAddress *object, bool missing_ok)
static Datum BoolGetDatum(bool X)
Definition postgres.h:112
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
ObjectType objtype
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition tuplestore.c:785
static const char * CreateCommandName(Node *parsetree)
Definition utility.h:103
const char * type

References AccessShareLock, CollectedCommand::address, CollectedCommand::alterTable, CollectedCommand::atscfg, BoolGetDatum(), ObjectAddress::classId, CollectedCommand::classId, EventTriggerQueryState::commandList, CreateCommandName(), CollectedCommand::createopc, CStringGetTextDatum, currentEventTriggerState, CollectedCommand::d, DatumGetObjectId(), CollectedCommand::defprivs, elog, ereport, errcode(), errmsg, ERROR, fb(), get_catalog_object_by_oid(), get_namespace_name_or_temp(), get_object_attnum_namespace(), get_object_attnum_oid(), getObjectIdentity(), getObjectTypeDescription(), CollectedCommand::grant, heap_getattr(), HeapTupleIsValid, i, CollectedCommand::in_extension, InitMaterializedSRF(), Int32GetDatum(), InvalidAttrNumber, InternalGrant::is_grant, is_objectclass_supported(), CollectedCommand::istmt, lfirst, ObjectAddressSet, ObjectAddress::objectId, CollectedCommand::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, CollectedCommand::objtype, InternalGrant::objtype, OidIsValid, CollectedCommand::opfam, CollectedCommand::parsetree, PG_RETURN_VOID, PointerGetDatum(), RelationGetDescr, SCT_AlterDefaultPrivileges, SCT_AlterOpFamily, SCT_AlterTable, SCT_AlterTSConfig, SCT_CreateOpClass, SCT_Grant, SCT_Simple, CollectedCommand::simple, stringify_adefprivs_objtype(), stringify_grant_objtype(), table_close(), table_open(), tuplestore_putvalues(), type, CollectedCommand::type, and values.

◆ pg_event_trigger_dropped_objects()

Datum pg_event_trigger_dropped_objects ( PG_FUNCTION_ARGS  )

Definition at line 1525 of file event_trigger.c.

1526{
1527 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1528 slist_iter iter;
1529
1530 /*
1531 * Protect this function from being called out of context
1532 */
1535 ereport(ERROR,
1537 errmsg("%s can only be called in a sql_drop event trigger function",
1538 "pg_event_trigger_dropped_objects()")));
1539
1540 /* Build tuplestore to hold the result rows */
1541 InitMaterializedSRF(fcinfo, 0);
1542
1544 {
1545 SQLDropObject *obj;
1546 int i = 0;
1547 Datum values[12] = {0};
1548 bool nulls[12] = {0};
1549
1550 obj = slist_container(SQLDropObject, next, iter.cur);
1551
1552 /* classid */
1554
1555 /* objid */
1557
1558 /* objsubid */
1560
1561 /* original */
1562 values[i++] = BoolGetDatum(obj->original);
1563
1564 /* normal */
1565 values[i++] = BoolGetDatum(obj->normal);
1566
1567 /* is_temporary */
1568 values[i++] = BoolGetDatum(obj->istemp);
1569
1570 /* object_type */
1572
1573 /* schema_name */
1574 if (obj->schemaname)
1576 else
1577 nulls[i++] = true;
1578
1579 /* object_name */
1580 if (obj->objname)
1582 else
1583 nulls[i++] = true;
1584
1585 /* object_identity */
1586 if (obj->objidentity)
1588 else
1589 nulls[i++] = true;
1590
1591 /* address_names and address_args */
1592 if (obj->addrnames)
1593 {
1595
1596 if (obj->addrargs)
1598 else
1600 }
1601 else
1602 {
1603 nulls[i++] = true;
1604 nulls[i++] = true;
1605 }
1606
1607 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
1608 values, nulls);
1609 }
1610
1611 return (Datum) 0;
1612}
ArrayType * construct_empty_array(Oid elmtype)
static int32 next
Definition blutils.c:225
#define slist_container(type, membername, ptr)
Definition ilist.h:1106
#define slist_foreach(iter, lhead)
Definition ilist.h:1132
ArrayType * strlist_to_textarray(List *list)
slist_node * cur
Definition ilist.h:259

References SQLDropObject::addrargs, SQLDropObject::address, SQLDropObject::addrnames, BoolGetDatum(), ObjectAddress::classId, construct_empty_array(), CStringGetTextDatum, slist_iter::cur, currentEventTriggerState, ereport, errcode(), errmsg, ERROR, fb(), i, EventTriggerQueryState::in_sql_drop, InitMaterializedSRF(), Int32GetDatum(), SQLDropObject::istemp, next, SQLDropObject::normal, ObjectAddress::objectId, ObjectIdGetDatum(), ObjectAddress::objectSubId, SQLDropObject::objecttype, SQLDropObject::objidentity, SQLDropObject::objname, SQLDropObject::original, PointerGetDatum(), SQLDropObject::schemaname, slist_container, slist_foreach, EventTriggerQueryState::SQLDropList, strlist_to_textarray(), tuplestore_putvalues(), and values.

◆ pg_event_trigger_table_rewrite_oid()

Datum pg_event_trigger_table_rewrite_oid ( PG_FUNCTION_ARGS  )

Definition at line 1621 of file event_trigger.c.

1622{
1623 /*
1624 * Protect this function from being called out of context
1625 */
1628 ereport(ERROR,
1630 errmsg("%s can only be called in a table_rewrite event trigger function",
1631 "pg_event_trigger_table_rewrite_oid()")));
1632
1634}
#define PG_RETURN_OID(x)
Definition fmgr.h:361

References currentEventTriggerState, ereport, errcode(), errmsg, ERROR, fb(), InvalidOid, PG_RETURN_OID, and EventTriggerQueryState::table_rewrite_oid.

◆ pg_event_trigger_table_rewrite_reason()

Datum pg_event_trigger_table_rewrite_reason ( PG_FUNCTION_ARGS  )

Definition at line 1642 of file event_trigger.c.

1643{
1644 /*
1645 * Protect this function from being called out of context
1646 */
1649 ereport(ERROR,
1651 errmsg("%s can only be called in a table_rewrite event trigger function",
1652 "pg_event_trigger_table_rewrite_reason()")));
1653
1655}
#define PG_RETURN_INT32(x)
Definition fmgr.h:355

References currentEventTriggerState, ereport, errcode(), errmsg, ERROR, fb(), PG_RETURN_INT32, and EventTriggerQueryState::table_rewrite_reason.

◆ SetDatabaseHasLoginEventTriggers()

void SetDatabaseHasLoginEventTriggers ( void  )
static

Definition at line 391 of file event_trigger.c.

392{
393 /* Set dathasloginevt flag in pg_database */
397 HeapTuple tuple;
398
399 /*
400 * Use shared lock to prevent a conflict with EventTriggerOnLogin() trying
401 * to reset pg_database.dathasloginevt flag. Note, this lock doesn't
402 * effectively blocks database or other objection. It's just custom lock
403 * tag used to prevent multiple backends changing
404 * pg_database.dathasloginevt flag.
405 */
407
409 if (!HeapTupleIsValid(tuple))
410 elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
411 otid = tuple->t_self;
412 db = (Form_pg_database) GETSTRUCT(tuple);
413 if (!db->dathasloginevt)
414 {
415 db->dathasloginevt = true;
416 CatalogTupleUpdate(pg_db, &otid, tuple);
418 }
421 heap_freetuple(tuple);
422}
void UnlockTuple(Relation relation, const ItemPointerData *tid, LOCKMODE lockmode)
Definition lmgr.c:601
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition lmgr.c:1088
#define InplaceUpdateTupleLock
Definition lockdefs.h:48
ItemPointerData t_self
Definition htup.h:65
HeapTuple SearchSysCacheLockedCopy1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:399

References AccessExclusiveLock, CatalogTupleUpdate(), CommandCounterIncrement(), elog, ERROR, fb(), Form_pg_database, GETSTRUCT(), heap_freetuple(), HeapTupleIsValid, InplaceUpdateTupleLock, LockSharedObject(), MyDatabaseId, ObjectIdGetDatum(), RowExclusiveLock, SearchSysCacheLockedCopy1(), HeapTupleData::t_self, table_close(), table_open(), and UnlockTuple().

Referenced by AlterEventTrigger(), and insert_event_trigger_tuple().

◆ stringify_adefprivs_objtype()

static const char * stringify_adefprivs_objtype ( ObjectType  objtype)
static

Definition at line 2338 of file event_trigger.c.

2339{
2340 switch (objtype)
2341 {
2342 case OBJECT_COLUMN:
2343 return "COLUMNS";
2344 case OBJECT_TABLE:
2345 return "TABLES";
2346 case OBJECT_SEQUENCE:
2347 return "SEQUENCES";
2348 case OBJECT_DATABASE:
2349 return "DATABASES";
2350 case OBJECT_DOMAIN:
2351 return "DOMAINS";
2352 case OBJECT_FDW:
2353 return "FOREIGN DATA WRAPPERS";
2355 return "FOREIGN SERVERS";
2356 case OBJECT_FUNCTION:
2357 return "FUNCTIONS";
2358 case OBJECT_LANGUAGE:
2359 return "LANGUAGES";
2360 case OBJECT_LARGEOBJECT:
2361 return "LARGE OBJECTS";
2362 case OBJECT_SCHEMA:
2363 return "SCHEMAS";
2364 case OBJECT_PROCEDURE:
2365 return "PROCEDURES";
2366 case OBJECT_ROUTINE:
2367 return "ROUTINES";
2368 case OBJECT_TABLESPACE:
2369 return "TABLESPACES";
2370 case OBJECT_TYPE:
2371 return "TYPES";
2372 /* these currently aren't used */
2374 case OBJECT_AGGREGATE:
2375 case OBJECT_AMOP:
2376 case OBJECT_AMPROC:
2377 case OBJECT_ATTRIBUTE:
2378 case OBJECT_CAST:
2379 case OBJECT_COLLATION:
2380 case OBJECT_CONVERSION:
2381 case OBJECT_DEFAULT:
2382 case OBJECT_DEFACL:
2385 case OBJECT_EXTENSION:
2387 case OBJECT_INDEX:
2388 case OBJECT_MATVIEW:
2389 case OBJECT_OPCLASS:
2390 case OBJECT_OPERATOR:
2391 case OBJECT_OPFAMILY:
2393 case OBJECT_POLICY:
2394 case OBJECT_PROPGRAPH:
2395 case OBJECT_PUBLICATION:
2398 case OBJECT_ROLE:
2399 case OBJECT_RULE:
2403 case OBJECT_TRANSFORM:
2404 case OBJECT_TRIGGER:
2407 case OBJECT_TSPARSER:
2408 case OBJECT_TSTEMPLATE:
2410 case OBJECT_VIEW:
2411 elog(ERROR, "unsupported object type: %d", (int) objtype);
2412 }
2413
2414 return "???"; /* keep compiler quiet */
2415}
@ OBJECT_FDW
@ OBJECT_TSPARSER
@ OBJECT_COLLATION
@ OBJECT_USER_MAPPING
@ OBJECT_PROPGRAPH
@ OBJECT_ACCESS_METHOD
@ OBJECT_OPCLASS
@ OBJECT_DEFACL
@ OBJECT_AGGREGATE
@ OBJECT_MATVIEW
@ OBJECT_SCHEMA
@ OBJECT_POLICY
@ OBJECT_OPERATOR
@ OBJECT_FOREIGN_TABLE
@ OBJECT_TSCONFIGURATION
@ OBJECT_OPFAMILY
@ OBJECT_DOMAIN
@ OBJECT_COLUMN
@ OBJECT_ROUTINE
@ OBJECT_LARGEOBJECT
@ OBJECT_PUBLICATION_NAMESPACE
@ OBJECT_PROCEDURE
@ OBJECT_EXTENSION
@ OBJECT_INDEX
@ OBJECT_DEFAULT
@ OBJECT_SEQUENCE
@ OBJECT_TSTEMPLATE
@ OBJECT_LANGUAGE
@ OBJECT_AMOP
@ OBJECT_PUBLICATION_REL
@ OBJECT_FOREIGN_SERVER
@ OBJECT_TSDICTIONARY
@ OBJECT_ATTRIBUTE
@ OBJECT_PUBLICATION
@ OBJECT_RULE
@ OBJECT_CONVERSION
@ OBJECT_AMPROC
@ OBJECT_TABLE
@ OBJECT_VIEW
@ OBJECT_TYPE
@ OBJECT_FUNCTION
@ OBJECT_TABCONSTRAINT
@ OBJECT_DOMCONSTRAINT
@ OBJECT_SUBSCRIPTION
@ OBJECT_STATISTIC_EXT
@ OBJECT_CAST
@ OBJECT_TRIGGER
@ OBJECT_TRANSFORM

References elog, ERROR, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_PARAMETER_ACL, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PROPGRAPH, OBJECT_PUBLICATION, OBJECT_PUBLICATION_NAMESPACE, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, and OBJECT_VIEW.

Referenced by pg_event_trigger_ddl_commands().

◆ stringify_grant_objtype()

static const char * stringify_grant_objtype ( ObjectType  objtype)
static

Definition at line 2252 of file event_trigger.c.

2253{
2254 switch (objtype)
2255 {
2256 case OBJECT_COLUMN:
2257 return "COLUMN";
2258 case OBJECT_TABLE:
2259 return "TABLE";
2260 case OBJECT_SEQUENCE:
2261 return "SEQUENCE";
2262 case OBJECT_DATABASE:
2263 return "DATABASE";
2264 case OBJECT_DOMAIN:
2265 return "DOMAIN";
2266 case OBJECT_FDW:
2267 return "FOREIGN DATA WRAPPER";
2269 return "FOREIGN SERVER";
2270 case OBJECT_FUNCTION:
2271 return "FUNCTION";
2272 case OBJECT_LANGUAGE:
2273 return "LANGUAGE";
2274 case OBJECT_LARGEOBJECT:
2275 return "LARGE OBJECT";
2276 case OBJECT_SCHEMA:
2277 return "SCHEMA";
2279 return "PARAMETER";
2280 case OBJECT_PROCEDURE:
2281 return "PROCEDURE";
2282 case OBJECT_ROUTINE:
2283 return "ROUTINE";
2284 case OBJECT_TABLESPACE:
2285 return "TABLESPACE";
2286 case OBJECT_TYPE:
2287 return "TYPE";
2288 /* these currently aren't used */
2290 case OBJECT_AGGREGATE:
2291 case OBJECT_AMOP:
2292 case OBJECT_AMPROC:
2293 case OBJECT_ATTRIBUTE:
2294 case OBJECT_CAST:
2295 case OBJECT_COLLATION:
2296 case OBJECT_CONVERSION:
2297 case OBJECT_DEFAULT:
2298 case OBJECT_DEFACL:
2301 case OBJECT_EXTENSION:
2303 case OBJECT_INDEX:
2304 case OBJECT_MATVIEW:
2305 case OBJECT_OPCLASS:
2306 case OBJECT_OPERATOR:
2307 case OBJECT_OPFAMILY:
2308 case OBJECT_POLICY:
2309 case OBJECT_PROPGRAPH:
2310 case OBJECT_PUBLICATION:
2313 case OBJECT_ROLE:
2314 case OBJECT_RULE:
2318 case OBJECT_TRANSFORM:
2319 case OBJECT_TRIGGER:
2322 case OBJECT_TSPARSER:
2323 case OBJECT_TSTEMPLATE:
2325 case OBJECT_VIEW:
2326 elog(ERROR, "unsupported object type: %d", (int) objtype);
2327 }
2328
2329 return "???"; /* keep compiler quiet */
2330}

References elog, ERROR, OBJECT_ACCESS_METHOD, OBJECT_AGGREGATE, OBJECT_AMOP, OBJECT_AMPROC, OBJECT_ATTRIBUTE, OBJECT_CAST, OBJECT_COLLATION, OBJECT_COLUMN, OBJECT_CONVERSION, OBJECT_DATABASE, OBJECT_DEFACL, OBJECT_DEFAULT, OBJECT_DOMAIN, OBJECT_DOMCONSTRAINT, OBJECT_EVENT_TRIGGER, OBJECT_EXTENSION, OBJECT_FDW, OBJECT_FOREIGN_SERVER, OBJECT_FOREIGN_TABLE, OBJECT_FUNCTION, OBJECT_INDEX, OBJECT_LANGUAGE, OBJECT_LARGEOBJECT, OBJECT_MATVIEW, OBJECT_OPCLASS, OBJECT_OPERATOR, OBJECT_OPFAMILY, OBJECT_PARAMETER_ACL, OBJECT_POLICY, OBJECT_PROCEDURE, OBJECT_PROPGRAPH, OBJECT_PUBLICATION, OBJECT_PUBLICATION_NAMESPACE, OBJECT_PUBLICATION_REL, OBJECT_ROLE, OBJECT_ROUTINE, OBJECT_RULE, OBJECT_SCHEMA, OBJECT_SEQUENCE, OBJECT_STATISTIC_EXT, OBJECT_SUBSCRIPTION, OBJECT_TABCONSTRAINT, OBJECT_TABLE, OBJECT_TABLESPACE, OBJECT_TRANSFORM, OBJECT_TRIGGER, OBJECT_TSCONFIGURATION, OBJECT_TSDICTIONARY, OBJECT_TSPARSER, OBJECT_TSTEMPLATE, OBJECT_TYPE, OBJECT_USER_MAPPING, and OBJECT_VIEW.

Referenced by pg_event_trigger_ddl_commands().

◆ trackDroppedObjectsNeeded()

bool trackDroppedObjectsNeeded ( void  )

Definition at line 1246 of file event_trigger.c.

1247{
1248 /*
1249 * true if any sql_drop, table_rewrite, ddl_command_end event trigger
1250 * exists
1251 */
1252 return (EventCacheLookup(EVT_SQLDrop) != NIL) ||
1255}

References EventCacheLookup(), EVT_DDLCommandEnd, EVT_SQLDrop, EVT_TableRewrite, and NIL.

Referenced by deleteObjectsInList(), and EventTriggerBeginCompleteQuery().

◆ validate_ddl_tags()

static void validate_ddl_tags ( const char filtervar,
List taglist 
)
static

Definition at line 217 of file event_trigger.c.

218{
219 ListCell *lc;
220
221 foreach(lc, taglist)
222 {
223 const char *tagstr = strVal(lfirst(lc));
224 CommandTag commandTag = GetCommandTagEnum(tagstr);
225
226 if (commandTag == CMDTAG_UNKNOWN)
229 errmsg("filter value \"%s\" not recognized for filter variable \"%s\"",
230 tagstr, filtervar)));
231 if (!command_tag_event_trigger_ok(commandTag))
234 /* translator: %s represents an SQL statement name */
235 errmsg("event triggers are not supported for %s",
236 tagstr)));
237 }
238}
CommandTag GetCommandTagEnum(const char *commandname)
Definition cmdtag.c:83

References command_tag_event_trigger_ok(), ereport, errcode(), errmsg, ERROR, fb(), GetCommandTagEnum(), lfirst, and strVal.

Referenced by CreateEventTrigger().

◆ validate_table_rewrite_tags()

static void validate_table_rewrite_tags ( const char filtervar,
List taglist 
)
static

Definition at line 244 of file event_trigger.c.

245{
246 ListCell *lc;
247
248 foreach(lc, taglist)
249 {
250 const char *tagstr = strVal(lfirst(lc));
251 CommandTag commandTag = GetCommandTagEnum(tagstr);
252
253 if (!command_tag_table_rewrite_ok(commandTag))
256 /* translator: %s represents an SQL statement name */
257 errmsg("event triggers are not supported for %s",
258 tagstr)));
259 }
260}

References command_tag_table_rewrite_ok(), ereport, errcode(), errmsg, ERROR, fb(), GetCommandTagEnum(), lfirst, and strVal.

Referenced by CreateEventTrigger().

Variable Documentation

◆ currentEventTriggerState

◆ event_triggers