PostgreSQL Source Code  git master
event_trigger.h File Reference
Include dependency graph for event_trigger.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  EventTriggerData
 

Macros

#define AT_REWRITE_ALTER_PERSISTENCE   0x01
 
#define AT_REWRITE_DEFAULT_VAL   0x02
 
#define AT_REWRITE_COLUMN_REWRITE   0x04
 
#define AT_REWRITE_ACCESS_METHOD   0x08
 
#define CALLED_AS_EVENT_TRIGGER(fcinfo)    ((fcinfo)->context != NULL && IsA((fcinfo)->context, EventTriggerData))
 

Typedefs

typedef struct EventTriggerData EventTriggerData
 

Functions

Oid CreateEventTrigger (CreateEventTrigStmt *stmt)
 
Oid get_event_trigger_oid (const char *trigname, bool missing_ok)
 
Oid AlterEventTrigger (AlterEventTrigStmt *stmt)
 
ObjectAddress AlterEventTriggerOwner (const char *name, Oid newOwnerId)
 
void AlterEventTriggerOwner_oid (Oid, Oid newOwnerId)
 
bool EventTriggerSupportsObjectType (ObjectType obtype)
 
bool EventTriggerSupportsObjectClass (ObjectClass objclass)
 
void EventTriggerDDLCommandStart (Node *parsetree)
 
void EventTriggerDDLCommandEnd (Node *parsetree)
 
void EventTriggerSQLDrop (Node *parsetree)
 
void EventTriggerTableRewrite (Node *parsetree, Oid tableOid, int reason)
 
void EventTriggerOnLogin (void)
 
bool EventTriggerBeginCompleteQuery (void)
 
void EventTriggerEndCompleteQuery (void)
 
bool trackDroppedObjectsNeeded (void)
 
void EventTriggerSQLDropAddObject (const ObjectAddress *object, bool original, bool normal)
 
void EventTriggerInhibitCommandCollection (void)
 
void EventTriggerUndoInhibitCommandCollection (void)
 
void EventTriggerCollectSimpleCommand (ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
 
void EventTriggerAlterTableStart (Node *parsetree)
 
void EventTriggerAlterTableRelid (Oid objectId)
 
void EventTriggerCollectAlterTableSubcmd (Node *subcmd, ObjectAddress address)
 
void EventTriggerAlterTableEnd (void)
 
void EventTriggerCollectGrant (InternalGrant *istmt)
 
void EventTriggerCollectAlterOpFam (AlterOpFamilyStmt *stmt, Oid opfamoid, List *operators, List *procedures)
 
void EventTriggerCollectCreateOpClass (CreateOpClassStmt *stmt, Oid opcoid, List *operators, List *procedures)
 
void EventTriggerCollectAlterTSConfig (AlterTSConfigurationStmt *stmt, Oid cfgId, Oid *dictIds, int ndicts)
 
void EventTriggerCollectAlterDefPrivs (AlterDefaultPrivilegesStmt *stmt)
 

Variables

PGDLLIMPORT bool event_triggers
 

Macro Definition Documentation

◆ AT_REWRITE_ACCESS_METHOD

#define AT_REWRITE_ACCESS_METHOD   0x08

Definition at line 37 of file event_trigger.h.

◆ AT_REWRITE_ALTER_PERSISTENCE

#define AT_REWRITE_ALTER_PERSISTENCE   0x01

Definition at line 34 of file event_trigger.h.

◆ AT_REWRITE_COLUMN_REWRITE

#define AT_REWRITE_COLUMN_REWRITE   0x04

Definition at line 36 of file event_trigger.h.

◆ AT_REWRITE_DEFAULT_VAL

#define AT_REWRITE_DEFAULT_VAL   0x02

Definition at line 35 of file event_trigger.h.

◆ CALLED_AS_EVENT_TRIGGER

#define CALLED_AS_EVENT_TRIGGER (   fcinfo)     ((fcinfo)->context != NULL && IsA((fcinfo)->context, EventTriggerData))

Definition at line 43 of file event_trigger.h.

Typedef Documentation

◆ EventTriggerData

Function Documentation

◆ AlterEventTrigger()

Oid AlterEventTrigger ( AlterEventTrigStmt stmt)

Definition at line 417 of file event_trigger.c.

418 {
419  Relation tgrel;
420  HeapTuple tup;
421  Oid trigoid;
422  Form_pg_event_trigger evtForm;
423  char tgenabled = stmt->tgenabled;
424 
425  tgrel = table_open(EventTriggerRelationId, RowExclusiveLock);
426 
427  tup = SearchSysCacheCopy1(EVENTTRIGGERNAME,
428  CStringGetDatum(stmt->trigname));
429  if (!HeapTupleIsValid(tup))
430  ereport(ERROR,
431  (errcode(ERRCODE_UNDEFINED_OBJECT),
432  errmsg("event trigger \"%s\" does not exist",
433  stmt->trigname)));
434 
435  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
436  trigoid = evtForm->oid;
437 
438  if (!object_ownercheck(EventTriggerRelationId, trigoid, GetUserId()))
440  stmt->trigname);
441 
442  /* tuple is a copy, so we can modify it below */
443  evtForm->evtenabled = tgenabled;
444 
445  CatalogTupleUpdate(tgrel, &tup->t_self, tup);
446 
447  /*
448  * Login event triggers have an additional flag in pg_database to avoid
449  * faster lookups in hot codepaths. Set the flag unless already True.
450  */
451  if (namestrcmp(&evtForm->evtevent, "login") == 0 &&
452  tgenabled != TRIGGER_DISABLED)
454 
455  InvokeObjectPostAlterHook(EventTriggerRelationId,
456  trigoid, 0);
457 
458  /* clean up */
459  heap_freetuple(tup);
461 
462  return trigoid;
463 }
@ ACLCHECK_NOT_OWNER
Definition: acl.h:184
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2701
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:4132
int errcode(int sqlerrcode)
Definition: elog.c:860
int errmsg(const char *fmt,...)
Definition: elog.c:1075
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
static void SetDatatabaseHasLoginEventTriggers(void)
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
#define stmt
Definition: indent_codes.h:59
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:313
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid GetUserId(void)
Definition: miscinit.c:515
int namestrcmp(Name name, const char *str)
Definition: name.c:247
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:197
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:2110
FormData_pg_event_trigger * Form_pg_event_trigger
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:350
unsigned int Oid
Definition: postgres_ext.h:31
ItemPointerData t_self
Definition: htup.h:65
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:86
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:152

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

