PostgreSQL Source Code  git master
event_trigger.c File Reference
#include "postgres.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_event_trigger.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_trigger.h"
#include "catalog/pg_ts_config.h"
#include "catalog/pg_type.h"
#include "commands/dbcommands.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 "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/lsyscache.h"
#include "utils/memutils.h"
#include "utils/rel.h"
#include "utils/syscache.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 *tags)
 
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 const char * stringify_grant_objtype (ObjectType objtype)
 
static const char * stringify_adefprivs_objtype (ObjectType objtype)
 
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 ListEventTriggerCommonSetup (Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata)
 
void EventTriggerDDLCommandStart (Node *parsetree)
 
void EventTriggerDDLCommandEnd (Node *parsetree)
 
void EventTriggerSQLDrop (Node *parsetree)
 
void EventTriggerTableRewrite (Node *parsetree, Oid tableOid, int reason)
 
bool EventTriggerSupportsObjectType (ObjectType obtype)
 
bool EventTriggerSupportsObjectClass (ObjectClass objclass)
 
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, 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)
 
Datum pg_event_trigger_ddl_commands (PG_FUNCTION_ARGS)
 

Variables

static EventTriggerQueryStatecurrentEventTriggerState = NULL
 

Typedef Documentation

◆ EventTriggerQueryState

◆ SQLDropObject

typedef struct SQLDropObject SQLDropObject

Function Documentation

◆ AlterEventTrigger()

Oid AlterEventTrigger ( AlterEventTrigStmt stmt)

Definition at line 362 of file event_trigger.c.

References aclcheck_error(), ACLCHECK_NOT_OWNER, CatalogTupleUpdate(), CStringGetDatum, ereport, errcode(), errmsg(), ERROR, EVENTTRIGGERNAME, GETSTRUCT, GetUserId(), heap_freetuple(), HeapTupleIsValid, InvokeObjectPostAlterHook, OBJECT_EVENT_TRIGGER, pg_event_trigger_ownercheck(), RowExclusiveLock, SearchSysCacheCopy1, HeapTupleData::t_self, table_close(), table_open(), AlterEventTrigStmt::tgenabled, and AlterEventTrigStmt::trigname.

Referenced by standard_ProcessUtility().

363 {
364  Relation tgrel;
365  HeapTuple tup;
366  Oid trigoid;
367  Form_pg_event_trigger evtForm;
368  char tgenabled = stmt->tgenabled;
369 
370  tgrel = table_open(EventTriggerRelationId, RowExclusiveLock);
371 
373  CStringGetDatum(stmt->trigname));
374  if (!HeapTupleIsValid(tup))
375  ereport(ERROR,
376  (errcode(ERRCODE_UNDEFINED_OBJECT),
377  errmsg("event trigger \"%s\" does not exist",
378  stmt->trigname)));
379 
380  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
381  trigoid = evtForm->oid;
382 
383  if (!pg_event_trigger_ownercheck(trigoid, GetUserId()))
385  stmt->trigname);
386 
387  /* tuple is a copy, so we can modify it below */
388  evtForm->evtenabled = tgenabled;
389 
390  CatalogTupleUpdate(tgrel, &tup->t_self, tup);
391 
392  InvokeObjectPostAlterHook(EventTriggerRelationId,
393  trigoid, 0);
394 
395  /* clean up */
396  heap_freetuple(tup);
398 
399  return trigoid;
400 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
Oid GetUserId(void)
Definition: miscinit.c:495
int errcode(int sqlerrcode)
Definition: elog.c:698
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3308
#define ERROR
Definition: elog.h:46
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5211
ItemPointerData t_self
Definition: htup.h:65
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:622
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:175
#define ereport(elevel,...)
Definition: elog.h:157
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:177
int errmsg(const char *fmt,...)
Definition: elog.c:909
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ AlterEventTriggerOwner()

ObjectAddress AlterEventTriggerOwner ( const char *  name,
Oid  newOwnerId 
)

Definition at line 406 of file event_trigger.c.

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

Referenced by ExecAlterOwnerStmt().

407 {
408  Oid evtOid;
409  HeapTuple tup;
410  Form_pg_event_trigger evtForm;
411  Relation rel;
412  ObjectAddress address;
413 
414  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
415 
417 
418  if (!HeapTupleIsValid(tup))
419  ereport(ERROR,
420  (errcode(ERRCODE_UNDEFINED_OBJECT),
421  errmsg("event trigger \"%s\" does not exist", name)));
422 
423  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
424  evtOid = evtForm->oid;
425 
426  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
427 
428  ObjectAddressSet(address, EventTriggerRelationId, evtOid);
429 
430  heap_freetuple(tup);
431 
433 
434  return address;
435 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
int errcode(int sqlerrcode)
Definition: elog.c:698
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
static void AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
#define ERROR
Definition: elog.h:46
#define RowExclusiveLock
Definition: lockdefs.h:38
#define CStringGetDatum(X)
Definition: postgres.h:622
#define ereport(elevel,...)
Definition: elog.h:157
FormData_pg_event_trigger * Form_pg_event_trigger
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
const char * name
Definition: encode.c:561
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:177
int errmsg(const char *fmt,...)
Definition: elog.c:909
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ AlterEventTriggerOwner_internal()

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

Definition at line 466 of file event_trigger.c.

References aclcheck_error(), ACLCHECK_NOT_OWNER, CatalogTupleUpdate(), changeDependencyOnOwner(), ereport, errcode(), errhint(), errmsg(), ERROR, GETSTRUCT, GetUserId(), InvokeObjectPostAlterHook, NameStr, OBJECT_EVENT_TRIGGER, pg_event_trigger_ownercheck(), superuser_arg(), and HeapTupleData::t_self.

Referenced by AlterEventTriggerOwner(), and AlterEventTriggerOwner_oid().

467 {
469 
470  form = (Form_pg_event_trigger) GETSTRUCT(tup);
471 
472  if (form->evtowner == newOwnerId)
473  return;
474 
475  if (!pg_event_trigger_ownercheck(form->oid, GetUserId()))
477  NameStr(form->evtname));
478 
479  /* New owner must be a superuser */
480  if (!superuser_arg(newOwnerId))
481  ereport(ERROR,
482  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
483  errmsg("permission denied to change owner of event trigger \"%s\"",
484  NameStr(form->evtname)),
485  errhint("The owner of an event trigger must be a superuser.")));
486 
487  form->evtowner = newOwnerId;
488  CatalogTupleUpdate(rel, &tup->t_self, tup);
489 
490  /* Update owner dependency reference */
491  changeDependencyOnOwner(EventTriggerRelationId,
492  form->oid,
493  newOwnerId);
494 
495  InvokeObjectPostAlterHook(EventTriggerRelationId,
496  form->oid, 0);
497 }
int errhint(const char *fmt,...)
Definition: elog.c:1156
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
Oid GetUserId(void)
Definition: miscinit.c:495
int errcode(int sqlerrcode)
Definition: elog.c:698
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
Definition: pg_shdepend.c:311
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3308
#define ERROR
Definition: elog.h:46
bool pg_event_trigger_ownercheck(Oid et_oid, Oid roleid)
Definition: aclchk.c:5211
ItemPointerData t_self
Definition: htup.h:65
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:175
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
#define ereport(elevel,...)
Definition: elog.h:157
FormData_pg_event_trigger * Form_pg_event_trigger
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:301
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define NameStr(name)
Definition: c.h:681

◆ AlterEventTriggerOwner_oid()

void AlterEventTriggerOwner_oid ( Oid  trigOid,
Oid  newOwnerId 
)

Definition at line 441 of file event_trigger.c.

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

Referenced by shdepReassignOwned().

442 {
443  HeapTuple tup;
444  Relation rel;
445 
446  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
447 
449 
450  if (!HeapTupleIsValid(tup))
451  ereport(ERROR,
452  (errcode(ERRCODE_UNDEFINED_OBJECT),
453  errmsg("event trigger with OID %u does not exist", trigOid)));
454 
455  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
456 
457  heap_freetuple(tup);
458 
460 }
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
int errcode(int sqlerrcode)
Definition: elog.c:698
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
static void AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
#define RowExclusiveLock
Definition: lockdefs.h:38
#define ereport(elevel,...)
Definition: elog.h:157
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:177
int errmsg(const char *fmt,...)
Definition: elog.c:909
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39

◆ CreateEventTrigger()

Oid CreateEventTrigger ( CreateEventTrigStmt stmt)

Definition at line 108 of file event_trigger.c.

References DefElem::arg, CStringGetDatum, DefElem::defname, ereport, errcode(), ERRCODE_DUPLICATE_OBJECT, errhint(), errmsg(), ERROR, error_duplicate_filter_variable(), CreateEventTrigStmt::eventname, EVENTTRIGGERNAME, CreateEventTrigStmt::funcname, get_func_rettype(), GetUserId(), HeapTupleIsValid, insert_event_trigger_tuple(), lfirst, LookupFuncName(), NameListToString(), SearchSysCache1(), superuser(), CreateEventTrigStmt::trigname, validate_ddl_tags(), validate_table_rewrite_tags(), and CreateEventTrigStmt::whenclause.

Referenced by standard_ProcessUtility().

109 {
110  HeapTuple tuple;
111  Oid funcoid;
112  Oid funcrettype;
113  Oid evtowner = GetUserId();
114  ListCell *lc;
115  List *tags = NULL;
116 
117  /*
118  * It would be nice to allow database owners or even regular users to do
119  * this, but there are obvious privilege escalation risks which would have
120  * to somehow be plugged first.
121  */
122  if (!superuser())
123  ereport(ERROR,
124  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
125  errmsg("permission denied to create event trigger \"%s\"",
126  stmt->trigname),
127  errhint("Must be superuser to create an event trigger.")));
128 
129  /* Validate event name. */
130  if (strcmp(stmt->eventname, "ddl_command_start") != 0 &&
131  strcmp(stmt->eventname, "ddl_command_end") != 0 &&
132  strcmp(stmt->eventname, "sql_drop") != 0 &&
133  strcmp(stmt->eventname, "table_rewrite") != 0)
134  ereport(ERROR,
135  (errcode(ERRCODE_SYNTAX_ERROR),
136  errmsg("unrecognized event name \"%s\"",
137  stmt->eventname)));
138 
139  /* Validate filter conditions. */
140  foreach(lc, stmt->whenclause)
141  {
142  DefElem *def = (DefElem *) lfirst(lc);
143 
144  if (strcmp(def->defname, "tag") == 0)
145  {
146  if (tags != NULL)
148  tags = (List *) def->arg;
149  }
150  else
151  ereport(ERROR,
152  (errcode(ERRCODE_SYNTAX_ERROR),
153  errmsg("unrecognized filter variable \"%s\"", def->defname)));
154  }
155 
156  /* Validate tag list, if any. */
157  if ((strcmp(stmt->eventname, "ddl_command_start") == 0 ||
158  strcmp(stmt->eventname, "ddl_command_end") == 0 ||
159  strcmp(stmt->eventname, "sql_drop") == 0)
160  && tags != NULL)
161  validate_ddl_tags("tag", tags);
162  else if (strcmp(stmt->eventname, "table_rewrite") == 0
163  && tags != NULL)
164  validate_table_rewrite_tags("tag", tags);
165 
166  /*
167  * Give user a nice error message if an event trigger of the same name
168  * already exists.
169  */
171  if (HeapTupleIsValid(tuple))
172  ereport(ERROR,
174  errmsg("event trigger \"%s\" already exists",
175  stmt->trigname)));
176 
177  /* Find and validate the trigger function. */
178  funcoid = LookupFuncName(stmt->funcname, 0, NULL, false);
179  funcrettype = get_func_rettype(funcoid);
180  if (funcrettype != EVENT_TRIGGEROID)
181  ereport(ERROR,
182  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
183  errmsg("function %s must return type %s",
184  NameListToString(stmt->funcname), "event_trigger")));
185 
186  /* Insert catalog entries. */
187  return insert_event_trigger_tuple(stmt->trigname, stmt->eventname,
188  evtowner, funcoid, tags);
189 }
static void validate_ddl_tags(const char *filtervar, List *taglist)
int errhint(const char *fmt,...)
Definition: elog.c:1156
Oid GetUserId(void)
Definition: miscinit.c:495
int errcode(int sqlerrcode)
Definition: elog.c:698
bool superuser(void)
Definition: superuser.c:46
unsigned int Oid
Definition: postgres_ext.h:31
Oid get_func_rettype(Oid funcid)
Definition: lsyscache.c:1626
#define ERROR
Definition: elog.h:46
static void validate_table_rewrite_tags(const char *filtervar, List *taglist)
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
Definition: parse_func.c:2145
static void error_duplicate_filter_variable(const char *defname)
#define CStringGetDatum(X)
Definition: postgres.h:622
Node * arg
Definition: parsenodes.h:759
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1150
char * NameListToString(List *names)
Definition: namespace.c:3147
static Oid insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtOwner, Oid funcoid, List *tags)
#define ereport(elevel,...)
Definition: elog.h:157
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define lfirst(lc)
Definition: pg_list.h:169
int errmsg(const char *fmt,...)
Definition: elog.c:909
char * defname
Definition: parsenodes.h:758
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:32
Definition: pg_list.h:50