Referenced by standard_ProcessUtility().

◆ AlterEventTriggerOwner()

ObjectAddress AlterEventTriggerOwner ( const char *  name,
Oid  newOwnerId 
)

Definition at line 469 of file event_trigger.c.

470 {
471  Oid evtOid;
472  HeapTuple tup;
473  Form_pg_event_trigger evtForm;
474  Relation rel;
475  ObjectAddress address;
476 
477  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
478 
479  tup = SearchSysCacheCopy1(EVENTTRIGGERNAME, CStringGetDatum(name));
480 
481  if (!HeapTupleIsValid(tup))
482  ereport(ERROR,
483  (errcode(ERRCODE_UNDEFINED_OBJECT),
484  errmsg("event trigger \"%s\" does not exist", name)));
485 
486  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
487  evtOid = evtForm->oid;
488 
489  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
490 
491  ObjectAddressSet(address, EventTriggerRelationId, evtOid);
492 
493  heap_freetuple(tup);
494 
496 
497  return address;
498 }
static void AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
const char * name

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

Referenced by ExecAlterOwnerStmt().

◆ AlterEventTriggerOwner_oid()

void AlterEventTriggerOwner_oid ( Oid  trigOid,
Oid  newOwnerId 
)

Definition at line 504 of file event_trigger.c.

505 {
506  HeapTuple tup;
507  Relation rel;
508 
509  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
510 
511  tup = SearchSysCacheCopy1(EVENTTRIGGEROID, ObjectIdGetDatum(trigOid));
512 
513  if (!HeapTupleIsValid(tup))
514  ereport(ERROR,
515  (errcode(ERRCODE_UNDEFINED_OBJECT),
516  errmsg("event trigger with OID %u does not exist", trigOid)));
517 
518  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
519 
520  heap_freetuple(tup);
521 
523 }
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252

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

Referenced by shdepReassignOwned().

◆ CreateEventTrigger()

Oid CreateEventTrigger ( CreateEventTrigStmt stmt)

Definition at line 117 of file event_trigger.c.

118 {
119  HeapTuple tuple;
120  Oid funcoid;
121  Oid funcrettype;
122  Oid evtowner = GetUserId();
123  ListCell *lc;
124  List *tags = NULL;
125 
126  /*
127  * It would be nice to allow database owners or even regular users to do
128  * this, but there are obvious privilege escalation risks which would have
129  * to somehow be plugged first.
130  */
131  if (!superuser())
132  ereport(ERROR,
133  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
134  errmsg("permission denied to create event trigger \"%s\"",
135  stmt->trigname),
136  errhint("Must be superuser to create an event trigger.")));
137 
138  /* Validate event name. */
139  if (strcmp(stmt->eventname, "ddl_command_start") != 0 &&
140  strcmp(stmt->eventname, "ddl_command_end") != 0 &&
141  strcmp(stmt->eventname, "sql_drop") != 0 &&
142  strcmp(stmt->eventname, "login") != 0 &&
143  strcmp(stmt->eventname, "table_rewrite") != 0)
144  ereport(ERROR,
145  (errcode(ERRCODE_SYNTAX_ERROR),
146  errmsg("unrecognized event name \"%s\"",
147  stmt->eventname)));
148 
149  /* Validate filter conditions. */
150  foreach(lc, stmt->whenclause)
151  {
152  DefElem *def = (DefElem *) lfirst(lc);
153 
154  if (strcmp(def->defname, "tag") == 0)
155  {
156  if (tags != NULL)
158  tags = (List *) def->arg;
159  }
160  else
161  ereport(ERROR,
162  (errcode(ERRCODE_SYNTAX_ERROR),
163  errmsg("unrecognized filter variable \"%s\"", def->defname)));
164  }
165 
166  /* Validate tag list, if any. */
167  if ((strcmp(stmt->eventname, "ddl_command_start") == 0 ||
168  strcmp(stmt->eventname, "ddl_command_end") == 0 ||
169  strcmp(stmt->eventname, "sql_drop") == 0)
170  && tags != NULL)
171  validate_ddl_tags("tag", tags);
172  else if (strcmp(stmt->eventname, "table_rewrite") == 0
173  && tags != NULL)
174  validate_table_rewrite_tags("tag", tags);
175  else if (strcmp(stmt->eventname, "login") == 0 && tags != NULL)
176  ereport(ERROR,
177  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
178  errmsg("tag filtering is not supported for login event trigger")));
179 
180  /*
181  * Give user a nice error message if an event trigger of the same name
182  * already exists.
183  */
184  tuple = SearchSysCache1(EVENTTRIGGERNAME, CStringGetDatum(stmt->trigname));
185  if (HeapTupleIsValid(tuple))
186  ereport(ERROR,
188  errmsg("event trigger \"%s\" already exists",
189  stmt->trigname)));
190 
191  /* Find and validate the trigger function. */
192  funcoid = LookupFuncName(stmt->funcname, 0, NULL, false);
193  funcrettype = get_func_rettype(funcoid);
194  if (funcrettype != EVENT_TRIGGEROID)
195  ereport(ERROR,
196  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
197  errmsg("function %s must return type %s",
198  NameListToString(stmt->funcname), "event_trigger")));
199 
200  /* Insert catalog entries. */
201  return insert_event_trigger_tuple(stmt->trigname, stmt->eventname,
202  evtowner, funcoid, tags);
203 }
int errhint(const char *fmt,...)
Definition: elog.c:1322
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:1632
char * NameListToString(const List *names)
Definition: namespace.c:3579
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
Definition: parse_func.c:2143
#define lfirst(lc)
Definition: pg_list.h:172
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:32
char * defname
Definition: parsenodes.h:802
Node * arg
Definition: parsenodes.h:803
Definition: pg_list.h:54
bool superuser(void)
Definition: superuser.c:46
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:219

References DefElem::arg, CStringGetDatum(), DefElem::defname, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errhint(), errmsg(), ERROR, error_duplicate_filter_variable(), 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().