◆ error_duplicate_filter_variable()

static void error_duplicate_filter_variable ( const char *  defname)
static

Definition at line 244 of file event_trigger.c.

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

Referenced by CreateEventTrigger().

245 {
246  ereport(ERROR,
247  (errcode(ERRCODE_SYNTAX_ERROR),
248  errmsg("filter variable \"%s\" specified more than once",
249  defname)));
250 }
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ EventTriggerAlterTableEnd()

void EventTriggerAlterTableEnd ( void  )

Definition at line 1637 of file event_trigger.c.

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

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

1638 {
1639  CollectedCommand *parent;
1640 
1641  /* ignore if event trigger context not set, or collection disabled */
1642  if (!currentEventTriggerState ||
1644  return;
1645 
1647 
1648  /* If no subcommands, don't collect */
1650  {
1651  MemoryContext oldcxt;
1652 
1654 
1658 
1659  MemoryContextSwitchTo(oldcxt);
1660  }
1661  else
1663 
1665 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
struct CollectedCommand::@109::@111 alterTable
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
void pfree(void *pointer)
Definition: mcxt.c:1169
CollectedCommand * currentCommand
Definition: event_trigger.c:67
struct CollectedCommand * parent
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:336
static int list_length(const List *l)
Definition: pg_list.h:149

◆ EventTriggerAlterTableRelid()

void EventTriggerAlterTableRelid ( Oid  objectId)

Definition at line 1584 of file event_trigger.c.

References CollectedCommand::alterTable, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::currentCommand, and CollectedCommand::d.

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

1585 {
1586  if (!currentEventTriggerState ||
1588  return;
1589 
1590  currentEventTriggerState->currentCommand->d.alterTable.objectId = objectId;
1591 }
struct CollectedCommand::@109::@111 alterTable
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
CollectedCommand * currentCommand
Definition: event_trigger.c:67
union CollectedCommand::@109 d

◆ EventTriggerAlterTableStart()

void EventTriggerAlterTableStart ( Node parsetree)

Definition at line 1550 of file event_trigger.c.

References CollectedCommand::alterTable, EventTriggerQueryState::commandCollectionInhibited, copyObject, creating_extension, EventTriggerQueryState::currentCommand, 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().

1551 {
1552  MemoryContext oldcxt;
1553  CollectedCommand *command;
1554 
1555  /* ignore if event trigger context not set, or collection disabled */
1556  if (!currentEventTriggerState ||
1558  return;
1559 
1561 
1562  command = palloc(sizeof(CollectedCommand));
1563 
1564  command->type = SCT_AlterTable;
1565  command->in_extension = creating_extension;
1566 
1567  command->d.alterTable.classId = RelationRelationId;
1568  command->d.alterTable.objectId = InvalidOid;
1569  command->d.alterTable.subcmds = NIL;
1570  command->parsetree = copyObject(parsetree);
1571 
1574 
1575  MemoryContextSwitchTo(oldcxt);
1576 }
#define NIL
Definition: pg_list.h:65
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
struct CollectedCommand::@109::@111 alterTable
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
CollectedCommand * currentCommand
Definition: event_trigger.c:67
struct CollectedCommand * parent
union CollectedCommand::@109 d
#define InvalidOid
Definition: postgres_ext.h:36
bool creating_extension
Definition: extension.c:71
void * palloc(Size size)
Definition: mcxt.c:1062
#define copyObject(obj)
Definition: nodes.h:654

◆ EventTriggerBeginCompleteQuery()

bool EventTriggerBeginCompleteQuery ( void  )

Definition at line 1077 of file event_trigger.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, EventTriggerQueryState::currentCommand, currentEventTriggerState, EventTriggerQueryState::cxt, EventTriggerQueryState::in_sql_drop, InvalidOid, MemoryContextAlloc(), NIL, EventTriggerQueryState::previous, slist_init(), EventTriggerQueryState::SQLDropList, EventTriggerQueryState::table_rewrite_oid, TopMemoryContext, and trackDroppedObjectsNeeded().

Referenced by ProcessUtilitySlow().

1078 {
1080  MemoryContext cxt;
1081 
1082  /*
1083  * Currently, sql_drop, table_rewrite, ddl_command_end events are the only
1084  * reason to have event trigger state at all; so if there are none, don't
1085  * install one.
1086  */
1088  return false;
1089 
1091  "event trigger state",
1093  state = MemoryContextAlloc(cxt, sizeof(EventTriggerQueryState));
1094  state->cxt = cxt;
1095  slist_init(&(state->SQLDropList));
1096  state->in_sql_drop = false;
1097  state->table_rewrite_oid = InvalidOid;
1098 
1101  state->currentCommand = NULL;
1102  state->commandList = NIL;
1104  currentEventTriggerState = state;
1105 
1106  return true;
1107 }
#define NIL
Definition: pg_list.h:65
#define AllocSetContextCreate
Definition: memutils.h:173
bool trackDroppedObjectsNeeded(void)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
static void slist_init(slist_head *head)
Definition: ilist.h:573
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
CollectedCommand * currentCommand
Definition: event_trigger.c:67
struct EventTriggerQueryState * previous
Definition: event_trigger.c:70
MemoryContext TopMemoryContext
Definition: mcxt.c:48
#define InvalidOid
Definition: postgres_ext.h:36
Definition: regguts.h:317
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863

◆ EventTriggerCollectAlterDefPrivs()

void EventTriggerCollectAlterDefPrivs ( AlterDefaultPrivilegesStmt stmt)

Definition at line 1821 of file event_trigger.c.

References AlterDefaultPrivilegesStmt::action, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, EventTriggerQueryState::cxt, CollectedCommand::d, CollectedCommand::defprivs, CollectedCommand::in_extension, lappend(), MemoryContextSwitchTo(), GrantStmt::objtype, palloc0(), CollectedCommand::parsetree, SCT_AlterDefaultPrivileges, and CollectedCommand::type.

Referenced by ProcessUtilitySlow().

1822 {
1823  MemoryContext oldcxt;
1824  CollectedCommand *command;
1825 
1826  /* ignore if event trigger context not set, or collection disabled */
1827  if (!currentEventTriggerState ||
1829  return;
1830 
1832 
1833  command = palloc0(sizeof(CollectedCommand));
1834  command->type = SCT_AlterDefaultPrivileges;
1835  command->d.defprivs.objtype = stmt->action->objtype;
1836  command->in_extension = creating_extension;
1837  command->parsetree = (Node *) copyObject(stmt);
1838 
1841  MemoryContextSwitchTo(oldcxt);
1842 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:538
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:336
void * palloc0(Size size)
Definition: mcxt.c:1093
bool creating_extension
Definition: extension.c:71
struct CollectedCommand::@109::@116 defprivs
ObjectType objtype
Definition: parsenodes.h:2029
#define copyObject(obj)
Definition: nodes.h:654

◆ EventTriggerCollectAlterOpFam()

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

Definition at line 1719 of file event_trigger.c.

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

Referenced by AlterOpFamilyAdd(), and AlterOpFamilyDrop().

1721 {
1722  MemoryContext oldcxt;
1723  CollectedCommand *command;
1724 
1725  /* ignore if event trigger context not set, or collection disabled */
1726  if (!currentEventTriggerState ||
1728  return;
1729 
1731 
1732  command = palloc(sizeof(CollectedCommand));
1733  command->type = SCT_AlterOpFamily;
1734  command->in_extension = creating_extension;
1735  ObjectAddressSet(command->d.opfam.address,
1736  OperatorFamilyRelationId, opfamoid);
1737  command->d.opfam.operators = operators;
1738  command->d.opfam.procedures = procedures;
1739  command->parsetree = (Node *) copyObject(stmt);
1740 
1743 
1744  MemoryContextSwitchTo(oldcxt);
1745 }
struct CollectedCommand::@109::@113 opfam
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:538
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:336
bool creating_extension
Definition: extension.c:71
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
void * palloc(Size size)
Definition: mcxt.c:1062
#define copyObject(obj)
Definition: nodes.h:654

◆ EventTriggerCollectAlterTableSubcmd()

void EventTriggerCollectAlterTableSubcmd ( Node subcmd,
ObjectAddress  address 
)

Definition at line 1602 of file event_trigger.c.

References CollectedATSubcmd::address, CollectedCommand::alterTable, Assert, EventTriggerQueryState::commandCollectionInhibited, copyObject, EventTriggerQueryState::currentCommand, EventTriggerQueryState::cxt, CollectedCommand::d, IsA, lappend(), MemoryContextSwitchTo(), newsub(), OidIsValid, palloc(), and CollectedATSubcmd::parsetree.

Referenced by ATExecCmd().

1603 {
1604  MemoryContext oldcxt;
1606 
1607  /* ignore if event trigger context not set, or collection disabled */
1608  if (!currentEventTriggerState ||
1610  return;
1611 
1612  Assert(IsA(subcmd, AlterTableCmd));
1615 
1617 
1618  newsub = palloc(sizeof(CollectedATSubcmd));
1619  newsub->address = address;
1620  newsub->parsetree = copyObject(subcmd);
1621 
1624 
1625  MemoryContextSwitchTo(oldcxt);
1626 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:589
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
struct CollectedCommand::@109::@111 alterTable
#define OidIsValid(objectId)
Definition: c.h:710
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
CollectedCommand * currentCommand
Definition: event_trigger.c:67
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:336
#define Assert(condition)
Definition: c.h:804
void * palloc(Size size)
Definition: mcxt.c:1062
#define copyObject(obj)
Definition: nodes.h:654
static color newsub(struct colormap *cm, color co)
Definition: regc_color.c:389
ObjectAddress address

◆ EventTriggerCollectAlterTSConfig()

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

Definition at line 1786 of file event_trigger.c.

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

Referenced by DropConfigurationMapping(), and MakeConfigurationMapping().

1788 {
1789  MemoryContext oldcxt;
1790  CollectedCommand *command;
1791 
1792  /* ignore if event trigger context not set, or collection disabled */
1793  if (!currentEventTriggerState ||
1795  return;
1796 
1798 
1799  command = palloc0(sizeof(CollectedCommand));
1800  command->type = SCT_AlterTSConfig;
1801  command->in_extension = creating_extension;
1802  ObjectAddressSet(command->d.atscfg.address,
1803  TSConfigRelationId, cfgId);
1804  command->d.atscfg.dictIds = palloc(sizeof(Oid) * ndicts);
1805  memcpy(command->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts);
1806  command->d.atscfg.ndicts = ndicts;
1807  command->parsetree = (Node *) copyObject(stmt);
1808 
1811 
1812  MemoryContextSwitchTo(oldcxt);
1813 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:538
CollectedCommandType type
unsigned int Oid
Definition: postgres_ext.h:31
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:336
void * palloc0(Size size)
Definition: mcxt.c:1093
bool creating_extension
Definition: extension.c:71
struct CollectedCommand::@109::@115 atscfg
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
void * palloc(Size size)
Definition: mcxt.c:1062
#define copyObject(obj)
Definition: nodes.h:654

◆ EventTriggerCollectCreateOpClass()

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

Definition at line 1752 of file event_trigger.c.

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

Referenced by DefineOpClass().

1754 {
1755  MemoryContext oldcxt;
1756  CollectedCommand *command;
1757 
1758  /* ignore if event trigger context not set, or collection disabled */
1759  if (!currentEventTriggerState ||
1761  return;
1762 
1764 
1765  command = palloc0(sizeof(CollectedCommand));
1766  command->type = SCT_CreateOpClass;
1767  command->in_extension = creating_extension;
1768  ObjectAddressSet(command->d.createopc.address,
1769  OperatorClassRelationId, opcoid);
1770  command->d.createopc.operators = operators;
1771  command->d.createopc.procedures = procedures;
1772  command->parsetree = (Node *) copyObject(stmt);
1773 
1776 
1777  MemoryContextSwitchTo(oldcxt);
1778 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:538
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:336
void * palloc0(Size size)
Definition: mcxt.c:1093
bool creating_extension
Definition: extension.c:71
struct CollectedCommand::@109::@114 createopc
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define copyObject(obj)
Definition: nodes.h:654

◆ EventTriggerCollectGrant()

void EventTriggerCollectGrant ( InternalGrant istmt)

Definition at line 1675 of file event_trigger.c.

References InternalGrant::col_privs, EventTriggerQueryState::commandCollectionInhibited, EventTriggerQueryState::commandList, copyObject, creating_extension, 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().

1676 {
1677  MemoryContext oldcxt;
1678  CollectedCommand *command;
1679  InternalGrant *icopy;
1680  ListCell *cell;
1681 
1682  /* ignore if event trigger context not set, or collection disabled */
1683  if (!currentEventTriggerState ||
1685  return;
1686 
1688 
1689  /*
1690  * This is tedious, but necessary.
1691  */
1692  icopy = palloc(sizeof(InternalGrant));
1693  memcpy(icopy, istmt, sizeof(InternalGrant));
1694  icopy->objects = list_copy(istmt->objects);
1695  icopy->grantees = list_copy(istmt->grantees);
1696  icopy->col_privs = NIL;
1697  foreach(cell, istmt->col_privs)
1698  icopy->col_privs = lappend(icopy->col_privs, copyObject(lfirst(cell)));
1699 
1700  /* Now collect it, using the copied InternalGrant */
1701  command = palloc(sizeof(CollectedCommand));
1702  command->type = SCT_Grant;
1703  command->in_extension = creating_extension;
1704  command->d.grant.istmt = icopy;
1705  command->parsetree = NULL;
1706 
1709 
1710  MemoryContextSwitchTo(oldcxt);
1711 }
#define NIL
Definition: pg_list.h:65
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
List * list_copy(const List *oldlist)
Definition: list.c:1418
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
struct CollectedCommand::@109::@112 grant
union CollectedCommand::@109 d
List * lappend(List *list, void *datum)
Definition: list.c:336
bool creating_extension
Definition: extension.c:71
#define lfirst(lc)
Definition: pg_list.h:169
void * palloc(Size size)
Definition: mcxt.c:1062
#define copyObject(obj)
Definition: nodes.h:654

◆ EventTriggerCollectSimpleCommand()

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

Definition at line 1512 of file event_trigger.c.

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

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

1515 {
1516  MemoryContext oldcxt;
1517  CollectedCommand *command;
1518 
1519  /* ignore if event trigger context not set, or collection disabled */
1520  if (!currentEventTriggerState ||
1522  return;
1523 
1525 
1526  command = palloc(sizeof(CollectedCommand));
1527 
1528  command->type = SCT_Simple;
1529  command->in_extension = creating_extension;
1530 
1531  command->d.simple.address = address;
1532  command->d.simple.secondaryObject = secondaryObject;
1533  command->parsetree = copyObject(parsetree);
1534 
1536  command);
1537 
1538  MemoryContextSwitchTo(oldcxt);
1539 }
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
CollectedCommandType type
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
union CollectedCommand::@109 d
struct CollectedCommand::@109::@110 simple
List * lappend(List *list, void *datum)
Definition: list.c:336
bool creating_extension
Definition: extension.c:71
void * palloc(Size size)
Definition: mcxt.c:1062
#define copyObject(obj)
Definition: nodes.h:654

◆ EventTriggerCommonSetup()

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

Definition at line 556 of file event_trigger.c.

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

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

559 {
560  CommandTag tag;
561  List *cachelist;
562  ListCell *lc;
563  List *runlist = NIL;
564 
565  /*
566  * We want the list of command tags for which this procedure is actually
567  * invoked to match up exactly with the list that CREATE EVENT TRIGGER
568  * accepts. This debugging cross-check will throw an error if this
569  * function is invoked for a command tag that CREATE EVENT TRIGGER won't
570  * accept. (Unfortunately, there doesn't seem to be any simple, automated
571  * way to verify that CREATE EVENT TRIGGER doesn't accept extra stuff that
572  * never reaches this control point.)
573  *
574  * If this cross-check fails for you, you probably need to either adjust
575  * standard_ProcessUtility() not to invoke event triggers for the command
576  * type in question, or you need to adjust event_trigger_ok to accept the
577  * relevant command tag.
578  */
579 #ifdef USE_ASSERT_CHECKING
580  {
581  CommandTag dbgtag;
582 
583  dbgtag = CreateCommandTag(parsetree);
584  if (event == EVT_DDLCommandStart ||
585  event == EVT_DDLCommandEnd ||
586  event == EVT_SQLDrop)
587  {
588  if (!command_tag_event_trigger_ok(dbgtag))
589  elog(ERROR, "unexpected command tag \"%s\"", GetCommandTagName(dbgtag));
590  }
591  else if (event == EVT_TableRewrite)
592  {
593  if (!command_tag_table_rewrite_ok(dbgtag))
594  elog(ERROR, "unexpected command tag \"%s\"", GetCommandTagName(dbgtag));
595  }
596  }
597 #endif
598 
599  /* Use cache to find triggers for this event; fast exit if none. */
600  cachelist = EventCacheLookup(event);
601  if (cachelist == NIL)
602  return NIL;
603 
604  /* Get the command tag. */
605  tag = CreateCommandTag(parsetree);
606 
607  /*
608  * Filter list of event triggers by command tag, and copy them into our
609  * memory context. Once we start running the command triggers, or indeed
610  * once we do anything at all that touches the catalogs, an invalidation
611  * might leave cachelist pointing at garbage, so we must do this before we
612  * can do much else.
613  */
614  foreach(lc, cachelist)
615  {
616  EventTriggerCacheItem *item = lfirst(lc);
617 
618  if (filter_event_trigger(tag, item))
619  {
620  /* We must plan to fire this trigger. */
621  runlist = lappend_oid(runlist, item->fnoid);
622  }
623  }
624 
625  /* don't spend any more time on this if no functions to run */
626  if (runlist == NIL)
627  return NIL;
628 
629  trigdata->type = T_EventTriggerData;
630  trigdata->event = eventstr;
631  trigdata->parsetree = parsetree;
632  trigdata->tag = tag;
633 
634  return runlist;
635 }
#define NIL
Definition: pg_list.h:65
CommandTag
Definition: cmdtag.h:20
CommandTag tag
Definition: event_trigger.h:29
bool command_tag_table_rewrite_ok(CommandTag commandTag)
Definition: cmdtag.c:63
List * lappend_oid(List *list, Oid datum)
Definition: list.c:372
#define ERROR
Definition: elog.h:46
const char * event
Definition: event_trigger.h:27
#define lfirst(lc)
Definition: pg_list.h:169
CommandTag CreateCommandTag(Node *parsetree)
Definition: utility.c:2337
const char * GetCommandTagName(CommandTag commandTag)
Definition: cmdtag.c:45
#define elog(elevel,...)
Definition: elog.h:232
List * EventCacheLookup(EventTriggerEvent event)
Definition: evtcache.c:64
bool command_tag_event_trigger_ok(CommandTag commandTag)
Definition: cmdtag.c:57
Definition: pg_list.h:50
static bool filter_event_trigger(CommandTag tag, EventTriggerCacheItem *item)

◆ EventTriggerDDLCommandEnd()

void EventTriggerDDLCommandEnd ( Node parsetree)

Definition at line 689 of file event_trigger.c.

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

Referenced by ProcessUtilitySlow().

690 {
691  List *runlist;
692  EventTriggerData trigdata;
693 
694  /*
695  * See EventTriggerDDLCommandStart for a discussion about why event
696  * triggers are disabled in single user mode.
697  */
698  if (!IsUnderPostmaster)
699  return;
700 
701  /*
702  * Also do nothing if our state isn't set up, which it won't be if there
703  * weren't any relevant event triggers at the start of the current DDL
704  * command. This test might therefore seem optional, but it's important
705  * because EventTriggerCommonSetup might find triggers that didn't exist
706  * at the time the command started. Although this function itself
707  * wouldn't crash, the event trigger functions would presumably call
708  * pg_event_trigger_ddl_commands which would fail. Better to do nothing
709  * until the next command.
710  */
712  return;
713 
714  runlist = EventTriggerCommonSetup(parsetree,
715  EVT_DDLCommandEnd, "ddl_command_end",
716  &trigdata);
717  if (runlist == NIL)
718  return;
719 
720  /*
721  * Make sure anything the main command did will be visible to the event
722  * triggers.
723  */
725 
726  /* Run the triggers. */
727  EventTriggerInvoke(runlist, &trigdata);
728 
729  /* Cleanup. */
730  list_free(runlist);
731 }
#define NIL
Definition: pg_list.h:65
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata)
bool IsUnderPostmaster
Definition: globals.c:112
void CommandCounterIncrement(void)
Definition: xact.c:1022
void list_free(List *list)
Definition: list.c:1391
Definition: pg_list.h:50

◆ EventTriggerDDLCommandStart()

void EventTriggerDDLCommandStart ( Node parsetree)

Definition at line 641 of file event_trigger.c.

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

Referenced by ProcessUtilitySlow().

642 {
643  List *runlist;
644  EventTriggerData trigdata;
645 
646  /*
647  * Event Triggers are completely disabled in standalone mode. There are
648  * (at least) two reasons for this:
649  *
650  * 1. A sufficiently broken event trigger might not only render the
651  * database unusable, but prevent disabling itself to fix the situation.
652  * In this scenario, restarting in standalone mode provides an escape
653  * hatch.
654  *
655  * 2. BuildEventTriggerCache relies on systable_beginscan_ordered, and
656  * therefore will malfunction if pg_event_trigger's indexes are damaged.
657  * To allow recovery from a damaged index, we need some operating mode
658  * wherein event triggers are disabled. (Or we could implement
659  * heapscan-and-sort logic for that case, but having disaster recovery
660  * scenarios depend on code that's otherwise untested isn't appetizing.)
661  */
662  if (!IsUnderPostmaster)
663  return;
664 
665  runlist = EventTriggerCommonSetup(parsetree,
667  "ddl_command_start",
668  &trigdata);
669  if (runlist == NIL)
670  return;
671 
672  /* Run the triggers. */
673  EventTriggerInvoke(runlist, &trigdata);
674 
675  /* Cleanup. */
676  list_free(runlist);
677 
678  /*
679  * Make sure anything the event triggers did will be visible to the main
680  * command.
681  */
683 }
#define NIL
Definition: pg_list.h:65
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata)
bool IsUnderPostmaster
Definition: globals.c:112
void CommandCounterIncrement(void)
Definition: xact.c:1022
void list_free(List *list)
Definition: list.c:1391
Definition: pg_list.h:50

◆ EventTriggerEndCompleteQuery()

void EventTriggerEndCompleteQuery ( void  )

Definition at line 1121 of file event_trigger.c.

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

Referenced by ProcessUtilitySlow().

1122 {
1123  EventTriggerQueryState *prevstate;
1124 
1125  prevstate = currentEventTriggerState->previous;
1126 
1127  /* this avoids the need for retail pfree of SQLDropList items: */
1129 
1130  currentEventTriggerState = prevstate;
1131 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
struct EventTriggerQueryState * previous
Definition: event_trigger.c:70

◆ EventTriggerInhibitCommandCollection()

void EventTriggerInhibitCommandCollection ( void  )

Definition at line 1478 of file event_trigger.c.

References EventTriggerQueryState::commandCollectionInhibited.

Referenced by ProcessUtilitySlow().

1479 {
1481  return;
1482 
1484 }
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73

◆ EventTriggerInvoke()

static void EventTriggerInvoke ( List fn_oid_list,
EventTriggerData trigdata 
)
static

Definition at line 873 of file event_trigger.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, check_stack_depth(), CommandCounterIncrement(), CurrentMemoryContext, DEBUG1, elog, 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(), EventTriggerSQLDrop(), and EventTriggerTableRewrite().

874 {
875  MemoryContext context;
876  MemoryContext oldcontext;
877  ListCell *lc;
878  bool first = true;
879 
880  /* Guard against stack overflow due to recursive event trigger */
882 
883  /*
884  * Let's evaluate event triggers in their own memory context, so that any
885  * leaks get cleaned up promptly.
886  */
888  "event trigger context",
890  oldcontext = MemoryContextSwitchTo(context);
891 
892  /* Call each event trigger. */
893  foreach(lc, fn_oid_list)
894  {
895  LOCAL_FCINFO(fcinfo, 0);
896  Oid fnoid = lfirst_oid(lc);
897  FmgrInfo flinfo;
898  PgStat_FunctionCallUsage fcusage;
899 
900  elog(DEBUG1, "EventTriggerInvoke %u", fnoid);
901 
902  /*
903  * We want each event trigger to be able to see the results of the
904  * previous event trigger's action. Caller is responsible for any
905  * command-counter increment that is needed between the event trigger
906  * and anything else in the transaction.
907  */
908  if (first)
909  first = false;
910  else
912 
913  /* Look up the function */
914  fmgr_info(fnoid, &flinfo);
915 
916  /* Call the function, passing no arguments but setting a context. */
917  InitFunctionCallInfoData(*fcinfo, &flinfo, 0,
918  InvalidOid, (Node *) trigdata, NULL);
919  pgstat_init_function_usage(fcinfo, &fcusage);
920  FunctionCallInvoke(fcinfo);
921  pgstat_end_function_usage(&fcusage, true);
922 
923  /* Reclaim memory. */
924  MemoryContextReset(context);
925  }
926 
927  /* Restore old memory context and delete the temporary one. */
928  MemoryContextSwitchTo(oldcontext);
929  MemoryContextDelete(context);
930 }
Definition: fmgr.h:56
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
#define AllocSetContextCreate
Definition: memutils.h:173
#define DEBUG1
Definition: elog.h:25
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
Definition: nodes.h:538
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:143
unsigned int Oid
Definition: postgres_ext.h:31
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
Definition: pgstat.c:1914
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
void check_stack_depth(void)
Definition: postgres.c:3469
MemoryContext CurrentMemoryContext
Definition: mcxt.c:42
void CommandCounterIncrement(void)
Definition: xact.c:1022
#define InvalidOid
Definition: postgres_ext.h:36
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
Definition: pgstat.c:1987
#define elog(elevel,...)
Definition: elog.h:232
#define lfirst_oid(lc)
Definition: pg_list.h:171

◆ EventTriggerSQLDrop()

void EventTriggerSQLDrop ( Node parsetree)

Definition at line 737 of file event_trigger.c.

References CommandCounterIncrement(), 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().

738 {
739  List *runlist;
740  EventTriggerData trigdata;
741 
742  /*
743  * See EventTriggerDDLCommandStart for a discussion about why event
744  * triggers are disabled in single user mode.
745  */
746  if (!IsUnderPostmaster)
747  return;
748 
749  /*
750  * Use current state to determine whether this event fires at all. If
751  * there are no triggers for the sql_drop event, then we don't have
752  * anything to do here. Note that dropped object collection is disabled
753  * if this is the case, so even if we were to try to run, the list would
754  * be empty.
755  */
758  return;
759 
760  runlist = EventTriggerCommonSetup(parsetree,
761  EVT_SQLDrop, "sql_drop",
762  &trigdata);
763 
764  /*
765  * Nothing to do if run list is empty. Note this typically can't happen,
766  * because if there are no sql_drop events, then objects-to-drop wouldn't
767  * have been collected in the first place and we would have quit above.
768  * But it could occur if event triggers were dropped partway through.
769  */
770  if (runlist == NIL)
771  return;
772 
773  /*
774  * Make sure anything the main command did will be visible to the event
775  * triggers.
776  */
778 
779  /*
780  * Make sure pg_event_trigger_dropped_objects only works when running
781  * these triggers. Use PG_TRY to ensure in_sql_drop is reset even when
782  * one trigger fails. (This is perhaps not necessary, as the currentState
783  * variable will be removed shortly by our caller, but it seems better to
784  * play safe.)
785  */
787 
788  /* Run the triggers. */
789  PG_TRY();
790  {
791  EventTriggerInvoke(runlist, &trigdata);
792  }
793  PG_FINALLY();
794  {
796  }
797  PG_END_TRY();
798 
799  /* Cleanup. */
800  list_free(runlist);
801 }
#define NIL
Definition: pg_list.h:65
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata)
bool IsUnderPostmaster
Definition: globals.c:112
static bool slist_is_empty(slist_head *head)
Definition: ilist.h:582
#define PG_FINALLY()
Definition: elog.h:330
void CommandCounterIncrement(void)
Definition: xact.c:1022
void list_free(List *list)
Definition: list.c:1391
#define PG_TRY()
Definition: elog.h:313
Definition: pg_list.h:50
#define PG_END_TRY()
Definition: elog.h:338

◆ EventTriggerSQLDropAddObject()

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

Definition at line 1171 of file event_trigger.c.

References AccessShareLock, SQLDropObject::addrargs, SQLDropObject::address, SQLDropObject::addrnames, Assert, attnum, ObjectAddress::classId, 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().

1172 {
1173  SQLDropObject *obj;
1174  MemoryContext oldcxt;
1175 
1177  return;
1178 
1180 
1181  /* don't report temp schemas except my own */
1182  if (object->classId == NamespaceRelationId &&
1183  (isAnyTempNamespace(object->objectId) &&
1184  !isTempNamespace(object->objectId)))
1185  return;
1186 
1188 
1189  obj = palloc0(sizeof(SQLDropObject));
1190  obj->address = *object;
1191  obj->original = original;
1192  obj->normal = normal;
1193 
1194  /*
1195  * Obtain schema names from the object's catalog tuple, if one exists;
1196  * this lets us skip objects in temp schemas. We trust that
1197  * ObjectProperty contains all object classes that can be
1198  * schema-qualified.
1199  */
1200  if (is_objectclass_supported(object->classId))
1201  {
1202  Relation catalog;
1203  HeapTuple tuple;
1204 
1205  catalog = table_open(obj->address.classId, AccessShareLock);
1206  tuple = get_catalog_object_by_oid(catalog,
1207  get_object_attnum_oid(object->classId),
1208  obj->address.objectId);
1209 
1210  if (tuple)
1211  {
1213  Datum datum;
1214  bool isnull;
1215 
1217  if (attnum != InvalidAttrNumber)
1218  {
1219  datum = heap_getattr(tuple, attnum,
1220  RelationGetDescr(catalog), &isnull);
1221  if (!isnull)
1222  {
1223  Oid namespaceId;
1224 
1225  namespaceId = DatumGetObjectId(datum);
1226  /* temp objects are only reported if they are my own */
1227  if (isTempNamespace(namespaceId))
1228  {
1229  obj->schemaname = "pg_temp";
1230  obj->istemp = true;
1231  }
1232  else if (isAnyTempNamespace(namespaceId))
1233  {
1234  pfree(obj);
1235  table_close(catalog, AccessShareLock);
1236  MemoryContextSwitchTo(oldcxt);
1237  return;
1238  }
1239  else
1240  {
1241  obj->schemaname = get_namespace_name(namespaceId);
1242  obj->istemp = false;
1243  }
1244  }
1245  }
1246 
1248  obj->address.objectSubId == 0)
1249  {
1250  attnum = get_object_attnum_name(obj->address.classId);
1251  if (attnum != InvalidAttrNumber)
1252  {
1253  datum = heap_getattr(tuple, attnum,
1254  RelationGetDescr(catalog), &isnull);
1255  if (!isnull)
1256  obj->objname = pstrdup(NameStr(*DatumGetName(datum)));
1257  }
1258  }
1259  }
1260 
1261  table_close(catalog, AccessShareLock);
1262  }
1263  else
1264  {
1265  if (object->classId == NamespaceRelationId &&
1266  isTempNamespace(object->objectId))
1267  obj->istemp = true;
1268  }
1269 
1270  /* object identity, objname and objargs */
1271  obj->objidentity =
1272  getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs,
1273  false);
1274 
1275  /* object type */
1276  obj->objecttype = getObjectTypeDescription(&obj->address, false);
1277 
1279 
1280  MemoryContextSwitchTo(oldcxt);
1281 }
bool get_object_namensp_unique(Oid class_id)
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
slist_node next
Definition: event_trigger.c:88
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
ObjectAddress address
Definition: event_trigger.c:78
AttrNumber get_object_attnum_oid(Oid class_id)
#define RelationGetDescr(relation)
Definition: rel.h:503
const char * objname
Definition: event_trigger.c:80
#define DatumGetObjectId(X)
Definition: postgres.h:544
char * pstrdup(const char *in)
Definition: mcxt.c:1299
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define AccessShareLock
Definition: lockdefs.h:36
static void slist_push_head(slist_head *head, slist_node *node)
Definition: ilist.h:593
List * addrnames
Definition: event_trigger.c:83
AttrNumber get_object_attnum_namespace(Oid class_id)
const char * objidentity
Definition: event_trigger.c:81
unsigned int Oid
Definition: postgres_ext.h:31
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2746
const char * objecttype
Definition: event_trigger.c:82
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
#define DatumGetName(X)
Definition: postgres.h:629
void pfree(void *pointer)
Definition: mcxt.c:1169
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3316
bool isTempNamespace(Oid namespaceId)
Definition: namespace.c:3202
bool EventTriggerSupportsObjectClass(ObjectClass objclass)
const char * schemaname
Definition: event_trigger.c:79
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:761
AttrNumber get_object_attnum_name(Oid class_id)
void * palloc0(Size size)
Definition: mcxt.c:1093
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
uintptr_t Datum
Definition: postgres.h:411
int16 attnum
Definition: pg_attribute.h:83
#define Assert(condition)
Definition: c.h:804
char * getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
#define InvalidAttrNumber
Definition: attnum.h:23
#define NameStr(name)
Definition: c.h:681
bool isAnyTempNamespace(Oid namespaceId)
Definition: namespace.c:3240
bool is_objectclass_supported(Oid class_id)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
int16 AttrNumber
Definition: attnum.h:21

◆ EventTriggerSupportsObjectClass()

bool EventTriggerSupportsObjectClass ( ObjectClass  objclass)

Definition at line 1011 of file event_trigger.c.

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_POLICY, OCLASS_PROC, OCLASS_PUBLICATION, OCLASS_PUBLICATION_NAMESPACE, OCLASS_PUBLICATION_REL, OCLASS_REWRITE, OCLASS_ROLE, 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().

1012 {
1013  switch (objclass)
1014  {
1015  case OCLASS_DATABASE:
1016  case OCLASS_TBLSPACE:
1017  case OCLASS_ROLE:
1018  /* no support for global objects */
1019  return false;
1020  case OCLASS_EVENT_TRIGGER:
1021  /* no support for event triggers on event triggers */
1022  return false;
1023  case OCLASS_CLASS:
1024  case OCLASS_PROC:
1025  case OCLASS_TYPE:
1026  case OCLASS_CAST:
1027  case OCLASS_COLLATION:
1028  case OCLASS_CONSTRAINT:
1029  case OCLASS_CONVERSION:
1030  case OCLASS_DEFAULT:
1031  case OCLASS_LANGUAGE:
1032  case OCLASS_LARGEOBJECT:
1033  case OCLASS_OPERATOR:
1034  case OCLASS_OPCLASS:
1035  case OCLASS_OPFAMILY:
1036  case OCLASS_AM:
1037  case OCLASS_AMOP:
1038  case OCLASS_AMPROC:
1039  case OCLASS_REWRITE:
1040  case OCLASS_TRIGGER:
1041  case OCLASS_SCHEMA:
1042  case OCLASS_STATISTIC_EXT:
1043  case OCLASS_TSPARSER:
1044  case OCLASS_TSDICT:
1045  case OCLASS_TSTEMPLATE:
1046  case OCLASS_TSCONFIG:
1047  case OCLASS_FDW:
1048  case OCLASS_FOREIGN_SERVER:
1049  case OCLASS_USER_MAPPING:
1050  case OCLASS_DEFACL:
1051  case OCLASS_EXTENSION:
1052  case OCLASS_POLICY:
1053  case OCLASS_PUBLICATION:
1056  case OCLASS_SUBSCRIPTION:
1057  case OCLASS_TRANSFORM:
1058  return true;
1059 
1060  /*
1061  * There's intentionally no default: case here; we want the
1062  * compiler to warn if a new OCLASS hasn't been handled above.
1063  */
1064  }
1065 
1066  /* Shouldn't get here, but if we do, say "no support" */
1067  return false;
1068 }

◆ EventTriggerSupportsObjectType()

bool EventTriggerSupportsObjectType ( ObjectType  obtype)

Definition at line 936 of file event_trigger.c.

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_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().

937 {
938  switch (obtype)
939  {
940  case OBJECT_DATABASE:
941  case OBJECT_TABLESPACE:
942  case OBJECT_ROLE:
943  /* no support for global objects */
944  return false;
946  /* no support for event triggers on event triggers */
947  return false;
949  case OBJECT_AGGREGATE:
950  case OBJECT_AMOP:
951  case OBJECT_AMPROC:
952  case OBJECT_ATTRIBUTE:
953  case OBJECT_CAST:
954  case OBJECT_COLUMN:
955  case OBJECT_COLLATION:
956  case OBJECT_CONVERSION:
957  case OBJECT_DEFACL:
958  case OBJECT_DEFAULT:
959  case OBJECT_DOMAIN:
961  case OBJECT_EXTENSION:
962  case OBJECT_FDW:
965  case OBJECT_FUNCTION:
966  case OBJECT_INDEX:
967  case OBJECT_LANGUAGE:
968  case OBJECT_LARGEOBJECT:
969  case OBJECT_MATVIEW:
970  case OBJECT_OPCLASS:
971  case OBJECT_OPERATOR:
972  case OBJECT_OPFAMILY:
973  case OBJECT_POLICY:
974  case OBJECT_PROCEDURE:
975  case OBJECT_PUBLICATION:
978  case OBJECT_ROUTINE:
979  case OBJECT_RULE:
980  case OBJECT_SCHEMA:
981  case OBJECT_SEQUENCE:
982  case OBJECT_SUBSCRIPTION:
985  case OBJECT_TABLE:
986  case OBJECT_TRANSFORM:
987  case OBJECT_TRIGGER:
989  case OBJECT_TSDICTIONARY:
990  case OBJECT_TSPARSER:
991  case OBJECT_TSTEMPLATE:
992  case OBJECT_TYPE:
993  case OBJECT_USER_MAPPING:
994  case OBJECT_VIEW:
995  return true;
996 
997  /*
998  * There's intentionally no default: case here; we want the
999  * compiler to warn if a new ObjectType hasn't been handled above.
1000  */
1001  }
1002 
1003  /* Shouldn't get here, but if we do, say "no support" */
1004  return false;
1005 }

◆ EventTriggerTableRewrite()

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

Definition at line 808 of file event_trigger.c.

References CommandCounterIncrement(), 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().

809 {
810  List *runlist;
811  EventTriggerData trigdata;
812 
813  /*
814  * See EventTriggerDDLCommandStart for a discussion about why event
815  * triggers are disabled in single user mode.
816  */
817  if (!IsUnderPostmaster)
818  return;
819 
820  /*
821  * Also do nothing if our state isn't set up, which it won't be if there
822  * weren't any relevant event triggers at the start of the current DDL
823  * command. This test might therefore seem optional, but it's
824  * *necessary*, because EventTriggerCommonSetup might find triggers that
825  * didn't exist at the time the command started.
826  */
828  return;
829 
830  runlist = EventTriggerCommonSetup(parsetree,
832  "table_rewrite",
833  &trigdata);
834  if (runlist == NIL)
835  return;
836 
837  /*
838  * Make sure pg_event_trigger_table_rewrite_oid only works when running
839  * these triggers. Use PG_TRY to ensure table_rewrite_oid is reset even
840  * when one trigger fails. (This is perhaps not necessary, as the
841  * currentState variable will be removed shortly by our caller, but it
842  * seems better to play safe.)
843  */
846 
847  /* Run the triggers. */
848  PG_TRY();
849  {
850  EventTriggerInvoke(runlist, &trigdata);
851  }
852  PG_FINALLY();
853  {
856  }
857  PG_END_TRY();
858 
859  /* Cleanup. */
860  list_free(runlist);
861 
862  /*
863  * Make sure anything the event triggers did will be visible to the main
864  * command.
865  */
867 }
#define NIL
Definition: pg_list.h:65
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata)
bool IsUnderPostmaster
Definition: globals.c:112
#define PG_FINALLY()
Definition: elog.h:330
void CommandCounterIncrement(void)
Definition: xact.c:1022
#define InvalidOid
Definition: postgres_ext.h:36
void list_free(List *list)
Definition: list.c:1391
#define PG_TRY()
Definition: elog.h:313
Definition: pg_list.h:50
#define PG_END_TRY()
Definition: elog.h:338

◆ EventTriggerUndoInhibitCommandCollection()

void EventTriggerUndoInhibitCommandCollection ( void  )

Definition at line 1490 of file event_trigger.c.

References EventTriggerQueryState::commandCollectionInhibited.

Referenced by ProcessUtilitySlow().

1491 {
1493  return;
1494 
1496 }
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73

◆ filter_event_trigger()

static bool filter_event_trigger ( CommandTag  tag,
EventTriggerCacheItem item 
)
static

Definition at line 525 of file event_trigger.c.

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().

526 {
527  /*
528  * Filter by session replication role, knowing that we never see disabled
529  * items down here.
530  */
532  {
533  if (item->enabled == TRIGGER_FIRES_ON_ORIGIN)
534  return false;
535  }
536  else
537  {
538  if (item->enabled == TRIGGER_FIRES_ON_REPLICA)
539  return false;
540  }
541 
542  /* Filter by tags, if any were specified. */
543  if (!bms_is_empty(item->tagset) && !bms_is_member(tag, item->tagset))
544  return false;
545 
546  /* if we reach that point, we're not filtering out this item */
547  return true;
548 }
#define TRIGGER_FIRES_ON_ORIGIN
Definition: trigger.h:148
int SessionReplicationRole
Definition: trigger.c:68
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
#define SESSION_REPLICATION_ROLE_REPLICA
Definition: trigger.h:140
#define TRIGGER_FIRES_ON_REPLICA
Definition: trigger.h:150
Bitmapset * tagset
Definition: evtcache.h:32
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427

◆ filter_list_to_array()

static Datum filter_list_to_array ( List filterlist)
static

Definition at line 332 of file event_trigger.c.

References construct_array(), cstring_to_text(), i, lfirst, list_length(), palloc(), pfree(), pg_ascii_toupper(), PointerGetDatum, pstrdup(), strVal, and value.

Referenced by insert_event_trigger_tuple().

333 {
334  ListCell *lc;
335  Datum *data;
336  int i = 0,
337  l = list_length(filterlist);
338 
339  data = (Datum *) palloc(l * sizeof(Datum));
340 
341  foreach(lc, filterlist)
342  {
343  const char *value = strVal(lfirst(lc));
344  char *result,
345  *p;
346 
347  result = pstrdup(value);
348  for (p = result; *p; p++)
349  *p = pg_ascii_toupper((unsigned char) *p);
350  data[i++] = PointerGetDatum(cstring_to_text(result));
351  pfree(result);
352  }
353 
354  return PointerGetDatum(construct_array(data, l, TEXTOID,
355  -1, false, TYPALIGN_INT));
356 }
#define PointerGetDatum(X)
Definition: postgres.h:600
char * pstrdup(const char *in)
Definition: mcxt.c:1299
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3319
#define strVal(v)
Definition: value.h:65
unsigned char pg_ascii_toupper(unsigned char ch)
Definition: pgstrcasecmp.c:135
void pfree(void *pointer)
Definition: mcxt.c:1169
uintptr_t Datum
Definition: postgres.h:411
static struct @143 value
text * cstring_to_text(const char *s)
Definition: varlena.c:189
#define lfirst(lc)
Definition: pg_list.h:169
static int list_length(const List *l)
Definition: pg_list.h:149
void * palloc(Size size)
Definition: mcxt.c:1062
int i

◆ get_event_trigger_oid()

Oid get_event_trigger_oid ( const char *  trigname,
bool  missing_ok 
)

Definition at line 506 of file event_trigger.c.

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

Referenced by get_object_address_unqualified().

507 {
508  Oid oid;
509 
510  oid = GetSysCacheOid1(EVENTTRIGGERNAME, Anum_pg_event_trigger_oid,
511  CStringGetDatum(trigname));
512  if (!OidIsValid(oid) && !missing_ok)
513  ereport(ERROR,
514  (errcode(ERRCODE_UNDEFINED_OBJECT),
515  errmsg("event trigger \"%s\" does not exist", trigname)));
516  return oid;
517 }
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:195
int errcode(int sqlerrcode)
Definition: elog.c:698
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:710
#define ERROR
Definition: elog.h:46
#define CStringGetDatum(X)
Definition: postgres.h:622
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ insert_event_trigger_tuple()

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

Definition at line 256 of file event_trigger.c.

References CatalogTupleInsert(), CharGetDatum, ObjectAddress::classId, DEPENDENCY_NORMAL, filter_list_to_array(), GetNewOidWithIndex(), heap_form_tuple(), heap_freetuple(), InvokeObjectPostCreateHook, NameGetDatum, namestrcpy(), NIL, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, RelationData::rd_att, recordDependencyOn(), recordDependencyOnCurrentExtension(), recordDependencyOnOwner(), RowExclusiveLock, table_close(), table_open(), TRIGGER_FIRES_ON_ORIGIN, and values.

Referenced by CreateEventTrigger().

258 {
259  Relation tgrel;
260  Oid trigoid;
261  HeapTuple tuple;
262  Datum values[Natts_pg_trigger];
263  bool nulls[Natts_pg_trigger];
264  NameData evtnamedata,
265  evteventdata;
266  ObjectAddress myself,
267  referenced;
268 
269  /* Open pg_event_trigger. */
270  tgrel = table_open(EventTriggerRelationId, RowExclusiveLock);
271 
272  /* Build the new pg_trigger tuple. */
273  trigoid = GetNewOidWithIndex(tgrel, EventTriggerOidIndexId,
274  Anum_pg_event_trigger_oid);
275  values[Anum_pg_event_trigger_oid - 1] = ObjectIdGetDatum(trigoid);
276  memset(nulls, false, sizeof(nulls));
277  namestrcpy(&evtnamedata, trigname);
278  values[Anum_pg_event_trigger_evtname - 1] = NameGetDatum(&evtnamedata);
279  namestrcpy(&evteventdata, eventname);
280  values[Anum_pg_event_trigger_evtevent - 1] = NameGetDatum(&evteventdata);
281  values[Anum_pg_event_trigger_evtowner - 1] = ObjectIdGetDatum(evtOwner);
282  values[Anum_pg_event_trigger_evtfoid - 1] = ObjectIdGetDatum(funcoid);
283  values[Anum_pg_event_trigger_evtenabled - 1] =
285  if (taglist == NIL)
286  nulls[Anum_pg_event_trigger_evttags - 1] = true;
287  else
288  values[Anum_pg_event_trigger_evttags - 1] =
289  filter_list_to_array(taglist);
290 
291  /* Insert heap tuple. */
292  tuple = heap_form_tuple(tgrel->rd_att, values, nulls);
293  CatalogTupleInsert(tgrel, tuple);
294  heap_freetuple(tuple);
295 
296  /* Depend on owner. */
297  recordDependencyOnOwner(EventTriggerRelationId, trigoid, evtOwner);
298 
299  /* Depend on event trigger function. */
300  myself.classId = EventTriggerRelationId;
301  myself.objectId = trigoid;
302  myself.objectSubId = 0;
303  referenced.classId = ProcedureRelationId;
304  referenced.objectId = funcoid;
305  referenced.objectSubId = 0;
306  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
307 
308  /* Depend on extension, if any. */
309  recordDependencyOnCurrentExtension(&myself, false);
310 
311  /* Post creation hook for new event trigger */
312  InvokeObjectPostCreateHook(EventTriggerRelationId, trigoid, 0);
313 
314  /* Close pg_event_trigger. */
316 
317  return trigoid;
318 }
#define NIL
Definition: pg_list.h:65
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:381
#define NameGetDatum(X)
Definition: postgres.h:639
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
#define InvokeObjectPostCreateHook(classId, objectId, subId)
Definition: objectaccess.h:151
void namestrcpy(Name name, const char *str)
Definition: name.c:233
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:44
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:163
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
unsigned int Oid
Definition: postgres_ext.h:31
#define TRIGGER_FIRES_ON_ORIGIN
Definition: trigger.h:148
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
static Datum filter_list_to_array(List *filterlist)
Definition: c.h:675
#define RowExclusiveLock
Definition: lockdefs.h:38
uintptr_t Datum
Definition: postgres.h:411
TupleDesc rd_att
Definition: rel.h:110
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:191
#define CharGetDatum(X)
Definition: postgres.h:460
static Datum values[MAXATTR]
Definition: bootstrap.c:156
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:221

◆ pg_event_trigger_ddl_commands()

Datum pg_event_trigger_ddl_commands ( PG_FUNCTION_ARGS  )

Definition at line 1849 of file event_trigger.c.

References AccessShareLock, ReturnSetInfo::allowedModes, CollectedCommand::alterTable, CollectedCommand::atscfg, BoolGetDatum, ObjectAddress::classId, EventTriggerQueryState::commandList, CreateCommandName(), CollectedCommand::createopc, CStringGetTextDatum, CollectedCommand::d, CollectedCommand::defprivs, ReturnSetInfo::econtext, ExprContext::ecxt_per_query_memory, elog, ereport, errcode(), errmsg(), ERROR, get_call_result_type(), 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, Int32GetDatum, InvalidAttrNumber, is_objectclass_supported(), IsA, lfirst, MemoryContextSwitchTo(), MemSet, ObjectAddressSet, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, OidIsValid, CollectedCommand::opfam, CollectedCommand::parsetree, PG_RETURN_VOID, PointerGetDatum, RelationGetDescr, ReturnSetInfo::returnMode, SCT_AlterDefaultPrivileges, SCT_AlterOpFamily, SCT_AlterTable, SCT_AlterTSConfig, SCT_CreateOpClass, SCT_Grant, SCT_Simple, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SFRM_Materialize, CollectedCommand::simple, stringify_adefprivs_objtype(), stringify_grant_objtype(), table_close(), table_open(), tuplestore_begin_heap(), tuplestore_donestoring, tuplestore_putvalues(), CollectedCommand::type, generate_unaccent_rules::type, TYPEFUNC_COMPOSITE, values, and work_mem.

1850 {
1851  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1852  TupleDesc tupdesc;
1853  Tuplestorestate *tupstore;
1854  MemoryContext per_query_ctx;
1855  MemoryContext oldcontext;
1856  ListCell *lc;
1857 
1858  /*
1859  * Protect this function from being called out of context
1860  */
1862  ereport(ERROR,
1863  (errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1864  errmsg("%s can only be called in an event trigger function",
1865  "pg_event_trigger_ddl_commands()")));
1866 
1867  /* check to see if caller supports us returning a tuplestore */
1868  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
1869  ereport(ERROR,
1870  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1871  errmsg("set-valued function called in context that cannot accept a set")));
1872  if (!(rsinfo->allowedModes & SFRM_Materialize))
1873  ereport(ERROR,
1874  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1875  errmsg("materialize mode required, but it is not allowed in this context")));
1876 
1877  /* Build a tuple descriptor for our result type */
1878  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1879  elog(ERROR, "return type must be a row type");
1880 
1881  /* Build tuplestore to hold the result rows */
1882  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
1883  oldcontext = MemoryContextSwitchTo(per_query_ctx);
1884 
1885  tupstore = tuplestore_begin_heap(true, false, work_mem);
1886  rsinfo->returnMode = SFRM_Materialize;
1887  rsinfo->setResult = tupstore;
1888  rsinfo->setDesc = tupdesc;
1889 
1890  MemoryContextSwitchTo(oldcontext);
1891 
1893  {
1894  CollectedCommand *cmd = lfirst(lc);
1895  Datum values[9];
1896  bool nulls[9];
1897  ObjectAddress addr;
1898  int i = 0;
1899 
1900  /*
1901  * For IF NOT EXISTS commands that attempt to create an existing
1902  * object, the returned OID is Invalid. Don't return anything.
1903  *
1904  * One might think that a viable alternative would be to look up the
1905  * Oid of the existing object and run the deparse with that. But
1906  * since the parse tree might be different from the one that created
1907  * the object in the first place, we might not end up in a consistent
1908  * state anyway.
1909  */
1910  if (cmd->type == SCT_Simple &&
1911  !OidIsValid(cmd->d.simple.address.objectId))
1912  continue;
1913 
1914  MemSet(nulls, 0, sizeof(nulls));
1915 
1916  switch (cmd->type)
1917  {
1918  case SCT_Simple:
1919  case SCT_AlterTable:
1920  case SCT_AlterOpFamily:
1921  case SCT_CreateOpClass:
1922  case SCT_AlterTSConfig:
1923  {
1924  char *identity;
1925  char *type;
1926  char *schema = NULL;
1927 
1928  if (cmd->type == SCT_Simple)
1929  addr = cmd->d.simple.address;
1930  else if (cmd->type == SCT_AlterTable)
1931  ObjectAddressSet(addr,
1932  cmd->d.alterTable.classId,
1933  cmd->d.alterTable.objectId);
1934  else if (cmd->type == SCT_AlterOpFamily)
1935  addr = cmd->d.opfam.address;
1936  else if (cmd->type == SCT_CreateOpClass)
1937  addr = cmd->d.createopc.address;
1938  else if (cmd->type == SCT_AlterTSConfig)
1939  addr = cmd->d.atscfg.address;
1940 
1941  /*
1942  * If an object was dropped in the same command we may end
1943  * up in a situation where we generated a message but can
1944  * no longer look for the object information, so skip it
1945  * rather than failing. This can happen for example with
1946  * some subcommand combinations of ALTER TABLE.
1947  */
1948  identity = getObjectIdentity(&addr, true);
1949  if (identity == NULL)
1950  continue;
1951 
1952  /* The type can never be NULL. */
1953  type = getObjectTypeDescription(&addr, true);
1954 
1955  /*
1956  * Obtain schema name, if any ("pg_temp" if a temp
1957  * object). If the object class is not in the supported
1958  * list here, we assume it's a schema-less object type,
1959  * and thus "schema" remains set to NULL.
1960  */
1962  {
1963  AttrNumber nspAttnum;
1964 
1965  nspAttnum = get_object_attnum_namespace(addr.classId);
1966  if (nspAttnum != InvalidAttrNumber)
1967  {
1968  Relation catalog;
1969  HeapTuple objtup;
1970  Oid schema_oid;
1971  bool isnull;
1972 
1973  catalog = table_open(addr.classId, AccessShareLock);
1974  objtup = get_catalog_object_by_oid(catalog,
1976  addr.objectId);
1977  if (!HeapTupleIsValid(objtup))
1978  elog(ERROR, "cache lookup failed for object %u/%u",
1979  addr.classId, addr.objectId);
1980  schema_oid =
1981  heap_getattr(objtup, nspAttnum,
1982  RelationGetDescr(catalog), &isnull);
1983  if (isnull)
1984  elog(ERROR,
1985  "invalid null namespace in object %u/%u/%d",
1986  addr.classId, addr.objectId, addr.objectSubId);
1987  schema = get_namespace_name_or_temp(schema_oid);
1988 
1989  table_close(catalog, AccessShareLock);
1990  }
1991  }
1992 
1993  /* classid */
1994  values[i++] = ObjectIdGetDatum(addr.classId);
1995  /* objid */
1996  values[i++] = ObjectIdGetDatum(addr.objectId);
1997  /* objsubid */
1998  values[i++] = Int32GetDatum(addr.objectSubId);
1999  /* command tag */
2000  values[i++] = CStringGetTextDatum(CreateCommandName(cmd->parsetree));
2001  /* object_type */
2002  values[i++] = CStringGetTextDatum(type);
2003  /* schema */
2004  if (schema == NULL)
2005  nulls[i++] = true;
2006  else
2007  values[i++] = CStringGetTextDatum(schema);
2008  /* identity */
2009  values[i++] = CStringGetTextDatum(identity);
2010  /* in_extension */
2011  values[i++] = BoolGetDatum(cmd->in_extension);
2012  /* command */
2013  values[i++] = PointerGetDatum(cmd);
2014  }
2015  break;
2016 
2018  /* classid */
2019  nulls[i++] = true;
2020  /* objid */
2021  nulls[i++] = true;
2022  /* objsubid */
2023  nulls[i++] = true;
2024  /* command tag */
2025  values[i++] = CStringGetTextDatum(CreateCommandName(cmd->parsetree));
2026  /* object_type */
2027  values[i++] = CStringGetTextDatum(stringify_adefprivs_objtype(cmd->d.defprivs.objtype));
2028  /* schema */
2029  nulls[i++] = true;
2030  /* identity */
2031  nulls[i++] = true;
2032  /* in_extension */
2033  values[i++] = BoolGetDatum(cmd->in_extension);
2034  /* command */
2035  values[i++] = PointerGetDatum(cmd);
2036  break;
2037 
2038  case SCT_Grant:
2039  /* classid */
2040  nulls[i++] = true;
2041  /* objid */
2042  nulls[i++] = true;
2043  /* objsubid */
2044  nulls[i++] = true;
2045  /* command tag */
2046  values[i++] = CStringGetTextDatum(cmd->d.grant.istmt->is_grant ?
2047  "GRANT" : "REVOKE");
2048  /* object_type */
2049  values[i++] = CStringGetTextDatum(stringify_grant_objtype(cmd->d.grant.istmt->objtype));
2050  /* schema */
2051  nulls[i++] = true;
2052  /* identity */
2053  nulls[i++] = true;
2054  /* in_extension */
2055  values[i++] = BoolGetDatum(cmd->in_extension);
2056  /* command */
2057  values[i++] = PointerGetDatum(cmd);
2058  break;
2059  }
2060 
2061  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
2062  }
2063 
2064  /* clean up and return the tuplestore */
2065  tuplestore_donestoring(tupstore);
2066 
2067  PG_RETURN_VOID();
2068 }
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
#define IsA(nodeptr, _type_)
Definition: nodes.h:589
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:207
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:167
struct CollectedCommand::@109::@113 opfam
AttrNumber get_object_attnum_oid(Oid class_id)
#define RelationGetDescr(relation)
Definition: rel.h:503
#define PointerGetDatum(X)
Definition: postgres.h:600
static const char * CreateCommandName(Node *parsetree)
Definition: utility.h:103
#define tuplestore_donestoring(state)
Definition: tuplestore.h:60
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define AccessShareLock
Definition: lockdefs.h:36
int errcode(int sqlerrcode)
Definition: elog.c:698
#define MemSet(start, val, len)
Definition: c.h:1008
struct CollectedCommand::@109::@111 alterTable
AttrNumber get_object_attnum_namespace(Oid class_id)
CollectedCommandType type
unsigned int Oid
Definition: postgres_ext.h:31
#define OidIsValid(objectId)
Definition: c.h:710
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
char * getObjectIdentity(const ObjectAddress *object, bool missing_ok)
struct CollectedCommand::@109::@112 grant
union CollectedCommand::@109 d
struct CollectedCommand::@109::@110 simple
#define heap_getattr(tup, attnum, tupleDesc, isnull)
Definition: htup_details.h:761
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:318
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
uintptr_t Datum
Definition: postgres.h:411
int work_mem
Definition: globals.c:124
static const char * stringify_adefprivs_objtype(ObjectType objtype)
#define BoolGetDatum(X)
Definition: postgres.h:446
#define ereport(elevel,...)
Definition: elog.h:157
int allowedModes
Definition: execnodes.h:306
#define PG_RETURN_VOID()
Definition: fmgr.h:349
SetFunctionReturnMode returnMode
Definition: execnodes.h:308
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
struct CollectedCommand::@109::@116 defprivs
#define lfirst(lc)
Definition: pg_list.h:169
char * getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
struct CollectedCommand::@109::@114 createopc
struct CollectedCommand::@109::@115 atscfg
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:234
#define InvalidAttrNumber
Definition: attnum.h:23
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
Tuplestorestate * setResult
Definition: execnodes.h:311
static Datum values[MAXATTR]
Definition: bootstrap.c:156
ExprContext * econtext
Definition: execnodes.h:304
#define Int32GetDatum(X)
Definition: postgres.h:523
TupleDesc setDesc
Definition: execnodes.h:312
int errmsg(const char *fmt,...)
Definition: elog.c:909
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3340
#define elog(elevel,...)
Definition: elog.h:232
int i
#define CStringGetTextDatum(s)
Definition: builtins.h:86
bool is_objectclass_supported(Oid class_id)
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:39
static const char * stringify_grant_objtype(ObjectType objtype)
int16 AttrNumber
Definition: attnum.h:21

◆ pg_event_trigger_dropped_objects()

Datum pg_event_trigger_dropped_objects ( PG_FUNCTION_ARGS  )

Definition at line 1290 of file event_trigger.c.

References SQLDropObject::addrargs, SQLDropObject::address, SQLDropObject::addrnames, ReturnSetInfo::allowedModes, BoolGetDatum, ObjectAddress::classId, construct_empty_array(), CStringGetTextDatum, ReturnSetInfo::econtext, ExprContext::ecxt_per_query_memory, elog, ereport, errcode(), errmsg(), ERROR, get_call_result_type(), i, EventTriggerQueryState::in_sql_drop, Int32GetDatum, IsA, SQLDropObject::istemp, MemoryContextSwitchTo(), MemSet, next, SQLDropObject::normal, ObjectAddress::objectId, ObjectIdGetDatum, ObjectAddress::objectSubId, SQLDropObject::objecttype, SQLDropObject::objidentity, SQLDropObject::objname, SQLDropObject::original, PointerGetDatum, ReturnSetInfo::returnMode, SQLDropObject::schemaname, ReturnSetInfo::setDesc, ReturnSetInfo::setResult, SFRM_Materialize, slist_container, slist_foreach, EventTriggerQueryState::SQLDropList, strlist_to_textarray(), tuplestore_begin_heap(), tuplestore_donestoring, tuplestore_putvalues(), TYPEFUNC_COMPOSITE, values, and work_mem.

1291 {
1292  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1293  TupleDesc tupdesc;
1294  Tuplestorestate *tupstore;
1295  MemoryContext per_query_ctx;
1296  MemoryContext oldcontext;
1297  slist_iter iter;
1298 
1299  /*
1300  * Protect this function from being called out of context
1301  */
1302  if (!currentEventTriggerState ||
1304  ereport(ERROR,
1305  (errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1306  errmsg("%s can only be called in a sql_drop event trigger function",
1307  "pg_event_trigger_dropped_objects()")));
1308 
1309  /* check to see if caller supports us returning a tuplestore */
1310  if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
1311  ereport(ERROR,
1312  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1313  errmsg("set-valued function called in context that cannot accept a set")));
1314  if (!(rsinfo->allowedModes & SFRM_Materialize))
1315  ereport(ERROR,
1316  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1317  errmsg("materialize mode required, but it is not allowed in this context")));
1318 
1319  /* Build a tuple descriptor for our result type */
1320  if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
1321  elog(ERROR, "return type must be a row type");
1322 
1323  /* Build tuplestore to hold the result rows */
1324  per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
1325  oldcontext = MemoryContextSwitchTo(per_query_ctx);
1326 
1327  tupstore = tuplestore_begin_heap(true, false, work_mem);
1328  rsinfo->returnMode = SFRM_Materialize;
1329  rsinfo->setResult = tupstore;
1330  rsinfo->setDesc = tupdesc;
1331 
1332  MemoryContextSwitchTo(oldcontext);
1333 
1335  {
1336  SQLDropObject *obj;
1337  int i = 0;
1338  Datum values[12];
1339  bool nulls[12];
1340 
1341  obj = slist_container(SQLDropObject, next, iter.cur);
1342 
1343  MemSet(values, 0, sizeof(values));
1344  MemSet(nulls, 0, sizeof(nulls));
1345 
1346  /* classid */
1347  values[i++] = ObjectIdGetDatum(obj->address.classId);
1348 
1349  /* objid */
1350  values[i++] = ObjectIdGetDatum(obj->address.objectId);
1351 
1352  /* objsubid */
1353  values[i++] = Int32GetDatum(obj->address.objectSubId);
1354 
1355  /* original */
1356  values[i++] = BoolGetDatum(obj->original);
1357 
1358  /* normal */
1359  values[i++] = BoolGetDatum(obj->normal);
1360 
1361  /* is_temporary */
1362  values[i++] = BoolGetDatum(obj->istemp);
1363 
1364  /* object_type */
1365  values[i++] = CStringGetTextDatum(obj->objecttype);
1366 
1367  /* schema_name */
1368  if (obj->schemaname)
1369  values[i++] = CStringGetTextDatum(obj->schemaname);
1370  else
1371  nulls[i++] = true;
1372 
1373  /* object_name */
1374  if (obj->objname)
1375  values[i++] = CStringGetTextDatum(obj->objname);
1376  else
1377  nulls[i++] = true;
1378 
1379  /* object_identity */
1380  if (obj->objidentity)
1381  values[i++] = CStringGetTextDatum(obj->objidentity);
1382  else
1383  nulls[i++] = true;
1384 
1385  /* address_names and address_args */
1386  if (obj->addrnames)
1387  {
1388  values[i++] = PointerGetDatum(strlist_to_textarray(obj->addrnames));
1389 
1390  if (obj->addrargs)
1391  values[i++] = PointerGetDatum(strlist_to_textarray(obj->addrargs));
1392  else
1393  values[i++] = PointerGetDatum(construct_empty_array(TEXTOID));
1394  }
1395  else
1396  {
1397  nulls[i++] = true;
1398  nulls[i++] = true;
1399  }
1400 
1401  tuplestore_putvalues(tupstore, tupdesc, values, nulls);
1402  }
1403 
1404  /* clean up and return the tuplestore */
1405  tuplestore_donestoring(tupstore);
1406 
1407  return (Datum) 0;
1408 }
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, Datum *values, bool *isnull)
Definition: tuplestore.c:750
#define IsA(nodeptr, _type_)
Definition: nodes.h:589
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
Definition: funcapi.c:207
static int32 next
Definition: blutils.c:219
ObjectAddress address
Definition: event_trigger.c:78
#define PointerGetDatum(X)
Definition: postgres.h:600
const char * objname
Definition: event_trigger.c:80
#define tuplestore_donestoring(state)
Definition: tuplestore.h:60
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
List * addrnames
Definition: event_trigger.c:83
int errcode(int sqlerrcode)
Definition: elog.c:698
#define MemSet(start, val, len)
Definition: c.h:1008
const char * objidentity
Definition: event_trigger.c:81
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3440
const char * objecttype
Definition: event_trigger.c:82
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
const char * schemaname
Definition: event_trigger.c:79
Tuplestorestate * tuplestore_begin_heap(bool randomAccess, bool interXact, int maxKBytes)
Definition: tuplestore.c:318
#define slist_container(type, membername, ptr)
Definition: ilist.h:693
uintptr_t Datum
Definition: postgres.h:411
int work_mem
Definition: globals.c:124
#define BoolGetDatum(X)
Definition: postgres.h:446
#define ereport(elevel,...)
Definition: elog.h:157
int allowedModes
Definition: execnodes.h:306
SetFunctionReturnMode returnMode
Definition: execnodes.h:308
MemoryContext ecxt_per_query_memory
Definition: execnodes.h:234
Tuplestorestate * setResult
Definition: execnodes.h:311
static Datum values[MAXATTR]
Definition: bootstrap.c:156
ExprContext * econtext
Definition: execnodes.h:304
#define slist_foreach(iter, lhead)
Definition: ilist.h:719
#define Int32GetDatum(X)
Definition: postgres.h:523
TupleDesc setDesc
Definition: execnodes.h:312
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define elog(elevel,...)
Definition: elog.h:232
int i
#define CStringGetTextDatum(s)
Definition: builtins.h:86
ArrayType * strlist_to_textarray(List *list)

◆ pg_event_trigger_table_rewrite_oid()

Datum pg_event_trigger_table_rewrite_oid ( PG_FUNCTION_ARGS  )

Definition at line 1417 of file event_trigger.c.

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

1418 {
1419  /*
1420  * Protect this function from being called out of context
1421  */
1422  if (!currentEventTriggerState ||
1424  ereport(ERROR,
1425  (errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1426  errmsg("%s can only be called in a table_rewrite event trigger function",
1427  "pg_event_trigger_table_rewrite_oid()")));
1428 
1430 }
int errcode(int sqlerrcode)
Definition: elog.c:698
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
#define ERROR
Definition: elog.h:46
#define InvalidOid
Definition: postgres_ext.h:36
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define PG_RETURN_OID(x)
Definition: fmgr.h:360

◆ pg_event_trigger_table_rewrite_reason()

Datum pg_event_trigger_table_rewrite_reason ( PG_FUNCTION_ARGS  )

Definition at line 1438 of file event_trigger.c.

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

1439 {
1440  /*
1441  * Protect this function from being called out of context
1442  */
1443  if (!currentEventTriggerState ||
1445  ereport(ERROR,
1446  (errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1447  errmsg("%s can only be called in a table_rewrite event trigger function",
1448  "pg_event_trigger_table_rewrite_reason()")));
1449 
1451 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
int errcode(int sqlerrcode)
Definition: elog.c:698
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:73
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ stringify_adefprivs_objtype()

static const char * stringify_adefprivs_objtype ( ObjectType  objtype)
static

Definition at line 2158 of file event_trigger.c.

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_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 pg_event_trigger_ddl_commands().

2159 {
2160  switch (objtype)
2161  {
2162  case OBJECT_COLUMN:
2163  return "COLUMNS";
2164  case OBJECT_TABLE:
2165  return "TABLES";
2166  case OBJECT_SEQUENCE:
2167  return "SEQUENCES";
2168  case OBJECT_DATABASE:
2169  return "DATABASES";
2170  case OBJECT_DOMAIN:
2171  return "DOMAINS";
2172  case OBJECT_FDW:
2173  return "FOREIGN DATA WRAPPERS";
2174  case OBJECT_FOREIGN_SERVER:
2175  return "FOREIGN SERVERS";
2176  case OBJECT_FUNCTION:
2177  return "FUNCTIONS";
2178  case OBJECT_LANGUAGE:
2179  return "LANGUAGES";
2180  case OBJECT_LARGEOBJECT:
2181  return "LARGE OBJECTS";
2182  case OBJECT_SCHEMA:
2183  return "SCHEMAS";
2184  case OBJECT_PROCEDURE:
2185  return "PROCEDURES";
2186  case OBJECT_ROUTINE:
2187  return "ROUTINES";
2188  case OBJECT_TABLESPACE:
2189  return "TABLESPACES";
2190  case OBJECT_TYPE:
2191  return "TYPES";
2192  /* these currently aren't used */
2193  case OBJECT_ACCESS_METHOD:
2194  case OBJECT_AGGREGATE:
2195  case OBJECT_AMOP:
2196  case OBJECT_AMPROC:
2197  case OBJECT_ATTRIBUTE:
2198  case OBJECT_CAST:
2199  case OBJECT_COLLATION:
2200  case OBJECT_CONVERSION:
2201  case OBJECT_DEFAULT:
2202  case OBJECT_DEFACL:
2203  case OBJECT_DOMCONSTRAINT:
2204  case OBJECT_EVENT_TRIGGER:
2205  case OBJECT_EXTENSION:
2206  case OBJECT_FOREIGN_TABLE:
2207  case OBJECT_INDEX:
2208  case OBJECT_MATVIEW:
2209  case OBJECT_OPCLASS:
2210  case OBJECT_OPERATOR:
2211  case OBJECT_OPFAMILY:
2212  case OBJECT_POLICY:
2213  case OBJECT_PUBLICATION:
2216  case OBJECT_ROLE:
2217  case OBJECT_RULE:
2218  case OBJECT_STATISTIC_EXT:
2219  case OBJECT_SUBSCRIPTION:
2220  case OBJECT_TABCONSTRAINT:
2221  case OBJECT_TRANSFORM:
2222  case OBJECT_TRIGGER:
2224  case OBJECT_TSDICTIONARY:
2225  case OBJECT_TSPARSER:
2226  case OBJECT_TSTEMPLATE:
2227  case OBJECT_USER_MAPPING:
2228  case OBJECT_VIEW:
2229  elog(ERROR, "unsupported object type: %d", (int) objtype);
2230  }
2231 
2232  return "???"; /* keep compiler quiet */
2233 }
#define ERROR
Definition: elog.h:46
#define elog(elevel,...)
Definition: elog.h:232

◆ stringify_grant_objtype()

static const char * stringify_grant_objtype ( ObjectType  objtype)
static

Definition at line 2075 of file event_trigger.c.

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_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 pg_event_trigger_ddl_commands().

2076 {
2077  switch (objtype)
2078  {
2079  case OBJECT_COLUMN:
2080  return "COLUMN";
2081  case OBJECT_TABLE:
2082  return "TABLE";
2083  case OBJECT_SEQUENCE:
2084  return "SEQUENCE";
2085  case OBJECT_DATABASE:
2086  return "DATABASE";
2087  case OBJECT_DOMAIN:
2088  return "DOMAIN";
2089  case OBJECT_FDW:
2090  return "FOREIGN DATA WRAPPER";
2091  case OBJECT_FOREIGN_SERVER:
2092  return "FOREIGN SERVER";
2093  case OBJECT_FUNCTION:
2094  return "FUNCTION";
2095  case OBJECT_LANGUAGE:
2096  return "LANGUAGE";
2097  case OBJECT_LARGEOBJECT:
2098  return "LARGE OBJECT";
2099  case OBJECT_SCHEMA:
2100  return "SCHEMA";
2101  case OBJECT_PROCEDURE:
2102  return "PROCEDURE";
2103  case OBJECT_ROUTINE:
2104  return "ROUTINE";
2105  case OBJECT_TABLESPACE:
2106  return "TABLESPACE";
2107  case OBJECT_TYPE:
2108  return "TYPE";
2109  /* these currently aren't used */
2110  case OBJECT_ACCESS_METHOD:
2111  case OBJECT_AGGREGATE:
2112  case OBJECT_AMOP:
2113  case OBJECT_AMPROC:
2114  case OBJECT_ATTRIBUTE:
2115  case OBJECT_CAST:
2116  case OBJECT_COLLATION:
2117  case OBJECT_CONVERSION:
2118  case OBJECT_DEFAULT:
2119  case OBJECT_DEFACL:
2120  case OBJECT_DOMCONSTRAINT:
2121  case OBJECT_EVENT_TRIGGER:
2122  case OBJECT_EXTENSION:
2123  case OBJECT_FOREIGN_TABLE:
2124  case OBJECT_INDEX:
2125  case OBJECT_MATVIEW:
2126  case OBJECT_OPCLASS:
2127  case OBJECT_OPERATOR:
2128  case OBJECT_OPFAMILY:
2129  case OBJECT_POLICY:
2130  case OBJECT_PUBLICATION:
2133  case OBJECT_ROLE:
2134  case OBJECT_RULE:
2135  case OBJECT_STATISTIC_EXT:
2136  case OBJECT_SUBSCRIPTION:
2137  case OBJECT_TABCONSTRAINT:
2138  case OBJECT_TRANSFORM:
2139  case OBJECT_TRIGGER:
2141  case OBJECT_TSDICTIONARY:
2142  case OBJECT_TSPARSER:
2143  case OBJECT_TSTEMPLATE:
2144  case OBJECT_USER_MAPPING:
2145  case OBJECT_VIEW:
2146  elog(ERROR, "unsupported object type: %d", (int) objtype);
2147  }
2148 
2149  return "???"; /* keep compiler quiet */
2150 }
#define ERROR
Definition: elog.h:46
#define elog(elevel,...)
Definition: elog.h:232

◆ trackDroppedObjectsNeeded()

bool trackDroppedObjectsNeeded ( void  )

Definition at line 1139 of file event_trigger.c.

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

Referenced by deleteObjectsInList(), and EventTriggerBeginCompleteQuery().

1140 {
1141  /*
1142  * true if any sql_drop, table_rewrite, ddl_command_end event trigger
1143  * exists
1144  */
1145  return list_length(EventCacheLookup(EVT_SQLDrop)) > 0 ||
1148 }
static int list_length(const List *l)
Definition: pg_list.h:149
List * EventCacheLookup(EventTriggerEvent event)
Definition: evtcache.c:64

◆ validate_ddl_tags()

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

Definition at line 195 of file event_trigger.c.

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

Referenced by CreateEventTrigger().

196 {
197  ListCell *lc;
198 
199  foreach(lc, taglist)
200  {
201  const char *tagstr = strVal(lfirst(lc));
202  CommandTag commandTag = GetCommandTagEnum(tagstr);
203 
204  if (commandTag == CMDTAG_UNKNOWN)
205  ereport(ERROR,
206  (errcode(ERRCODE_SYNTAX_ERROR),
207  errmsg("filter value \"%s\" not recognized for filter variable \"%s\"",
208  tagstr, filtervar)));
209  if (!command_tag_event_trigger_ok(commandTag))
210  ereport(ERROR,
211  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
212  /* translator: %s represents an SQL statement name */
213  errmsg("event triggers are not supported for %s",
214  tagstr)));
215  }
216 }
CommandTag
Definition: cmdtag.h:20
#define strVal(v)
Definition: value.h:65
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
#define lfirst(lc)
Definition: pg_list.h:169
CommandTag GetCommandTagEnum(const char *commandname)
Definition: cmdtag.c:74
int errmsg(const char *fmt,...)
Definition: elog.c:909
bool command_tag_event_trigger_ok(CommandTag commandTag)
Definition: cmdtag.c:57

◆ validate_table_rewrite_tags()

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

Definition at line 222 of file event_trigger.c.

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

Referenced by CreateEventTrigger().

223 {
224  ListCell *lc;
225 
226  foreach(lc, taglist)
227  {
228  const char *tagstr = strVal(lfirst(lc));
229  CommandTag commandTag = GetCommandTagEnum(tagstr);
230 
231  if (!command_tag_table_rewrite_ok(commandTag))
232  ereport(ERROR,
233  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
234  /* translator: %s represents an SQL statement name */
235  errmsg("event triggers are not supported for %s",
236  tagstr)));
237  }
238 }
CommandTag
Definition: cmdtag.h:20
#define strVal(v)
Definition: value.h:65
int errcode(int sqlerrcode)
Definition: elog.c:698
bool command_tag_table_rewrite_ok(CommandTag commandTag)
Definition: cmdtag.c:63
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
#define lfirst(lc)
Definition: pg_list.h:169
CommandTag GetCommandTagEnum(const char *commandname)
Definition: cmdtag.c:74
int errmsg(const char *fmt,...)
Definition: elog.c:909

Variable Documentation

◆ currentEventTriggerState

EventTriggerQueryState* currentEventTriggerState = NULL
static

Definition at line 73 of file event_trigger.c.

Referenced by EventTriggerBeginCompleteQuery().