◆ EventTriggerAlterTableEnd()

void EventTriggerAlterTableEnd ( void  )

Definition at line 1804 of file event_trigger.c.

1805 {
1806  CollectedCommand *parent;
1807 
1808  /* ignore if event trigger context not set, or collection disabled */
1809  if (!currentEventTriggerState ||
1811  return;
1812 
1814 
1815  /* If no subcommands, don't collect */
1817  {
1818  MemoryContext oldcxt;
1819 
1821 
1825 
1826  MemoryContextSwitchTo(oldcxt);
1827  }
1828  else
1830 
1832 }
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:78
List * lappend(List *list, void *datum)
Definition: list.c:339
void pfree(void *pointer)
Definition: mcxt.c:1431
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
#define NIL
Definition: pg_list.h:68
union CollectedCommand::@112 d
struct CollectedCommand * parent
struct CollectedCommand::@112::@114 alterTable
CollectedCommand * currentCommand
Definition: event_trigger.c:72

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

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

◆ EventTriggerAlterTableRelid()

◆ EventTriggerAlterTableStart()

void EventTriggerAlterTableStart ( Node parsetree)

Definition at line 1717 of file event_trigger.c.

1718 {
1719  MemoryContext oldcxt;
1720  CollectedCommand *command;
1721 
1722  /* ignore if event trigger context not set, or collection disabled */
1723  if (!currentEventTriggerState ||
1725  return;
1726 
1728 
1729  command = palloc(sizeof(CollectedCommand));
1730 
1731  command->type = SCT_AlterTable;
1732  command->in_extension = creating_extension;
1733 
1734  command->d.alterTable.classId = RelationRelationId;
1735  command->d.alterTable.objectId = InvalidOid;
1736  command->d.alterTable.subcmds = NIL;
1737  command->parsetree = copyObject(parsetree);
1738 
1741 
1742  MemoryContextSwitchTo(oldcxt);
1743 }
@ SCT_AlterTable
bool creating_extension
Definition: extension.c:73
void * palloc(Size size)
Definition: mcxt.c:1201
#define copyObject(obj)
Definition: nodes.h:223
#define InvalidOid
Definition: postgres_ext.h:36
CollectedCommandType type

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

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

◆ EventTriggerBeginCompleteQuery()

bool EventTriggerBeginCompleteQuery ( void  )

Definition at line 1275 of file event_trigger.c.

1276 {
1278  MemoryContext cxt;
1279 
1280  /*
1281  * Currently, sql_drop, table_rewrite, ddl_command_end events are the only
1282  * reason to have event trigger state at all; so if there are none, don't
1283  * install one.
1284  */
1286  return false;
1287 
1289  "event trigger state",
1292  state->cxt = cxt;
1293  slist_init(&(state->SQLDropList));
1294  state->in_sql_drop = false;
1295  state->table_rewrite_oid = InvalidOid;
1296 
1297  state->commandCollectionInhibited = currentEventTriggerState ?
1299  state->currentCommand = NULL;
1300  state->commandList = NIL;
1301  state->previous = currentEventTriggerState;
1303 
1304  return true;
1305 }
bool trackDroppedObjectsNeeded(void)
static void slist_init(slist_head *head)
Definition: ilist.h:986
MemoryContext TopMemoryContext
Definition: mcxt.c:141
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1034
#define AllocSetContextCreate
Definition: memutils.h:128
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:152
Definition: regguts.h:323

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerCollectAlterDefPrivs()

void EventTriggerCollectAlterDefPrivs ( AlterDefaultPrivilegesStmt stmt)

Definition at line 1988 of file event_trigger.c.

1989 {
1990  MemoryContext oldcxt;
1991  CollectedCommand *command;
1992 
1993  /* ignore if event trigger context not set, or collection disabled */
1994  if (!currentEventTriggerState ||
1996  return;
1997 
1999 
2000  command = palloc0(sizeof(CollectedCommand));
2001  command->type = SCT_AlterDefaultPrivileges;
2002  command->d.defprivs.objtype = stmt->action->objtype;
2003  command->in_extension = creating_extension;
2004  command->parsetree = (Node *) copyObject(stmt);
2005 
2008  MemoryContextSwitchTo(oldcxt);
2009 }
@ SCT_AlterDefaultPrivileges
void * palloc0(Size size)
Definition: mcxt.c:1232
struct CollectedCommand::@112::@119 defprivs
Definition: nodes.h:129

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerCollectAlterOpFam()

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

Definition at line 1886 of file event_trigger.c.

1888 {
1889  MemoryContext oldcxt;
1890  CollectedCommand *command;
1891 
1892  /* ignore if event trigger context not set, or collection disabled */
1893  if (!currentEventTriggerState ||
1895  return;
1896 
1898 
1899  command = palloc(sizeof(CollectedCommand));
1900  command->type = SCT_AlterOpFamily;
1901  command->in_extension = creating_extension;
1902  ObjectAddressSet(command->d.opfam.address,
1903  OperatorFamilyRelationId, opfamoid);
1904  command->d.opfam.operators = operators;
1905  command->d.opfam.procedures = procedures;
1906  command->parsetree = (Node *) copyObject(stmt);
1907 
1910 
1911  MemoryContextSwitchTo(oldcxt);
1912 }
@ SCT_AlterOpFamily
struct CollectedCommand::@112::@116 opfam

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

Referenced by AlterOpFamilyAdd(), and AlterOpFamilyDrop().

◆ EventTriggerCollectAlterTableSubcmd()

void EventTriggerCollectAlterTableSubcmd ( Node subcmd,
ObjectAddress  address 
)

Definition at line 1769 of file event_trigger.c.

1770 {
1771  MemoryContext oldcxt;
1773 
1774  /* ignore if event trigger context not set, or collection disabled */
1775  if (!currentEventTriggerState ||
1777  return;
1778 
1779  Assert(IsA(subcmd, AlterTableCmd));
1782 
1784 
1785  newsub = palloc(sizeof(CollectedATSubcmd));
1786  newsub->address = address;
1787  newsub->parsetree = copyObject(subcmd);
1788 
1791 
1792  MemoryContextSwitchTo(oldcxt);
1793 }
#define OidIsValid(objectId)
Definition: c.h:764
Assert(fmt[strlen(fmt) - 1] !='\n')
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
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, IsA, lappend(), MemoryContextSwitchTo(), newsub(), OidIsValid, and palloc().

Referenced by ATExecCmd().

◆ EventTriggerCollectAlterTSConfig()

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

Definition at line 1953 of file event_trigger.c.

1955 {
1956  MemoryContext oldcxt;
1957  CollectedCommand *command;
1958 
1959  /* ignore if event trigger context not set, or collection disabled */
1960  if (!currentEventTriggerState ||
1962  return;
1963 
1965 
1966  command = palloc0(sizeof(CollectedCommand));
1967  command->type = SCT_AlterTSConfig;
1968  command->in_extension = creating_extension;
1969  ObjectAddressSet(command->d.atscfg.address,
1970  TSConfigRelationId, cfgId);
1971  command->d.atscfg.dictIds = palloc(sizeof(Oid) * ndicts);
1972  memcpy(command->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts);
1973  command->d.atscfg.ndicts = ndicts;
1974  command->parsetree = (Node *) copyObject(stmt);
1975 
1978 
1979  MemoryContextSwitchTo(oldcxt);
1980 }
@ SCT_AlterTSConfig
struct CollectedCommand::@112::@118 atscfg

References CollectedCommand::atscfg, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, currentEventTriggerState, EventTriggerQueryState::cxt, CollectedCommand::d, CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), ObjectAddressSet, palloc(), palloc0(), CollectedCommand::parsetree, SCT_AlterTSConfig, stmt, and CollectedCommand::type.

Referenced by DropConfigurationMapping(), and MakeConfigurationMapping().

◆ EventTriggerCollectCreateOpClass()

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

Definition at line 1919 of file event_trigger.c.

1921 {
1922  MemoryContext oldcxt;
1923  CollectedCommand *command;
1924 
1925  /* ignore if event trigger context not set, or collection disabled */
1926  if (!currentEventTriggerState ||
1928  return;
1929 
1931 
1932  command = palloc0(sizeof(CollectedCommand));
1933  command->type = SCT_CreateOpClass;
1934  command->in_extension = creating_extension;
1935  ObjectAddressSet(command->d.createopc.address,
1936  OperatorClassRelationId, opcoid);
1937  command->d.createopc.operators = operators;
1938  command->d.createopc.procedures = procedures;
1939  command->parsetree = (Node *) copyObject(stmt);
1940 
1943 
1944  MemoryContextSwitchTo(oldcxt);
1945 }
@ SCT_CreateOpClass
struct CollectedCommand::@112::@117 createopc

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

Referenced by DefineOpClass().

◆ EventTriggerCollectGrant()

void EventTriggerCollectGrant ( InternalGrant istmt)

Definition at line 1842 of file event_trigger.c.

1843 {
1844  MemoryContext oldcxt;
1845  CollectedCommand *command;
1846  InternalGrant *icopy;
1847  ListCell *cell;
1848 
1849  /* ignore if event trigger context not set, or collection disabled */
1850  if (!currentEventTriggerState ||
1852  return;
1853 
1855 
1856  /*
1857  * This is tedious, but necessary.
1858  */
1859  icopy = palloc(sizeof(InternalGrant));
1860  memcpy(icopy, istmt, sizeof(InternalGrant));
1861  icopy->objects = list_copy(istmt->objects);
1862  icopy->grantees = list_copy(istmt->grantees);
1863  icopy->col_privs = NIL;
1864  foreach(cell, istmt->col_privs)
1865  icopy->col_privs = lappend(icopy->col_privs, copyObject(lfirst(cell)));
1866 
1867  /* Now collect it, using the copied InternalGrant */
1868  command = palloc(sizeof(CollectedCommand));
1869  command->type = SCT_Grant;
1870  command->in_extension = creating_extension;
1871  command->d.grant.istmt = icopy;
1872  command->parsetree = NULL;
1873 
1876 
1877  MemoryContextSwitchTo(oldcxt);
1878 }
@ SCT_Grant
List * list_copy(const List *oldlist)
Definition: list.c:1573
struct CollectedCommand::@112::@115 grant

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

Referenced by ExecGrantStmt_oids().

◆ EventTriggerCollectSimpleCommand()

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

Definition at line 1679 of file event_trigger.c.

1682 {
1683  MemoryContext oldcxt;
1684  CollectedCommand *command;
1685 
1686  /* ignore if event trigger context not set, or collection disabled */
1687  if (!currentEventTriggerState ||
1689  return;
1690 
1692 
1693  command = palloc(sizeof(CollectedCommand));
1694 
1695  command->type = SCT_Simple;
1696  command->in_extension = creating_extension;
1697 
1698  command->d.simple.address = address;
1699  command->d.simple.secondaryObject = secondaryObject;
1700  command->parsetree = copyObject(parsetree);
1701 
1703  command);
1704 
1705  MemoryContextSwitchTo(oldcxt);
1706 }
@ SCT_Simple
struct CollectedCommand::@112::@113 simple

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

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

◆ EventTriggerDDLCommandEnd()

void EventTriggerDDLCommandEnd ( Node parsetree)

Definition at line 766 of file event_trigger.c.

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

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerDDLCommandStart()

void EventTriggerDDLCommandStart ( Node parsetree)

Definition at line 715 of file event_trigger.c.

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

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerEndCompleteQuery()

void EventTriggerEndCompleteQuery ( void  )

Definition at line 1319 of file event_trigger.c.

1320 {
1321  EventTriggerQueryState *prevstate;
1322 
1323  prevstate = currentEventTriggerState->previous;
1324 
1325  /* this avoids the need for retail pfree of SQLDropList items: */
1327 
1328  currentEventTriggerState = prevstate;
1329 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:403
struct EventTriggerQueryState * previous
Definition: event_trigger.c:75

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

Referenced by ProcessUtilitySlow().

◆ EventTriggerInhibitCommandCollection()

void EventTriggerInhibitCommandCollection ( void  )

Definition at line 1645 of file event_trigger.c.

1646 {
1648  return;
1649 
1651 }

References EventTriggerQueryState::commandCollectionInhibited, and currentEventTriggerState.

Referenced by ProcessUtilitySlow().

◆ EventTriggerOnLogin()

void EventTriggerOnLogin ( void  )

Definition at line 887 of file event_trigger.c.

888 {
889  List *runlist;
890  EventTriggerData trigdata;
891 
892  /*
893  * See EventTriggerDDLCommandStart for a discussion about why event
894  * triggers are disabled in single user mode or via a GUC. We also need a
895  * database connection (some background workers doesn't have it).
896  */
899  return;
900 
902  runlist = EventTriggerCommonSetup(NULL,
903  EVT_Login, "login",
904  &trigdata, false);
905 
906  if (runlist != NIL)
907  {
908  /*
909  * Event trigger execution may require an active snapshot.
910  */
912 
913  /* Run the triggers. */
914  EventTriggerInvoke(runlist, &trigdata);
915 
916  /* Cleanup. */
917  list_free(runlist);
918 
920  }
921 
922  /*
923  * There is no active login event trigger, but our
924  * pg_database.dathasloginevt was set. Try to unset this flag. We use the
925  * lock to prevent concurrent SetDatatabaseHasLoginEventTriggers(), but we
926  * don't want to hang the connection waiting on the lock. Thus, we are
927  * just trying to acquire the lock conditionally.
928  */
929  else if (ConditionalLockSharedObject(DatabaseRelationId, MyDatabaseId,
931  {
932  /*
933  * The lock is held. Now we need to recheck that login event triggers
934  * list is still empty. Once the list is empty, we know that even if
935  * there is a backend, which concurrently inserts/enables login
936  * trigger, it will update pg_database.dathasloginevt *afterwards*.
937  */
938  runlist = EventTriggerCommonSetup(NULL,
939  EVT_Login, "login",
940  &trigdata, true);
941 
942  if (runlist == NIL)
943  {
944  Relation pg_db = table_open(DatabaseRelationId, RowExclusiveLock);
945  HeapTuple tuple;
946  Form_pg_database db;
947  ScanKeyData key[1];
948  SysScanDesc scan;
949 
950  /*
951  * Get the pg_database tuple to scribble on. Note that this does
952  * not directly rely on the syscache to avoid issues with
953  * flattened toast values for the in-place update.
954  */
955  ScanKeyInit(&key[0],
956  Anum_pg_database_oid,
957  BTEqualStrategyNumber, F_OIDEQ,
959 
960  scan = systable_beginscan(pg_db, DatabaseOidIndexId, true,
961  NULL, 1, key);
962  tuple = systable_getnext(scan);
963  tuple = heap_copytuple(tuple);
964  systable_endscan(scan);
965 
966  if (!HeapTupleIsValid(tuple))
967  elog(ERROR, "could not find tuple for database %u", MyDatabaseId);
968 
969  db = (Form_pg_database) GETSTRUCT(tuple);
970  if (db->dathasloginevt)
971  {
972  db->dathasloginevt = false;
973 
974  /*
975  * Do an "in place" update of the pg_database tuple. Doing
976  * this instead of regular updates serves two purposes. First,
977  * that avoids possible waiting on the row-level lock. Second,
978  * that avoids dealing with TOAST.
979  *
980  * It's known that changes made by heap_inplace_update() may
981  * be lost due to concurrent normal updates. However, we are
982  * OK with that. The subsequent connections will still have a
983  * chance to set "dathasloginevt" to false.
984  */
985  heap_inplace_update(pg_db, tuple);
986  }
988  heap_freetuple(tuple);
989  }
990  else
991  {
992  list_free(runlist);
993  }
994  }
996 }
@ EVT_Login
Definition: evtcache.h:26
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:599
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:506
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:387
bool MyDatabaseHasLoginEventTriggers
Definition: globals.c:94
Oid MyDatabaseId
Definition: globals.c:90
void heap_inplace_update(Relation relation, HeapTuple tuple)
Definition: heapam.c:5893
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:777
bool ConditionalLockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1070
#define AccessExclusiveLock
Definition: lockdefs.h:43
FormData_pg_database * Form_pg_database
Definition: pg_database.h:96
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:223
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:655
void PopActiveSnapshot(void)
Definition: snapmgr.c:750
#define BTEqualStrategyNumber
Definition: stratnum.h:31
void StartTransactionCommand(void)
Definition: xact.c:2953
void CommitTransactionCommand(void)
Definition: xact.c:3050

References AccessExclusiveLock, BTEqualStrategyNumber, CommitTransactionCommand(), ConditionalLockSharedObject(), elog(), ERROR, event_triggers, EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_Login, GETSTRUCT, GetTransactionSnapshot(), heap_copytuple(), heap_freetuple(), heap_inplace_update(), HeapTupleIsValid, IsUnderPostmaster, sort-test::key, list_free(), MyDatabaseHasLoginEventTriggers, MyDatabaseId, NIL, ObjectIdGetDatum(), OidIsValid, PopActiveSnapshot(), PushActiveSnapshot(), RowExclusiveLock, ScanKeyInit(), StartTransactionCommand(), systable_beginscan(), systable_endscan(), systable_getnext(), table_close(), and table_open().

Referenced by PostgresMain().

◆ EventTriggerSQLDrop()

void EventTriggerSQLDrop ( Node parsetree)

Definition at line 814 of file event_trigger.c.

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

References CommandCounterIncrement(), currentEventTriggerState, event_triggers, EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_SQLDrop, 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 1369 of file event_trigger.c.

1370 {
1371  SQLDropObject *obj;
1372  MemoryContext oldcxt;
1373 
1375  return;
1376 
1378 
1379  /* don't report temp schemas except my own */
1380  if (object->classId == NamespaceRelationId &&
1381  (isAnyTempNamespace(object->objectId) &&
1382  !isTempNamespace(object->objectId)))
1383  return;
1384 
1386 
1387  obj = palloc0(sizeof(SQLDropObject));
1388  obj->address = *object;
1389  obj->original = original;
1390  obj->normal = normal;
1391 
1392  /*
1393  * Obtain schema names from the object's catalog tuple, if one exists;
1394  * this lets us skip objects in temp schemas. We trust that
1395  * ObjectProperty contains all object classes that can be
1396  * schema-qualified.
1397  */
1398  if (is_objectclass_supported(object->classId))
1399  {
1400  Relation catalog;
1401  HeapTuple tuple;
1402 
1403  catalog = table_open(obj->address.classId, AccessShareLock);
1404  tuple = get_catalog_object_by_oid(catalog,
1405  get_object_attnum_oid(object->classId),
1406  obj->address.objectId);
1407 
1408  if (tuple)
1409  {
1411  Datum datum;
1412  bool isnull;
1413 
1415  if (attnum != InvalidAttrNumber)
1416  {
1417  datum = heap_getattr(tuple, attnum,
1418  RelationGetDescr(catalog), &isnull);
1419  if (!isnull)
1420  {
1421  Oid namespaceId;
1422 
1423  namespaceId = DatumGetObjectId(datum);
1424  /* temp objects are only reported if they are my own */
1425  if (isTempNamespace(namespaceId))
1426  {
1427  obj->schemaname = "pg_temp";
1428  obj->istemp = true;
1429  }
1430  else if (isAnyTempNamespace(namespaceId))
1431  {
1432  pfree(obj);
1433  table_close(catalog, AccessShareLock);
1434  MemoryContextSwitchTo(oldcxt);
1435  return;
1436  }
1437  else
1438  {
1439  obj->schemaname = get_namespace_name(namespaceId);
1440  obj->istemp = false;
1441  }
1442  }
1443  }
1444 
1446  obj->address.objectSubId == 0)
1447  {
1449  if (attnum != InvalidAttrNumber)
1450  {
1451  datum = heap_getattr(tuple, attnum,
1452  RelationGetDescr(catalog), &isnull);
1453  if (!isnull)
1454  obj->objname = pstrdup(NameStr(*DatumGetName(datum)));
1455  }
1456  }
1457  }
1458 
1459  table_close(catalog, AccessShareLock);
1460  }
1461  else
1462  {
1463  if (object->classId == NamespaceRelationId &&
1464  isTempNamespace(object->objectId))
1465  obj->istemp = true;
1466  }
1467 
1468  /* object identity, objname and objargs */
1469  obj->objidentity =
1470  getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs,
1471  false);
1472 
1473  /* object type */
1474  obj->objecttype = getObjectTypeDescription(&obj->address, false);
1475 
1477 
1478  MemoryContextSwitchTo(oldcxt);
1479 }
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
#define NameStr(name)
Definition: c.h:735
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2843
bool EventTriggerSupportsObjectClass(ObjectClass objclass)
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:792
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:3321
char * pstrdup(const char *in)
Definition: mcxt.c:1619
bool isTempNamespace(Oid namespaceId)
Definition: namespace.c:3634
bool isAnyTempNamespace(Oid namespaceId)
Definition: namespace.c:3672
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)
char * getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
bool is_objectclass_supported(Oid class_id)
int16 attnum
Definition: pg_attribute.h:74
static Name DatumGetName(Datum X)
Definition: postgres.h:360
uintptr_t Datum
Definition: postgres.h:64
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:242
#define RelationGetDescr(relation)
Definition: rel.h:530
ObjectAddress address
Definition: event_trigger.c:86
const char * schemaname
Definition: event_trigger.c:87
slist_node next
Definition: event_trigger.c:96
const char * objidentity
Definition: event_trigger.c:89
const char * objecttype
Definition: event_trigger.c:90
List * addrnames
Definition: event_trigger.c:91
const char * objname
Definition: event_trigger.c:88

References AccessShareLock, SQLDropObject::addrargs, SQLDropObject::address, SQLDropObject::addrnames, Assert(), attnum, ObjectAddress::classId, currentEventTriggerState, EventTriggerQueryState::cxt, DatumGetName(), DatumGetObjectId(), EventTriggerSupportsObjectClass(), get_catalog_object_by_oid(), get_namespace_name(), get_object_attnum_name(), get_object_attnum_namespace(), get_object_attnum_oid(), get_object_namensp_unique(), getObjectClass(), getObjectIdentityParts(), getObjectTypeDescription(), heap_getattr(), InvalidAttrNumber, is_objectclass_supported(), isAnyTempNamespace(), SQLDropObject::istemp, isTempNamespace(), MemoryContextSwitchTo(), NameStr, SQLDropObject::next, SQLDropObject::normal, ObjectAddress::objectId, ObjectAddress::objectSubId, SQLDropObject::objecttype, SQLDropObject::objidentity, SQLDropObject::objname, SQLDropObject::original, palloc0(), pfree(), pstrdup(), RelationGetDescr, SQLDropObject::schemaname, slist_push_head(), EventTriggerQueryState::SQLDropList, table_close(), and table_open().

Referenced by deleteObjectsInList(), and DropSubscription().

◆ EventTriggerSupportsObjectClass()

bool EventTriggerSupportsObjectClass ( ObjectClass  objclass)

Definition at line 1207 of file event_trigger.c.

1208 {
1209  switch (objclass)
1210  {
1211  case OCLASS_DATABASE:
1212  case OCLASS_TBLSPACE:
1213  case OCLASS_ROLE:
1215  case OCLASS_PARAMETER_ACL:
1216  /* no support for global objects */
1217  return false;
1218  case OCLASS_EVENT_TRIGGER:
1219  /* no support for event triggers on event triggers */
1220  return false;
1221  case OCLASS_CLASS:
1222  case OCLASS_PROC:
1223  case OCLASS_TYPE:
1224  case OCLASS_CAST:
1225  case OCLASS_COLLATION:
1226  case OCLASS_CONSTRAINT:
1227  case OCLASS_CONVERSION:
1228  case OCLASS_DEFAULT:
1229  case OCLASS_LANGUAGE:
1230  case OCLASS_LARGEOBJECT:
1231  case OCLASS_OPERATOR:
1232  case OCLASS_OPCLASS:
1233  case OCLASS_OPFAMILY:
1234  case OCLASS_AM:
1235  case OCLASS_AMOP:
1236  case OCLASS_AMPROC:
1237  case OCLASS_REWRITE:
1238  case OCLASS_TRIGGER:
1239  case OCLASS_SCHEMA:
1240  case OCLASS_STATISTIC_EXT:
1241  case OCLASS_TSPARSER:
1242  case OCLASS_TSDICT:
1243  case OCLASS_TSTEMPLATE:
1244  case OCLASS_TSCONFIG:
1245  case OCLASS_FDW:
1246  case OCLASS_FOREIGN_SERVER:
1247  case OCLASS_USER_MAPPING:
1248  case OCLASS_DEFACL:
1249  case OCLASS_EXTENSION:
1250  case OCLASS_POLICY:
1251  case OCLASS_PUBLICATION:
1254  case OCLASS_SUBSCRIPTION:
1255  case OCLASS_TRANSFORM:
1256  return true;
1257 
1258  /*
1259  * There's intentionally no default: case here; we want the
1260  * compiler to warn if a new OCLASS hasn't been handled above.
1261  */
1262  }
1263 
1264  /* Shouldn't get here, but if we do, say "no support" */
1265  return false;
1266 }
@ OCLASS_OPERATOR
Definition: dependency.h:100
@ OCLASS_PARAMETER_ACL
Definition: dependency.h:124
@ OCLASS_LARGEOBJECT
Definition: dependency.h:99
@ OCLASS_FDW
Definition: dependency.h:118
@ OCLASS_OPFAMILY
Definition: dependency.h:102
@ OCLASS_DEFACL
Definition: dependency.h:121
@ OCLASS_TSPARSER
Definition: dependency.h:110
@ OCLASS_TRIGGER
Definition: dependency.h:107
@ OCLASS_DEFAULT
Definition: dependency.h:97
@ OCLASS_TSTEMPLATE
Definition: dependency.h:112
@ OCLASS_AMPROC
Definition: dependency.h:105
@ OCLASS_TBLSPACE
Definition: dependency.h:117
@ OCLASS_TSCONFIG
Definition: dependency.h:113
@ OCLASS_TYPE
Definition: dependency.h:92
@ OCLASS_LANGUAGE
Definition: dependency.h:98
@ OCLASS_CAST
Definition: dependency.h:93
@ OCLASS_SUBSCRIPTION
Definition: dependency.h:129
@ OCLASS_PUBLICATION_NAMESPACE
Definition: dependency.h:127
@ OCLASS_EXTENSION
Definition: dependency.h:122
@ OCLASS_COLLATION
Definition: dependency.h:94
@ OCLASS_FOREIGN_SERVER
Definition: dependency.h:119
@ OCLASS_REWRITE
Definition: dependency.h:106
@ OCLASS_STATISTIC_EXT
Definition: dependency.h:109
@ OCLASS_PROC
Definition: dependency.h:91
@ OCLASS_OPCLASS
Definition: dependency.h:101
@ OCLASS_CONVERSION
Definition: dependency.h:96
@ OCLASS_DATABASE
Definition: dependency.h:116
@ OCLASS_ROLE_MEMBERSHIP
Definition: dependency.h:115
@ OCLASS_SCHEMA
Definition: dependency.h:108
@ OCLASS_EVENT_TRIGGER
Definition: dependency.h:123
@ OCLASS_CLASS
Definition: dependency.h:90
@ OCLASS_TRANSFORM
Definition: dependency.h:130
@ OCLASS_ROLE
Definition: dependency.h:114
@ OCLASS_CONSTRAINT
Definition: dependency.h:95
@ OCLASS_POLICY
Definition: dependency.h:125
@ OCLASS_USER_MAPPING
Definition: dependency.h:120
@ OCLASS_PUBLICATION_REL
Definition: dependency.h:128
@ OCLASS_AM
Definition: dependency.h:103
@ OCLASS_TSDICT
Definition: dependency.h:111
@ OCLASS_PUBLICATION
Definition: dependency.h:126
@ OCLASS_AMOP
Definition: dependency.h:104

References OCLASS_AM, OCLASS_AMOP, OCLASS_AMPROC, OCLASS_CAST, OCLASS_CLASS, OCLASS_COLLATION, OCLASS_CONSTRAINT, OCLASS_CONVERSION, OCLASS_DATABASE, OCLASS_DEFACL, OCLASS_DEFAULT, OCLASS_EVENT_TRIGGER, OCLASS_EXTENSION, OCLASS_FDW, OCLASS_FOREIGN_SERVER, OCLASS_LANGUAGE, OCLASS_LARGEOBJECT, OCLASS_OPCLASS, OCLASS_OPERATOR, OCLASS_OPFAMILY, OCLASS_PARAMETER_ACL, OCLASS_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_NAMESPACE, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, OCLASS_ROLE_MEMBERSHIP, OCLASS_SCHEMA, OCLASS_STATISTIC_EXT, OCLASS_SUBSCRIPTION, OCLASS_TBLSPACE, OCLASS_TRANSFORM, OCLASS_TRIGGER, OCLASS_TSCONFIG, OCLASS_TSDICT, OCLASS_TSPARSER, OCLASS_TSTEMPLATE, OCLASS_TYPE, and OCLASS_USER_MAPPING.

Referenced by deleteObjectsInList(), and EventTriggerSQLDropAddObject().

◆ EventTriggerSupportsObjectType()

bool EventTriggerSupportsObjectType ( ObjectType  obtype)

Definition at line 1131 of file event_trigger.c.

1132 {
1133  switch (obtype)
1134  {
1135  case OBJECT_DATABASE:
1136  case OBJECT_TABLESPACE:
1137  case OBJECT_ROLE:
1138  case OBJECT_PARAMETER_ACL:
1139  /* no support for global objects */
1140  return false;
1141  case OBJECT_EVENT_TRIGGER:
1142  /* no support for event triggers on event triggers */
1143  return false;
1144  case OBJECT_ACCESS_METHOD:
1145  case OBJECT_AGGREGATE:
1146  case OBJECT_AMOP:
1147  case OBJECT_AMPROC:
1148  case OBJECT_ATTRIBUTE:
1149  case OBJECT_CAST:
1150  case OBJECT_COLUMN:
1151  case OBJECT_COLLATION:
1152  case OBJECT_CONVERSION:
1153  case OBJECT_DEFACL:
1154  case OBJECT_DEFAULT:
1155  case OBJECT_DOMAIN:
1156  case OBJECT_DOMCONSTRAINT:
1157  case OBJECT_EXTENSION:
1158  case OBJECT_FDW:
1159  case OBJECT_FOREIGN_SERVER:
1160  case OBJECT_FOREIGN_TABLE:
1161  case OBJECT_FUNCTION:
1162  case OBJECT_INDEX:
1163  case OBJECT_LANGUAGE:
1164  case OBJECT_LARGEOBJECT:
1165  case OBJECT_MATVIEW:
1166  case OBJECT_OPCLASS:
1167  case OBJECT_OPERATOR:
1168  case OBJECT_OPFAMILY:
1169  case OBJECT_POLICY:
1170  case OBJECT_PROCEDURE:
1171  case OBJECT_PUBLICATION:
1174  case OBJECT_ROUTINE:
1175  case OBJECT_RULE:
1176  case OBJECT_SCHEMA:
1177  case OBJECT_SEQUENCE:
1178  case OBJECT_SUBSCRIPTION:
1179  case OBJECT_STATISTIC_EXT:
1180  case OBJECT_TABCONSTRAINT:
1181  case OBJECT_TABLE:
1182  case OBJECT_TRANSFORM:
1183  case OBJECT_TRIGGER:
1185  case OBJECT_TSDICTIONARY:
1186  case OBJECT_TSPARSER:
1187  case OBJECT_TSTEMPLATE:
1188  case OBJECT_TYPE:
1189  case OBJECT_USER_MAPPING:
1190  case OBJECT_VIEW:
1191  return true;
1192 
1193  /*
1194  * There's intentionally no default: case here; we want the
1195  * compiler to warn if a new ObjectType hasn't been handled above.
1196  */
1197  }
1198 
1199  /* Shouldn't get here, but if we do, say "no support" */
1200  return false;
1201 }
@ OBJECT_FDW
Definition: parsenodes.h:2112
@ OBJECT_TSPARSER
Definition: parsenodes.h:2143
@ OBJECT_COLLATION
Definition: parsenodes.h:2103
@ OBJECT_USER_MAPPING
Definition: parsenodes.h:2146
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:2096
@ OBJECT_OPCLASS
Definition: parsenodes.h:2120
@ OBJECT_DEFACL
Definition: parsenodes.h:2107
@ OBJECT_AGGREGATE
Definition: parsenodes.h:2097
@ OBJECT_MATVIEW
Definition: parsenodes.h:2119
@ OBJECT_SCHEMA
Definition: parsenodes.h:2132
@ OBJECT_POLICY
Definition: parsenodes.h:2124
@ OBJECT_OPERATOR
Definition: parsenodes.h:2121
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:2114
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2141
@ OBJECT_OPFAMILY
Definition: parsenodes.h:2122
@ OBJECT_DOMAIN
Definition: parsenodes.h:2108
@ OBJECT_COLUMN
Definition: parsenodes.h:2102
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2138
@ OBJECT_ROLE
Definition: parsenodes.h:2129
@ OBJECT_ROUTINE
Definition: parsenodes.h:2130
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:2118
@ OBJECT_PUBLICATION_NAMESPACE
Definition: parsenodes.h:2127
@ OBJECT_PROCEDURE
Definition: parsenodes.h:2125
@ OBJECT_EXTENSION
Definition: parsenodes.h:2111
@ OBJECT_INDEX
Definition: parsenodes.h:2116
@ OBJECT_DEFAULT
Definition: parsenodes.h:2106
@ OBJECT_DATABASE
Definition: parsenodes.h:2105
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2133
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2144
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2117
@ OBJECT_AMOP
Definition: parsenodes.h:2098
@ OBJECT_PUBLICATION_REL
Definition: parsenodes.h:2128
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:2113
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2142
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:2100
@ OBJECT_PUBLICATION
Definition: parsenodes.h:2126
@ OBJECT_RULE
Definition: parsenodes.h:2131
@ OBJECT_CONVERSION
Definition: parsenodes.h:2104
@ OBJECT_AMPROC
Definition: parsenodes.h:2099
@ OBJECT_TABLE
Definition: parsenodes.h:2137
@ OBJECT_VIEW
Definition: parsenodes.h:2147
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:2123
@ OBJECT_TYPE
Definition: parsenodes.h:2145
@ OBJECT_FUNCTION
Definition: parsenodes.h:2115
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2136
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:2109
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2134
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2135
@ OBJECT_CAST
Definition: parsenodes.h:2101
@ OBJECT_TRIGGER
Definition: parsenodes.h:2140
@ OBJECT_TRANSFORM
Definition: parsenodes.h:2139

References 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_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 ExecGrantStmt_oids(), and standard_ProcessUtility().

◆ EventTriggerTableRewrite()

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

Definition at line 1003 of file event_trigger.c.

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

References CommandCounterIncrement(), currentEventTriggerState, event_triggers, EventTriggerCommonSetup(), EventTriggerInvoke(), EVT_TableRewrite, 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 1657 of file event_trigger.c.

1658 {
1660  return;
1661 
1663 }

References EventTriggerQueryState::commandCollectionInhibited, and currentEventTriggerState.

Referenced by ProcessUtilitySlow().

◆ get_event_trigger_oid()

Oid get_event_trigger_oid ( const char *  trigname,
bool  missing_ok 
)

Definition at line 569 of file event_trigger.c.

570 {
571  Oid oid;
572 
573  oid = GetSysCacheOid1(EVENTTRIGGERNAME, Anum_pg_event_trigger_oid,
574  CStringGetDatum(trigname));
575  if (!OidIsValid(oid) && !missing_ok)
576  ereport(ERROR,
577  (errcode(ERRCODE_UNDEFINED_OBJECT),
578  errmsg("event trigger \"%s\" does not exist", trigname)));
579  return oid;
580 }
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:104

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

Referenced by get_object_address_unqualified().

◆ trackDroppedObjectsNeeded()

bool trackDroppedObjectsNeeded ( void  )

Definition at line 1337 of file event_trigger.c.

1338 {
1339  /*
1340  * true if any sql_drop, table_rewrite, ddl_command_end event trigger
1341  * exists
1342  */
1343  return (EventCacheLookup(EVT_SQLDrop) != NIL) ||
1346 }
List * EventCacheLookup(EventTriggerEvent event)
Definition: evtcache.c:64

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

Referenced by deleteObjectsInList(), and EventTriggerBeginCompleteQuery().

Variable Documentation

◆ event_triggers