PostgreSQL Source Code  git master
event_trigger.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * event_trigger.c
4  * PostgreSQL EVENT TRIGGER support code.
5  *
6  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * IDENTIFICATION
10  * src/backend/commands/event_trigger.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 #include "postgres.h"
15 
16 #include "access/heapam.h"
17 #include "access/htup_details.h"
18 #include "access/table.h"
19 #include "access/xact.h"
20 #include "catalog/catalog.h"
21 #include "catalog/dependency.h"
22 #include "catalog/indexing.h"
23 #include "catalog/objectaccess.h"
24 #include "catalog/pg_database.h"
26 #include "catalog/pg_namespace.h"
27 #include "catalog/pg_opclass.h"
28 #include "catalog/pg_opfamily.h"
29 #include "catalog/pg_proc.h"
30 #include "catalog/pg_trigger.h"
31 #include "catalog/pg_ts_config.h"
32 #include "catalog/pg_type.h"
33 #include "commands/dbcommands.h"
34 #include "commands/event_trigger.h"
35 #include "commands/extension.h"
36 #include "commands/trigger.h"
37 #include "funcapi.h"
38 #include "lib/ilist.h"
39 #include "miscadmin.h"
40 #include "parser/parse_func.h"
41 #include "pgstat.h"
42 #include "storage/lmgr.h"
43 #include "tcop/deparse_utility.h"
44 #include "tcop/utility.h"
45 #include "utils/acl.h"
46 #include "utils/builtins.h"
47 #include "utils/evtcache.h"
48 #include "utils/fmgroids.h"
49 #include "utils/inval.h"
50 #include "utils/lsyscache.h"
51 #include "utils/memutils.h"
52 #include "utils/rel.h"
53 #include "utils/snapmgr.h"
54 #include "utils/syscache.h"
55 
56 typedef struct EventTriggerQueryState
57 {
58  /* memory context for this state's objects */
60 
61  /* sql_drop */
64 
65  /* table_rewrite */
66  Oid table_rewrite_oid; /* InvalidOid, or set for table_rewrite
67  * event */
68  int table_rewrite_reason; /* AT_REWRITE reason */
69 
70  /* Support for command collection */
73  List *commandList; /* list of CollectedCommand; see
74  * deparse_utility.h */
77 
79 
80 /* GUC parameter */
81 bool event_triggers = true;
82 
83 /* Support for dropped objects */
84 typedef struct SQLDropObject
85 {
87  const char *schemaname;
88  const char *objname;
89  const char *objidentity;
90  const char *objecttype;
93  bool original;
94  bool normal;
95  bool istemp;
98 
100  HeapTuple tup,
101  Oid newOwnerId);
102 static void error_duplicate_filter_variable(const char *defname);
103 static Datum filter_list_to_array(List *filterlist);
104 static Oid insert_event_trigger_tuple(const char *trigname, const char *eventname,
105  Oid evtOwner, Oid funcoid, List *taglist);
106 static void validate_ddl_tags(const char *filtervar, List *taglist);
107 static void validate_table_rewrite_tags(const char *filtervar, List *taglist);
108 static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata);
109 static const char *stringify_grant_objtype(ObjectType objtype);
110 static const char *stringify_adefprivs_objtype(ObjectType objtype);
111 static void SetDatatabaseHasLoginEventTriggers(void);
112 
113 /*
114  * Create an event trigger.
115  */
116 Oid
118 {
119  HeapTuple tuple;
120  Oid funcoid;
121  Oid funcrettype;
122  Oid evtowner = GetUserId();
123  ListCell *lc;
124  List *tags = NULL;
125 
126  /*
127  * It would be nice to allow database owners or even regular users to do
128  * this, but there are obvious privilege escalation risks which would have
129  * to somehow be plugged first.
130  */
131  if (!superuser())
132  ereport(ERROR,
133  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
134  errmsg("permission denied to create event trigger \"%s\"",
135  stmt->trigname),
136  errhint("Must be superuser to create an event trigger.")));
137 
138  /* Validate event name. */
139  if (strcmp(stmt->eventname, "ddl_command_start") != 0 &&
140  strcmp(stmt->eventname, "ddl_command_end") != 0 &&
141  strcmp(stmt->eventname, "sql_drop") != 0 &&
142  strcmp(stmt->eventname, "login") != 0 &&
143  strcmp(stmt->eventname, "table_rewrite") != 0)
144  ereport(ERROR,
145  (errcode(ERRCODE_SYNTAX_ERROR),
146  errmsg("unrecognized event name \"%s\"",
147  stmt->eventname)));
148 
149  /* Validate filter conditions. */
150  foreach(lc, stmt->whenclause)
151  {
152  DefElem *def = (DefElem *) lfirst(lc);
153 
154  if (strcmp(def->defname, "tag") == 0)
155  {
156  if (tags != NULL)
158  tags = (List *) def->arg;
159  }
160  else
161  ereport(ERROR,
162  (errcode(ERRCODE_SYNTAX_ERROR),
163  errmsg("unrecognized filter variable \"%s\"", def->defname)));
164  }
165 
166  /* Validate tag list, if any. */
167  if ((strcmp(stmt->eventname, "ddl_command_start") == 0 ||
168  strcmp(stmt->eventname, "ddl_command_end") == 0 ||
169  strcmp(stmt->eventname, "sql_drop") == 0)
170  && tags != NULL)
171  validate_ddl_tags("tag", tags);
172  else if (strcmp(stmt->eventname, "table_rewrite") == 0
173  && tags != NULL)
174  validate_table_rewrite_tags("tag", tags);
175  else if (strcmp(stmt->eventname, "login") == 0 && tags != NULL)
176  ereport(ERROR,
177  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
178  errmsg("tag filtering is not supported for login event trigger")));
179 
180  /*
181  * Give user a nice error message if an event trigger of the same name
182  * already exists.
183  */
184  tuple = SearchSysCache1(EVENTTRIGGERNAME, CStringGetDatum(stmt->trigname));
185  if (HeapTupleIsValid(tuple))
186  ereport(ERROR,
188  errmsg("event trigger \"%s\" already exists",
189  stmt->trigname)));
190 
191  /* Find and validate the trigger function. */
192  funcoid = LookupFuncName(stmt->funcname, 0, NULL, false);
193  funcrettype = get_func_rettype(funcoid);
194  if (funcrettype != EVENT_TRIGGEROID)
195  ereport(ERROR,
196  (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
197  errmsg("function %s must return type %s",
198  NameListToString(stmt->funcname), "event_trigger")));
199 
200  /* Insert catalog entries. */
201  return insert_event_trigger_tuple(stmt->trigname, stmt->eventname,
202  evtowner, funcoid, tags);
203 }
204 
205 /*
206  * Validate DDL command tags.
207  */
208 static void
209 validate_ddl_tags(const char *filtervar, List *taglist)
210 {
211  ListCell *lc;
212 
213  foreach(lc, taglist)
214  {
215  const char *tagstr = strVal(lfirst(lc));
216  CommandTag commandTag = GetCommandTagEnum(tagstr);
217 
218  if (commandTag == CMDTAG_UNKNOWN)
219  ereport(ERROR,
220  (errcode(ERRCODE_SYNTAX_ERROR),
221  errmsg("filter value \"%s\" not recognized for filter variable \"%s\"",
222  tagstr, filtervar)));
223  if (!command_tag_event_trigger_ok(commandTag))
224  ereport(ERROR,
225  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
226  /* translator: %s represents an SQL statement name */
227  errmsg("event triggers are not supported for %s",
228  tagstr)));
229  }
230 }
231 
232 /*
233  * Validate DDL command tags for event table_rewrite.
234  */
235 static void
236 validate_table_rewrite_tags(const char *filtervar, List *taglist)
237 {
238  ListCell *lc;
239 
240  foreach(lc, taglist)
241  {
242  const char *tagstr = strVal(lfirst(lc));
243  CommandTag commandTag = GetCommandTagEnum(tagstr);
244 
245  if (!command_tag_table_rewrite_ok(commandTag))
246  ereport(ERROR,
247  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
248  /* translator: %s represents an SQL statement name */
249  errmsg("event triggers are not supported for %s",
250  tagstr)));
251  }
252 }
253 
254 /*
255  * Complain about a duplicate filter variable.
256  */
257 static void
259 {
260  ereport(ERROR,
261  (errcode(ERRCODE_SYNTAX_ERROR),
262  errmsg("filter variable \"%s\" specified more than once",
263  defname)));
264 }
265 
266 /*
267  * Insert the new pg_event_trigger row and record dependencies.
268  */
269 static Oid
270 insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtOwner,
271  Oid funcoid, List *taglist)
272 {
273  Relation tgrel;
274  Oid trigoid;
275  HeapTuple tuple;
276  Datum values[Natts_pg_trigger];
277  bool nulls[Natts_pg_trigger];
278  NameData evtnamedata,
279  evteventdata;
280  ObjectAddress myself,
281  referenced;
282 
283  /* Open pg_event_trigger. */
284  tgrel = table_open(EventTriggerRelationId, RowExclusiveLock);
285 
286  /* Build the new pg_trigger tuple. */
287  trigoid = GetNewOidWithIndex(tgrel, EventTriggerOidIndexId,
288  Anum_pg_event_trigger_oid);
289  values[Anum_pg_event_trigger_oid - 1] = ObjectIdGetDatum(trigoid);
290  memset(nulls, false, sizeof(nulls));
291  namestrcpy(&evtnamedata, trigname);
292  values[Anum_pg_event_trigger_evtname - 1] = NameGetDatum(&evtnamedata);
293  namestrcpy(&evteventdata, eventname);
294  values[Anum_pg_event_trigger_evtevent - 1] = NameGetDatum(&evteventdata);
295  values[Anum_pg_event_trigger_evtowner - 1] = ObjectIdGetDatum(evtOwner);
296  values[Anum_pg_event_trigger_evtfoid - 1] = ObjectIdGetDatum(funcoid);
297  values[Anum_pg_event_trigger_evtenabled - 1] =
299  if (taglist == NIL)
300  nulls[Anum_pg_event_trigger_evttags - 1] = true;
301  else
302  values[Anum_pg_event_trigger_evttags - 1] =
303  filter_list_to_array(taglist);
304 
305  /* Insert heap tuple. */
306  tuple = heap_form_tuple(tgrel->rd_att, values, nulls);
307  CatalogTupleInsert(tgrel, tuple);
308  heap_freetuple(tuple);
309 
310  /*
311  * Login event triggers have an additional flag in pg_database to avoid
312  * faster lookups in hot codepaths. Set the flag unless already True.
313  */
314  if (strcmp(eventname, "login") == 0)
316 
317  /* Depend on owner. */
318  recordDependencyOnOwner(EventTriggerRelationId, trigoid, evtOwner);
319 
320  /* Depend on event trigger function. */
321  myself.classId = EventTriggerRelationId;
322  myself.objectId = trigoid;
323  myself.objectSubId = 0;
324  referenced.classId = ProcedureRelationId;
325  referenced.objectId = funcoid;
326  referenced.objectSubId = 0;
327  recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
328 
329  /* Depend on extension, if any. */
330  recordDependencyOnCurrentExtension(&myself, false);
331 
332  /* Post creation hook for new event trigger */
333  InvokeObjectPostCreateHook(EventTriggerRelationId, trigoid, 0);
334 
335  /* Close pg_event_trigger. */
337 
338  return trigoid;
339 }
340 
341 /*
342  * In the parser, a clause like WHEN tag IN ('cmd1', 'cmd2') is represented
343  * by a DefElem whose value is a List of String nodes; in the catalog, we
344  * store the list of strings as a text array. This function transforms the
345  * former representation into the latter one.
346  *
347  * For cleanliness, we store command tags in the catalog as text. It's
348  * possible (although not currently anticipated) that we might have
349  * a case-sensitive filter variable in the future, in which case this would
350  * need some further adjustment.
351  */
352 static Datum
354 {
355  ListCell *lc;
356  Datum *data;
357  int i = 0,
358  l = list_length(filterlist);
359 
360  data = (Datum *) palloc(l * sizeof(Datum));
361 
362  foreach(lc, filterlist)
363  {
364  const char *value = strVal(lfirst(lc));
365  char *result,
366  *p;
367 
368  result = pstrdup(value);
369  for (p = result; *p; p++)
370  *p = pg_ascii_toupper((unsigned char) *p);
371  data[i++] = PointerGetDatum(cstring_to_text(result));
372  pfree(result);
373  }
374 
375  return PointerGetDatum(construct_array_builtin(data, l, TEXTOID));
376 }
377 
378 /*
379  * Set pg_database.dathasloginevt flag for current database indicating that
380  * current database has on login triggers.
381  */
382 void
384 {
385  /* Set dathasloginevt flag in pg_database */
386  Form_pg_database db;
387  Relation pg_db = table_open(DatabaseRelationId, RowExclusiveLock);
388  HeapTuple tuple;
389 
390  /*
391  * Use shared lock to prevent a conflict with EventTriggerOnLogin() trying
392  * to reset pg_database.dathasloginevt flag. Note, this lock doesn't
393  * effectively blocks database or other objection. It's just custom lock
394  * tag used to prevent multiple backends changing
395  * pg_database.dathasloginevt flag.
396  */
397  LockSharedObject(DatabaseRelationId, MyDatabaseId, 0, AccessExclusiveLock);
398 
399  tuple = SearchSysCacheCopy1(DATABASEOID, ObjectIdGetDatum(MyDatabaseId));
400  if (!HeapTupleIsValid(tuple))
401  elog(ERROR, "cache lookup failed for database %u", MyDatabaseId);
402  db = (Form_pg_database) GETSTRUCT(tuple);
403  if (!db->dathasloginevt)
404  {
405  db->dathasloginevt = true;
406  CatalogTupleUpdate(pg_db, &tuple->t_self, tuple);
408  }
410  heap_freetuple(tuple);
411 }
412 
413 /*
414  * ALTER EVENT TRIGGER foo ENABLE|DISABLE|ENABLE ALWAYS|REPLICA
415  */
416 Oid
418 {
419  Relation tgrel;
420  HeapTuple tup;
421  Oid trigoid;
422  Form_pg_event_trigger evtForm;
423  char tgenabled = stmt->tgenabled;
424 
425  tgrel = table_open(EventTriggerRelationId, RowExclusiveLock);
426 
427  tup = SearchSysCacheCopy1(EVENTTRIGGERNAME,
428  CStringGetDatum(stmt->trigname));
429  if (!HeapTupleIsValid(tup))
430  ereport(ERROR,
431  (errcode(ERRCODE_UNDEFINED_OBJECT),
432  errmsg("event trigger \"%s\" does not exist",
433  stmt->trigname)));
434 
435  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
436  trigoid = evtForm->oid;
437 
438  if (!object_ownercheck(EventTriggerRelationId, trigoid, GetUserId()))
440  stmt->trigname);
441 
442  /* tuple is a copy, so we can modify it below */
443  evtForm->evtenabled = tgenabled;
444 
445  CatalogTupleUpdate(tgrel, &tup->t_self, tup);
446 
447  /*
448  * Login event triggers have an additional flag in pg_database to avoid
449  * faster lookups in hot codepaths. Set the flag unless already True.
450  */
451  if (namestrcmp(&evtForm->evtevent, "login") == 0 &&
452  tgenabled != TRIGGER_DISABLED)
454 
455  InvokeObjectPostAlterHook(EventTriggerRelationId,
456  trigoid, 0);
457 
458  /* clean up */
459  heap_freetuple(tup);
461 
462  return trigoid;
463 }
464 
465 /*
466  * Change event trigger's owner -- by name
467  */
469 AlterEventTriggerOwner(const char *name, Oid newOwnerId)
470 {
471  Oid evtOid;
472  HeapTuple tup;
473  Form_pg_event_trigger evtForm;
474  Relation rel;
475  ObjectAddress address;
476 
477  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
478 
479  tup = SearchSysCacheCopy1(EVENTTRIGGERNAME, CStringGetDatum(name));
480 
481  if (!HeapTupleIsValid(tup))
482  ereport(ERROR,
483  (errcode(ERRCODE_UNDEFINED_OBJECT),
484  errmsg("event trigger \"%s\" does not exist", name)));
485 
486  evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
487  evtOid = evtForm->oid;
488 
489  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
490 
491  ObjectAddressSet(address, EventTriggerRelationId, evtOid);
492 
493  heap_freetuple(tup);
494 
496 
497  return address;
498 }
499 
500 /*
501  * Change event trigger owner, by OID
502  */
503 void
504 AlterEventTriggerOwner_oid(Oid trigOid, Oid newOwnerId)
505 {
506  HeapTuple tup;
507  Relation rel;
508 
509  rel = table_open(EventTriggerRelationId, RowExclusiveLock);
510 
511  tup = SearchSysCacheCopy1(EVENTTRIGGEROID, ObjectIdGetDatum(trigOid));
512 
513  if (!HeapTupleIsValid(tup))
514  ereport(ERROR,
515  (errcode(ERRCODE_UNDEFINED_OBJECT),
516  errmsg("event trigger with OID %u does not exist", trigOid)));
517 
518  AlterEventTriggerOwner_internal(rel, tup, newOwnerId);
519 
520  heap_freetuple(tup);
521 
523 }
524 
525 /*
526  * Internal workhorse for changing an event trigger's owner
527  */
528 static void
530 {
532 
533  form = (Form_pg_event_trigger) GETSTRUCT(tup);
534 
535  if (form->evtowner == newOwnerId)
536  return;
537 
538  if (!object_ownercheck(EventTriggerRelationId, form->oid, GetUserId()))
540  NameStr(form->evtname));
541 
542  /* New owner must be a superuser */
543  if (!superuser_arg(newOwnerId))
544  ereport(ERROR,
545  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
546  errmsg("permission denied to change owner of event trigger \"%s\"",
547  NameStr(form->evtname)),
548  errhint("The owner of an event trigger must be a superuser.")));
549 
550  form->evtowner = newOwnerId;
551  CatalogTupleUpdate(rel, &tup->t_self, tup);
552 
553  /* Update owner dependency reference */
554  changeDependencyOnOwner(EventTriggerRelationId,
555  form->oid,
556  newOwnerId);
557 
558  InvokeObjectPostAlterHook(EventTriggerRelationId,
559  form->oid, 0);
560 }
561 
562 /*
563  * get_event_trigger_oid - Look up an event trigger by name to find its OID.
564  *
565  * If missing_ok is false, throw an error if trigger not found. If
566  * true, just return InvalidOid.
567  */
568 Oid
569 get_event_trigger_oid(const char *trigname, bool missing_ok)
570 {
571  Oid oid;
572 
573  oid = GetSysCacheOid1(EVENTTRIGGERNAME, Anum_pg_event_trigger_oid,
574  CStringGetDatum(trigname));
575  if (!OidIsValid(oid) && !missing_ok)
576  ereport(ERROR,
577  (errcode(ERRCODE_UNDEFINED_OBJECT),
578  errmsg("event trigger \"%s\" does not exist", trigname)));
579  return oid;
580 }
581 
582 /*
583  * Return true when we want to fire given Event Trigger and false otherwise,
584  * filtering on the session replication role and the event trigger registered
585  * tags matching.
586  */
587 static bool
589 {
590  /*
591  * Filter by session replication role, knowing that we never see disabled
592  * items down here.
593  */
595  {
596  if (item->enabled == TRIGGER_FIRES_ON_ORIGIN)
597  return false;
598  }
599  else
600  {
601  if (item->enabled == TRIGGER_FIRES_ON_REPLICA)
602  return false;
603  }
604 
605  /* Filter by tags, if any were specified. */
606  if (!bms_is_empty(item->tagset) && !bms_is_member(tag, item->tagset))
607  return false;
608 
609  /* if we reach that point, we're not filtering out this item */
610  return true;
611 }
612 
613 static CommandTag
615 {
616  if (event == EVT_Login)
617  return CMDTAG_LOGIN;
618  else
619  return CreateCommandTag(parsetree);
620 }
621 
622 /*
623  * Setup for running triggers for the given event. Return value is an OID list
624  * of functions to run; if there are any, trigdata is filled with an
625  * appropriate EventTriggerData for them to receive.
626  */
627 static List *
629  EventTriggerEvent event, const char *eventstr,
630  EventTriggerData *trigdata, bool unfiltered)
631 {
632  CommandTag tag;
633  List *cachelist;
634  ListCell *lc;
635  List *runlist = NIL;
636 
637  /*
638  * We want the list of command tags for which this procedure is actually
639  * invoked to match up exactly with the list that CREATE EVENT TRIGGER
640  * accepts. This debugging cross-check will throw an error if this
641  * function is invoked for a command tag that CREATE EVENT TRIGGER won't
642  * accept. (Unfortunately, there doesn't seem to be any simple, automated
643  * way to verify that CREATE EVENT TRIGGER doesn't accept extra stuff that
644  * never reaches this control point.)
645  *
646  * If this cross-check fails for you, you probably need to either adjust
647  * standard_ProcessUtility() not to invoke event triggers for the command
648  * type in question, or you need to adjust event_trigger_ok to accept the
649  * relevant command tag.
650  */
651 #ifdef USE_ASSERT_CHECKING
652  {
653  CommandTag dbgtag;
654 
655  dbgtag = EventTriggerGetTag(parsetree, event);
656 
657  if (event == EVT_DDLCommandStart ||
658  event == EVT_DDLCommandEnd ||
659  event == EVT_SQLDrop ||
660  event == EVT_Login)
661  {
662  if (!command_tag_event_trigger_ok(dbgtag))
663  elog(ERROR, "unexpected command tag \"%s\"", GetCommandTagName(dbgtag));
664  }
665  else if (event == EVT_TableRewrite)
666  {
667  if (!command_tag_table_rewrite_ok(dbgtag))
668  elog(ERROR, "unexpected command tag \"%s\"", GetCommandTagName(dbgtag));
669  }
670  }
671 #endif
672 
673  /* Use cache to find triggers for this event; fast exit if none. */
674  cachelist = EventCacheLookup(event);
675  if (cachelist == NIL)
676  return NIL;
677 
678  /* Get the command tag. */
679  tag = EventTriggerGetTag(parsetree, event);
680 
681  /*
682  * Filter list of event triggers by command tag, and copy them into our
683  * memory context. Once we start running the command triggers, or indeed
684  * once we do anything at all that touches the catalogs, an invalidation
685  * might leave cachelist pointing at garbage, so we must do this before we
686  * can do much else.
687  */
688  foreach(lc, cachelist)
689  {
690  EventTriggerCacheItem *item = lfirst(lc);
691 
692  if (unfiltered || filter_event_trigger(tag, item))
693  {
694  /* We must plan to fire this trigger. */
695  runlist = lappend_oid(runlist, item->fnoid);
696  }
697  }
698 
699  /* don't spend any more time on this if no functions to run */
700  if (runlist == NIL)
701  return NIL;
702 
703  trigdata->type = T_EventTriggerData;
704  trigdata->event = eventstr;
705  trigdata->parsetree = parsetree;
706  trigdata->tag = tag;
707 
708  return runlist;
709 }
710 
711 /*
712  * Fire ddl_command_start triggers.
713  */
714 void
716 {
717  List *runlist;
718  EventTriggerData trigdata;
719 
720  /*
721  * Event Triggers are completely disabled in standalone mode. There are
722  * (at least) two reasons for this:
723  *
724  * 1. A sufficiently broken event trigger might not only render the
725  * database unusable, but prevent disabling itself to fix the situation.
726  * In this scenario, restarting in standalone mode provides an escape
727  * hatch.
728  *
729  * 2. BuildEventTriggerCache relies on systable_beginscan_ordered, and
730  * therefore will malfunction if pg_event_trigger's indexes are damaged.
731  * To allow recovery from a damaged index, we need some operating mode
732  * wherein event triggers are disabled. (Or we could implement
733  * heapscan-and-sort logic for that case, but having disaster recovery
734  * scenarios depend on code that's otherwise untested isn't appetizing.)
735  *
736  * Additionally, event triggers can be disabled with a superuser-only GUC
737  * to make fixing database easier as per 1 above.
738  */
740  return;
741 
742  runlist = EventTriggerCommonSetup(parsetree,
744  "ddl_command_start",
745  &trigdata, false);
746  if (runlist == NIL)
747  return;
748 
749  /* Run the triggers. */
750  EventTriggerInvoke(runlist, &trigdata);
751 
752  /* Cleanup. */
753  list_free(runlist);
754 
755  /*
756  * Make sure anything the event triggers did will be visible to the main
757  * command.
758  */
760 }
761 
762 /*
763  * Fire ddl_command_end triggers.
764  */
765 void
767 {
768  List *runlist;
769  EventTriggerData trigdata;
770 
771  /*
772  * See EventTriggerDDLCommandStart for a discussion about why event
773  * triggers are disabled in single user mode or via GUC.
774  */
776  return;
777 
778  /*
779  * Also do nothing if our state isn't set up, which it won't be if there
780  * weren't any relevant event triggers at the start of the current DDL
781  * command. This test might therefore seem optional, but it's important
782  * because EventTriggerCommonSetup might find triggers that didn't exist
783  * at the time the command started. Although this function itself
784  * wouldn't crash, the event trigger functions would presumably call
785  * pg_event_trigger_ddl_commands which would fail. Better to do nothing
786  * until the next command.
787  */
789  return;
790 
791  runlist = EventTriggerCommonSetup(parsetree,
792  EVT_DDLCommandEnd, "ddl_command_end",
793  &trigdata, false);
794  if (runlist == NIL)
795  return;
796 
797  /*
798  * Make sure anything the main command did will be visible to the event
799  * triggers.
800  */
802 
803  /* Run the triggers. */
804  EventTriggerInvoke(runlist, &trigdata);
805 
806  /* Cleanup. */
807  list_free(runlist);
808 }
809 
810 /*
811  * Fire sql_drop triggers.
812  */
813 void
815 {
816  List *runlist;
817  EventTriggerData trigdata;
818 
819  /*
820  * See EventTriggerDDLCommandStart for a discussion about why event
821  * triggers are disabled in single user mode or via a GUC.
822  */
824  return;
825 
826  /*
827  * Use current state to determine whether this event fires at all. If
828  * there are no triggers for the sql_drop event, then we don't have
829  * anything to do here. Note that dropped object collection is disabled
830  * if this is the case, so even if we were to try to run, the list would
831  * be empty.
832  */
835  return;
836 
837  runlist = EventTriggerCommonSetup(parsetree,
838  EVT_SQLDrop, "sql_drop",
839  &trigdata, false);
840 
841  /*
842  * Nothing to do if run list is empty. Note this typically can't happen,
843  * because if there are no sql_drop events, then objects-to-drop wouldn't
844  * have been collected in the first place and we would have quit above.
845  * But it could occur if event triggers were dropped partway through.
846  */
847  if (runlist == NIL)
848  return;
849 
850  /*
851  * Make sure anything the main command did will be visible to the event
852  * triggers.
853  */
855 
856  /*
857  * Make sure pg_event_trigger_dropped_objects only works when running
858  * these triggers. Use PG_TRY to ensure in_sql_drop is reset even when
859  * one trigger fails. (This is perhaps not necessary, as the currentState
860  * variable will be removed shortly by our caller, but it seems better to
861  * play safe.)
862  */
864 
865  /* Run the triggers. */
866  PG_TRY();
867  {
868  EventTriggerInvoke(runlist, &trigdata);
869  }
870  PG_FINALLY();
871  {
873  }
874  PG_END_TRY();
875 
876  /* Cleanup. */
877  list_free(runlist);
878 }
879 
880 /*
881  * Fire login event triggers if any are present. The dathasloginevt
882  * pg_database flag is left when an event trigger is dropped, to avoid
883  * complicating the codepath in the case of multiple event triggers. This
884  * function will instead unset the flag if no trigger is defined.
885  */
886 void
888 {
889  List *runlist;
890  EventTriggerData trigdata;
891 
892  /*
893  * See EventTriggerDDLCommandStart for a discussion about why event
894  * triggers are disabled in single user mode or via a GUC. We also need a
895  * database connection (some background workers doesn't have it).
896  */
899  return;
900 
902  runlist = EventTriggerCommonSetup(NULL,
903  EVT_Login, "login",
904  &trigdata, false);
905 
906  if (runlist != NIL)
907  {
908  /*
909  * Event trigger execution may require an active snapshot.
910  */
912 
913  /* Run the triggers. */
914  EventTriggerInvoke(runlist, &trigdata);
915 
916  /* Cleanup. */
917  list_free(runlist);
918 
920  }
921 
922  /*
923  * There is no active login event trigger, but our
924  * pg_database.dathasloginevt was set. Try to unset this flag. We use the
925  * lock to prevent concurrent SetDatatabaseHasLoginEventTriggers(), but we
926  * don't want to hang the connection waiting on the lock. Thus, we are
927  * just trying to acquire the lock conditionally.
928  */
929  else if (ConditionalLockSharedObject(DatabaseRelationId, MyDatabaseId,
931  {
932  /*
933  * The lock is held. Now we need to recheck that login event triggers
934  * list is still empty. Once the list is empty, we know that even if
935  * there is a backend, which concurrently inserts/enables login
936  * trigger, it will update pg_database.dathasloginevt *afterwards*.
937  */
938  runlist = EventTriggerCommonSetup(NULL,
939  EVT_Login, "login",
940  &trigdata, true);
941 
942  if (runlist == NIL)
943  {
944  Relation pg_db = table_open(DatabaseRelationId, RowExclusiveLock);
945  HeapTuple tuple;
946  Form_pg_database db;
947  ScanKeyData key[1];
948  SysScanDesc scan;
949 
950  /*
951  * Get the pg_database tuple to scribble on. Note that this does
952  * not directly rely on the syscache to avoid issues with
953  * flattened toast values for the in-place update.
954  */
955  ScanKeyInit(&key[0],
956  Anum_pg_database_oid,
957  BTEqualStrategyNumber, F_OIDEQ,
959 
960  scan = systable_beginscan(pg_db, DatabaseOidIndexId, true,
961  NULL, 1, key);
962  tuple = systable_getnext(scan);
963  tuple = heap_copytuple(tuple);
964  systable_endscan(scan);
965 
966  if (!HeapTupleIsValid(tuple))
967  elog(ERROR, "could not find tuple for database %u", MyDatabaseId);
968 
969  db = (Form_pg_database) GETSTRUCT(tuple);
970  if (db->dathasloginevt)
971  {
972  db->dathasloginevt = false;
973 
974  /*
975  * Do an "in place" update of the pg_database tuple. Doing
976  * this instead of regular updates serves two purposes. First,
977  * that avoids possible waiting on the row-level lock. Second,
978  * that avoids dealing with TOAST.
979  *
980  * It's known that changes made by heap_inplace_update() may
981  * be lost due to concurrent normal updates. However, we are
982  * OK with that. The subsequent connections will still have a
983  * chance to set "dathasloginevt" to false.
984  */
985  heap_inplace_update(pg_db, tuple);
986  }
988  heap_freetuple(tuple);
989  }
990  else
991  {
992  list_free(runlist);
993  }
994  }
996 }
997 
998 
999 /*
1000  * Fire table_rewrite triggers.
1001  */
1002 void
1003 EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
1004 {
1005  List *runlist;
1006  EventTriggerData trigdata;
1007 
1008  /*
1009  * See EventTriggerDDLCommandStart for a discussion about why event
1010  * triggers are disabled in single user mode or via a GUC.
1011  */
1013  return;
1014 
1015  /*
1016  * Also do nothing if our state isn't set up, which it won't be if there
1017  * weren't any relevant event triggers at the start of the current DDL
1018  * command. This test might therefore seem optional, but it's
1019  * *necessary*, because EventTriggerCommonSetup might find triggers that
1020  * didn't exist at the time the command started.
1021  */
1023  return;
1024 
1025  runlist = EventTriggerCommonSetup(parsetree,
1027  "table_rewrite",
1028  &trigdata, false);
1029  if (runlist == NIL)
1030  return;
1031 
1032  /*
1033  * Make sure pg_event_trigger_table_rewrite_oid only works when running
1034  * these triggers. Use PG_TRY to ensure table_rewrite_oid is reset even
1035  * when one trigger fails. (This is perhaps not necessary, as the
1036  * currentState variable will be removed shortly by our caller, but it
1037  * seems better to play safe.)
1038  */
1041 
1042  /* Run the triggers. */
1043  PG_TRY();
1044  {
1045  EventTriggerInvoke(runlist, &trigdata);
1046  }
1047  PG_FINALLY();
1048  {
1051  }
1052  PG_END_TRY();
1053 
1054  /* Cleanup. */
1055  list_free(runlist);
1056 
1057  /*
1058  * Make sure anything the event triggers did will be visible to the main
1059  * command.
1060  */
1062 }
1063 
1064 /*
1065  * Invoke each event trigger in a list of event triggers.
1066  */
1067 static void
1068 EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
1069 {
1070  MemoryContext context;
1071  MemoryContext oldcontext;
1072  ListCell *lc;
1073  bool first = true;
1074 
1075  /* Guard against stack overflow due to recursive event trigger */
1077 
1078  /*
1079  * Let's evaluate event triggers in their own memory context, so that any
1080  * leaks get cleaned up promptly.
1081  */
1083  "event trigger context",
1085  oldcontext = MemoryContextSwitchTo(context);
1086 
1087  /* Call each event trigger. */
1088  foreach(lc, fn_oid_list)
1089  {
1090  LOCAL_FCINFO(fcinfo, 0);
1091  Oid fnoid = lfirst_oid(lc);
1092  FmgrInfo flinfo;
1093  PgStat_FunctionCallUsage fcusage;
1094 
1095  elog(DEBUG1, "EventTriggerInvoke %u", fnoid);
1096 
1097  /*
1098  * We want each event trigger to be able to see the results of the
1099  * previous event trigger's action. Caller is responsible for any
1100  * command-counter increment that is needed between the event trigger
1101  * and anything else in the transaction.
1102  */
1103  if (first)
1104  first = false;
1105  else
1107 
1108  /* Look up the function */
1109  fmgr_info(fnoid, &flinfo);
1110 
1111  /* Call the function, passing no arguments but setting a context. */
1112  InitFunctionCallInfoData(*fcinfo, &flinfo, 0,
1113  InvalidOid, (Node *) trigdata, NULL);
1114  pgstat_init_function_usage(fcinfo, &fcusage);
1115  FunctionCallInvoke(fcinfo);
1116  pgstat_end_function_usage(&fcusage, true);
1117 
1118  /* Reclaim memory. */
1119  MemoryContextReset(context);
1120  }
1121 
1122  /* Restore old memory context and delete the temporary one. */
1123  MemoryContextSwitchTo(oldcontext);
1124  MemoryContextDelete(context);
1125 }
1126 
1127 /*
1128  * Do event triggers support this object type?
1129  */
1130 bool
1132 {
1133  switch (obtype)
1134  {
1135  case OBJECT_DATABASE:
1136  case OBJECT_TABLESPACE:
1137  case OBJECT_ROLE:
1138  case OBJECT_PARAMETER_ACL:
1139  /* no support for global objects */
1140  return false;
1141  case OBJECT_EVENT_TRIGGER:
1142  /* no support for event triggers on event triggers */
1143  return false;
1144  case OBJECT_ACCESS_METHOD:
1145  case OBJECT_AGGREGATE:
1146  case OBJECT_AMOP:
1147  case OBJECT_AMPROC:
1148  case OBJECT_ATTRIBUTE:
1149  case OBJECT_CAST:
1150  case OBJECT_COLUMN:
1151  case OBJECT_COLLATION:
1152  case OBJECT_CONVERSION:
1153  case OBJECT_DEFACL:
1154  case OBJECT_DEFAULT:
1155  case OBJECT_DOMAIN:
1156  case OBJECT_DOMCONSTRAINT:
1157  case OBJECT_EXTENSION:
1158  case OBJECT_FDW:
1159  case OBJECT_FOREIGN_SERVER:
1160  case OBJECT_FOREIGN_TABLE:
1161  case OBJECT_FUNCTION:
1162  case OBJECT_INDEX:
1163  case OBJECT_LANGUAGE:
1164  case OBJECT_LARGEOBJECT:
1165  case OBJECT_MATVIEW:
1166  case OBJECT_OPCLASS:
1167  case OBJECT_OPERATOR:
1168  case OBJECT_OPFAMILY:
1169  case OBJECT_POLICY:
1170  case OBJECT_PROCEDURE:
1171  case OBJECT_PUBLICATION:
1174  case OBJECT_ROUTINE:
1175  case OBJECT_RULE:
1176  case OBJECT_SCHEMA:
1177  case OBJECT_SEQUENCE:
1178  case OBJECT_SUBSCRIPTION:
1179  case OBJECT_STATISTIC_EXT:
1180  case OBJECT_TABCONSTRAINT:
1181  case OBJECT_TABLE:
1182  case OBJECT_TRANSFORM:
1183  case OBJECT_TRIGGER:
1185  case OBJECT_TSDICTIONARY:
1186  case OBJECT_TSPARSER:
1187  case OBJECT_TSTEMPLATE:
1188  case OBJECT_TYPE:
1189  case OBJECT_USER_MAPPING:
1190  case OBJECT_VIEW:
1191  return true;
1192 
1193  /*
1194  * There's intentionally no default: case here; we want the
1195  * compiler to warn if a new ObjectType hasn't been handled above.
1196  */
1197  }
1198 
1199  /* Shouldn't get here, but if we do, say "no support" */
1200  return false;
1201 }
1202 
1203 /*
1204  * Do event triggers support this object class?
1205  */
1206 bool
1208 {
1209  switch (objclass)
1210  {
1211  case OCLASS_DATABASE:
1212  case OCLASS_TBLSPACE:
1213  case OCLASS_ROLE:
1215  case OCLASS_PARAMETER_ACL:
1216  /* no support for global objects */
1217  return false;
1218  case OCLASS_EVENT_TRIGGER:
1219  /* no support for event triggers on event triggers */
1220  return false;
1221  case OCLASS_CLASS:
1222  case OCLASS_PROC:
1223  case OCLASS_TYPE:
1224  case OCLASS_CAST:
1225  case OCLASS_COLLATION:
1226  case OCLASS_CONSTRAINT:
1227  case OCLASS_CONVERSION:
1228  case OCLASS_DEFAULT:
1229  case OCLASS_LANGUAGE:
1230  case OCLASS_LARGEOBJECT:
1231  case OCLASS_OPERATOR:
1232  case OCLASS_OPCLASS:
1233  case OCLASS_OPFAMILY:
1234  case OCLASS_AM:
1235  case OCLASS_AMOP:
1236  case OCLASS_AMPROC:
1237  case OCLASS_REWRITE:
1238  case OCLASS_TRIGGER:
1239  case OCLASS_SCHEMA:
1240  case OCLASS_STATISTIC_EXT:
1241  case OCLASS_TSPARSER:
1242  case OCLASS_TSDICT:
1243  case OCLASS_TSTEMPLATE:
1244  case OCLASS_TSCONFIG:
1245  case OCLASS_FDW:
1246  case OCLASS_FOREIGN_SERVER:
1247  case OCLASS_USER_MAPPING:
1248  case OCLASS_DEFACL:
1249  case OCLASS_EXTENSION:
1250  case OCLASS_POLICY:
1251  case OCLASS_PUBLICATION:
1254  case OCLASS_SUBSCRIPTION:
1255  case OCLASS_TRANSFORM:
1256  return true;
1257 
1258  /*
1259  * There's intentionally no default: case here; we want the
1260  * compiler to warn if a new OCLASS hasn't been handled above.
1261  */
1262  }
1263 
1264  /* Shouldn't get here, but if we do, say "no support" */
1265  return false;
1266 }
1267 
1268 /*
1269  * Prepare event trigger state for a new complete query to run, if necessary;
1270  * returns whether this was done. If it was, EventTriggerEndCompleteQuery must
1271  * be called when the query is done, regardless of whether it succeeds or fails
1272  * -- so use of a PG_TRY block is mandatory.
1273  */
1274 bool
1276 {
1278  MemoryContext cxt;
1279 
1280  /*
1281  * Currently, sql_drop, table_rewrite, ddl_command_end events are the only
1282  * reason to have event trigger state at all; so if there are none, don't
1283  * install one.
1284  */
1286  return false;
1287 
1289  "event trigger state",
1292  state->cxt = cxt;
1293  slist_init(&(state->SQLDropList));
1294  state->in_sql_drop = false;
1295  state->table_rewrite_oid = InvalidOid;
1296 
1297  state->commandCollectionInhibited = currentEventTriggerState ?
1299  state->currentCommand = NULL;
1300  state->commandList = NIL;
1301  state->previous = currentEventTriggerState;
1303 
1304  return true;
1305 }
1306 
1307 /*
1308  * Query completed (or errored out) -- clean up local state, return to previous
1309  * one.
1310  *
1311  * Note: it's an error to call this routine if EventTriggerBeginCompleteQuery
1312  * returned false previously.
1313  *
1314  * Note: this might be called in the PG_CATCH block of a failing transaction,
1315  * so be wary of running anything unnecessary. (In particular, it's probably
1316  * unwise to try to allocate memory.)
1317  */
1318 void
1320 {
1321  EventTriggerQueryState *prevstate;
1322 
1323  prevstate = currentEventTriggerState->previous;
1324 
1325  /* this avoids the need for retail pfree of SQLDropList items: */
1327 
1328  currentEventTriggerState = prevstate;
1329 }
1330 
1331 /*
1332  * Do we need to keep close track of objects being dropped?
1333  *
1334  * This is useful because there is a cost to running with them enabled.
1335  */
1336 bool
1338 {
1339  /*
1340  * true if any sql_drop, table_rewrite, ddl_command_end event trigger
1341  * exists
1342  */
1343  return (EventCacheLookup(EVT_SQLDrop) != NIL) ||
1346 }
1347 
1348 /*
1349  * Support for dropped objects information on event trigger functions.
1350  *
1351  * We keep the list of objects dropped by the current command in current
1352  * state's SQLDropList (comprising SQLDropObject items). Each time a new
1353  * command is to start, a clean EventTriggerQueryState is created; commands
1354  * that drop objects do the dependency.c dance to drop objects, which
1355  * populates the current state's SQLDropList; when the event triggers are
1356  * invoked they can consume the list via pg_event_trigger_dropped_objects().
1357  * When the command finishes, the EventTriggerQueryState is cleared, and
1358  * the one from the previous command is restored (when no command is in
1359  * execution, the current state is NULL).
1360  *
1361  * All this lets us support the case that an event trigger function drops
1362  * objects "reentrantly".
1363  */
1364 
1365 /*
1366  * Register one object as being dropped by the current command.
1367  */
1368 void
1369 EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool normal)
1370 {
1371  SQLDropObject *obj;
1372  MemoryContext oldcxt;
1373 
1375  return;
1376 
1378 
1379  /* don't report temp schemas except my own */
1380  if (object->classId == NamespaceRelationId &&
1381  (isAnyTempNamespace(object->objectId) &&
1382  !isTempNamespace(object->objectId)))
1383  return;
1384 
1386 
1387  obj = palloc0(sizeof(SQLDropObject));
1388  obj->address = *object;
1389  obj->original = original;
1390  obj->normal = normal;
1391 
1392  /*
1393  * Obtain schema names from the object's catalog tuple, if one exists;
1394  * this lets us skip objects in temp schemas. We trust that
1395  * ObjectProperty contains all object classes that can be
1396  * schema-qualified.
1397  */
1398  if (is_objectclass_supported(object->classId))
1399  {
1400  Relation catalog;
1401  HeapTuple tuple;
1402 
1403  catalog = table_open(obj->address.classId, AccessShareLock);
1404  tuple = get_catalog_object_by_oid(catalog,
1405  get_object_attnum_oid(object->classId),
1406  obj->address.objectId);
1407 
1408  if (tuple)
1409  {
1411  Datum datum;
1412  bool isnull;
1413 
1415  if (attnum != InvalidAttrNumber)
1416  {
1417  datum = heap_getattr(tuple, attnum,
1418  RelationGetDescr(catalog), &isnull);
1419  if (!isnull)
1420  {
1421  Oid namespaceId;
1422 
1423  namespaceId = DatumGetObjectId(datum);
1424  /* temp objects are only reported if they are my own */
1425  if (isTempNamespace(namespaceId))
1426  {
1427  obj->schemaname = "pg_temp";
1428  obj->istemp = true;
1429  }
1430  else if (isAnyTempNamespace(namespaceId))
1431  {
1432  pfree(obj);
1433  table_close(catalog, AccessShareLock);
1434  MemoryContextSwitchTo(oldcxt);
1435  return;
1436  }
1437  else
1438  {
1439  obj->schemaname = get_namespace_name(namespaceId);
1440  obj->istemp = false;
1441  }
1442  }
1443  }
1444 
1446  obj->address.objectSubId == 0)
1447  {
1449  if (attnum != InvalidAttrNumber)
1450  {
1451  datum = heap_getattr(tuple, attnum,
1452  RelationGetDescr(catalog), &isnull);
1453  if (!isnull)
1454  obj->objname = pstrdup(NameStr(*DatumGetName(datum)));
1455  }
1456  }
1457  }
1458 
1459  table_close(catalog, AccessShareLock);
1460  }
1461  else
1462  {
1463  if (object->classId == NamespaceRelationId &&
1464  isTempNamespace(object->objectId))
1465  obj->istemp = true;
1466  }
1467 
1468  /* object identity, objname and objargs */
1469  obj->objidentity =
1470  getObjectIdentityParts(&obj->address, &obj->addrnames, &obj->addrargs,
1471  false);
1472 
1473  /* object type */
1474  obj->objecttype = getObjectTypeDescription(&obj->address, false);
1475 
1477 
1478  MemoryContextSwitchTo(oldcxt);
1479 }
1480 
1481 /*
1482  * pg_event_trigger_dropped_objects
1483  *
1484  * Make the list of dropped objects available to the user function run by the
1485  * Event Trigger.
1486  */
1487 Datum
1489 {
1490  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
1491  slist_iter iter;
1492 
1493  /*
1494  * Protect this function from being called out of context
1495  */
1498  ereport(ERROR,
1499  (errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1500  errmsg("%s can only be called in a sql_drop event trigger function",
1501  "pg_event_trigger_dropped_objects()")));
1502 
1503  /* Build tuplestore to hold the result rows */
1504  InitMaterializedSRF(fcinfo, 0);
1505 
1507  {
1508  SQLDropObject *obj;
1509  int i = 0;
1510  Datum values[12] = {0};
1511  bool nulls[12] = {0};
1512 
1513  obj = slist_container(SQLDropObject, next, iter.cur);
1514 
1515  /* classid */
1517 
1518  /* objid */
1520 
1521  /* objsubid */
1523 
1524  /* original */
1525  values[i++] = BoolGetDatum(obj->original);
1526 
1527  /* normal */
1528  values[i++] = BoolGetDatum(obj->normal);
1529 
1530  /* is_temporary */
1531  values[i++] = BoolGetDatum(obj->istemp);
1532 
1533  /* object_type */
1535 
1536  /* schema_name */
1537  if (obj->schemaname)
1539  else
1540  nulls[i++] = true;
1541 
1542  /* object_name */
1543  if (obj->objname)
1544  values[i++] = CStringGetTextDatum(obj->objname);
1545  else
1546  nulls[i++] = true;
1547 
1548  /* object_identity */
1549  if (obj->objidentity)
1551  else
1552  nulls[i++] = true;
1553 
1554  /* address_names and address_args */
1555  if (obj->addrnames)
1556  {
1558 
1559  if (obj->addrargs)
1561  else
1563  }
1564  else
1565  {
1566  nulls[i++] = true;
1567  nulls[i++] = true;
1568  }
1569 
1570  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
1571  values, nulls);
1572  }
1573 
1574  return (Datum) 0;
1575 }
1576 
1577 /*
1578  * pg_event_trigger_table_rewrite_oid
1579  *
1580  * Make the Oid of the table going to be rewritten available to the user
1581  * function run by the Event Trigger.
1582  */
1583 Datum
1585 {
1586  /*
1587  * Protect this function from being called out of context
1588  */
1589  if (!currentEventTriggerState ||
1591  ereport(ERROR,
1592  (errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1593  errmsg("%s can only be called in a table_rewrite event trigger function",
1594  "pg_event_trigger_table_rewrite_oid()")));
1595 
1597 }
1598 
1599 /*
1600  * pg_event_trigger_table_rewrite_reason
1601  *
1602  * Make the rewrite reason available to the user.
1603  */
1604 Datum
1606 {
1607  /*
1608  * Protect this function from being called out of context
1609  */
1610  if (!currentEventTriggerState ||
1612  ereport(ERROR,
1613  (errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
1614  errmsg("%s can only be called in a table_rewrite event trigger function",
1615  "pg_event_trigger_table_rewrite_reason()")));
1616 
1618 }
1619 
1620 /*-------------------------------------------------------------------------
1621  * Support for DDL command deparsing
1622  *
1623  * The routines below enable an event trigger function to obtain a list of
1624  * DDL commands as they are executed. There are three main pieces to this
1625  * feature:
1626  *
1627  * 1) Within ProcessUtilitySlow, or some sub-routine thereof, each DDL command
1628  * adds a struct CollectedCommand representation of itself to the command list,
1629  * using the routines below.
1630  *
1631  * 2) Some time after that, ddl_command_end fires and the command list is made
1632  * available to the event trigger function via pg_event_trigger_ddl_commands();
1633  * the complete command details are exposed as a column of type pg_ddl_command.
1634  *
1635  * 3) An extension can install a function capable of taking a value of type
1636  * pg_ddl_command and transform it into some external, user-visible and/or
1637  * -modifiable representation.
1638  *-------------------------------------------------------------------------
1639  */
1640 
1641 /*
1642  * Inhibit DDL command collection.
1643  */
1644 void
1646 {
1648  return;
1649 
1651 }
1652 
1653 /*
1654  * Re-establish DDL command collection.
1655  */
1656 void
1658 {
1660  return;
1661 
1663 }
1664 
1665 /*
1666  * EventTriggerCollectSimpleCommand
1667  * Save data about a simple DDL command that was just executed
1668  *
1669  * address identifies the object being operated on. secondaryObject is an
1670  * object address that was related in some way to the executed command; its
1671  * meaning is command-specific.
1672  *
1673  * For instance, for an ALTER obj SET SCHEMA command, objtype is the type of
1674  * object being moved, objectId is its OID, and secondaryOid is the OID of the
1675  * old schema. (The destination schema OID can be obtained by catalog lookup
1676  * of the object.)
1677  */
1678 void
1680  ObjectAddress secondaryObject,
1681  Node *parsetree)
1682 {
1683  MemoryContext oldcxt;
1684  CollectedCommand *command;
1685 
1686  /* ignore if event trigger context not set, or collection disabled */
1687  if (!currentEventTriggerState ||
1689  return;
1690 
1692 
1693  command = palloc(sizeof(CollectedCommand));
1694 
1695  command->type = SCT_Simple;
1696  command->in_extension = creating_extension;
1697 
1698  command->d.simple.address = address;
1699  command->d.simple.secondaryObject = secondaryObject;
1700  command->parsetree = copyObject(parsetree);
1701 
1703  command);
1704 
1705  MemoryContextSwitchTo(oldcxt);
1706 }
1707 
1708 /*
1709  * EventTriggerAlterTableStart
1710  * Prepare to receive data on an ALTER TABLE command about to be executed
1711  *
1712  * Note we don't collect the command immediately; instead we keep it in
1713  * currentCommand, and only when we're done processing the subcommands we will
1714  * add it to the command list.
1715  */
1716 void
1718 {
1719  MemoryContext oldcxt;
1720  CollectedCommand *command;
1721 
1722  /* ignore if event trigger context not set, or collection disabled */
1723  if (!currentEventTriggerState ||
1725  return;
1726 
1728 
1729  command = palloc(sizeof(CollectedCommand));
1730 
1731  command->type = SCT_AlterTable;
1732  command->in_extension = creating_extension;
1733 
1734  command->d.alterTable.classId = RelationRelationId;
1735  command->d.alterTable.objectId = InvalidOid;
1736  command->d.alterTable.subcmds = NIL;
1737  command->parsetree = copyObject(parsetree);
1738 
1741 
1742  MemoryContextSwitchTo(oldcxt);
1743 }
1744 
1745 /*
1746  * Remember the OID of the object being affected by an ALTER TABLE.
1747  *
1748  * This is needed because in some cases we don't know the OID until later.
1749  */
1750 void
1752 {
1753  if (!currentEventTriggerState ||
1755  return;
1756 
1757  currentEventTriggerState->currentCommand->d.alterTable.objectId = objectId;
1758 }
1759 
1760 /*
1761  * EventTriggerCollectAlterTableSubcmd
1762  * Save data about a single part of an ALTER TABLE.
1763  *
1764  * Several different commands go through this path, but apart from ALTER TABLE
1765  * itself, they are all concerned with AlterTableCmd nodes that are generated
1766  * internally, so that's all that this code needs to handle at the moment.
1767  */
1768 void
1770 {
1771  MemoryContext oldcxt;
1773 
1774  /* ignore if event trigger context not set, or collection disabled */
1775  if (!currentEventTriggerState ||
1777  return;
1778 
1779  Assert(IsA(subcmd, AlterTableCmd));
1782 
1784 
1785  newsub = palloc(sizeof(CollectedATSubcmd));
1786  newsub->address = address;
1787  newsub->parsetree = copyObject(subcmd);
1788 
1791 
1792  MemoryContextSwitchTo(oldcxt);
1793 }
1794 
1795 /*
1796  * EventTriggerAlterTableEnd
1797  * Finish up saving an ALTER TABLE command, and add it to command list.
1798  *
1799  * FIXME this API isn't considering the possibility that an xact/subxact is
1800  * aborted partway through. Probably it's best to add an
1801  * AtEOSubXact_EventTriggers() to fix this.
1802  */
1803 void
1805 {
1806  CollectedCommand *parent;
1807 
1808  /* ignore if event trigger context not set, or collection disabled */
1809  if (!currentEventTriggerState ||
1811  return;
1812 
1814 
1815  /* If no subcommands, don't collect */
1817  {
1818  MemoryContext oldcxt;
1819 
1821 
1825 
1826  MemoryContextSwitchTo(oldcxt);
1827  }
1828  else
1830 
1832 }
1833 
1834 /*
1835  * EventTriggerCollectGrant
1836  * Save data about a GRANT/REVOKE command being executed
1837  *
1838  * This function creates a copy of the InternalGrant, as the original might
1839  * not have the right lifetime.
1840  */
1841 void
1843 {
1844  MemoryContext oldcxt;
1845  CollectedCommand *command;
1846  InternalGrant *icopy;
1847  ListCell *cell;
1848 
1849  /* ignore if event trigger context not set, or collection disabled */
1850  if (!currentEventTriggerState ||
1852  return;
1853 
1855 
1856  /*
1857  * This is tedious, but necessary.
1858  */
1859  icopy = palloc(sizeof(InternalGrant));
1860  memcpy(icopy, istmt, sizeof(InternalGrant));
1861  icopy->objects = list_copy(istmt->objects);
1862  icopy->grantees = list_copy(istmt->grantees);
1863  icopy->col_privs = NIL;
1864  foreach(cell, istmt->col_privs)
1865  icopy->col_privs = lappend(icopy->col_privs, copyObject(lfirst(cell)));
1866 
1867  /* Now collect it, using the copied InternalGrant */
1868  command = palloc(sizeof(CollectedCommand));
1869  command->type = SCT_Grant;
1870  command->in_extension = creating_extension;
1871  command->d.grant.istmt = icopy;
1872  command->parsetree = NULL;
1873 
1876 
1877  MemoryContextSwitchTo(oldcxt);
1878 }
1879 
1880 /*
1881  * EventTriggerCollectAlterOpFam
1882  * Save data about an ALTER OPERATOR FAMILY ADD/DROP command being
1883  * executed
1884  */
1885 void
1887  List *operators, List *procedures)
1888 {
1889  MemoryContext oldcxt;
1890  CollectedCommand *command;
1891 
1892  /* ignore if event trigger context not set, or collection disabled */
1893  if (!currentEventTriggerState ||
1895  return;
1896 
1898 
1899  command = palloc(sizeof(CollectedCommand));
1900  command->type = SCT_AlterOpFamily;
1901  command->in_extension = creating_extension;
1902  ObjectAddressSet(command->d.opfam.address,
1903  OperatorFamilyRelationId, opfamoid);
1904  command->d.opfam.operators = operators;
1905  command->d.opfam.procedures = procedures;
1906  command->parsetree = (Node *) copyObject(stmt);
1907 
1910 
1911  MemoryContextSwitchTo(oldcxt);
1912 }
1913 
1914 /*
1915  * EventTriggerCollectCreateOpClass
1916  * Save data about a CREATE OPERATOR CLASS command being executed
1917  */
1918 void
1920  List *operators, List *procedures)
1921 {
1922  MemoryContext oldcxt;
1923  CollectedCommand *command;
1924 
1925  /* ignore if event trigger context not set, or collection disabled */
1926  if (!currentEventTriggerState ||
1928  return;
1929 
1931 
1932  command = palloc0(sizeof(CollectedCommand));
1933  command->type = SCT_CreateOpClass;
1934  command->in_extension = creating_extension;
1935  ObjectAddressSet(command->d.createopc.address,
1936  OperatorClassRelationId, opcoid);
1937  command->d.createopc.operators = operators;
1938  command->d.createopc.procedures = procedures;
1939  command->parsetree = (Node *) copyObject(stmt);
1940 
1943 
1944  MemoryContextSwitchTo(oldcxt);
1945 }
1946 
1947 /*
1948  * EventTriggerCollectAlterTSConfig
1949  * Save data about an ALTER TEXT SEARCH CONFIGURATION command being
1950  * executed
1951  */
1952 void
1954  Oid *dictIds, int ndicts)
1955 {
1956  MemoryContext oldcxt;
1957  CollectedCommand *command;
1958 
1959  /* ignore if event trigger context not set, or collection disabled */
1960  if (!currentEventTriggerState ||
1962  return;
1963 
1965 
1966  command = palloc0(sizeof(CollectedCommand));
1967  command->type = SCT_AlterTSConfig;
1968  command->in_extension = creating_extension;
1969  ObjectAddressSet(command->d.atscfg.address,
1970  TSConfigRelationId, cfgId);
1971  command->d.atscfg.dictIds = palloc(sizeof(Oid) * ndicts);
1972  memcpy(command->d.atscfg.dictIds, dictIds, sizeof(Oid) * ndicts);
1973  command->d.atscfg.ndicts = ndicts;
1974  command->parsetree = (Node *) copyObject(stmt);
1975 
1978 
1979  MemoryContextSwitchTo(oldcxt);
1980 }
1981 
1982 /*
1983  * EventTriggerCollectAlterDefPrivs
1984  * Save data about an ALTER DEFAULT PRIVILEGES command being
1985  * executed
1986  */
1987 void
1989 {
1990  MemoryContext oldcxt;
1991  CollectedCommand *command;
1992 
1993  /* ignore if event trigger context not set, or collection disabled */
1994  if (!currentEventTriggerState ||
1996  return;
1997 
1999 
2000  command = palloc0(sizeof(CollectedCommand));
2001  command->type = SCT_AlterDefaultPrivileges;
2002  command->d.defprivs.objtype = stmt->action->objtype;
2003  command->in_extension = creating_extension;
2004  command->parsetree = (Node *) copyObject(stmt);
2005 
2008  MemoryContextSwitchTo(oldcxt);
2009 }
2010 
2011 /*
2012  * In a ddl_command_end event trigger, this function reports the DDL commands
2013  * being run.
2014  */
2015 Datum
2017 {
2018  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
2019  ListCell *lc;
2020 
2021  /*
2022  * Protect this function from being called out of context
2023  */
2025  ereport(ERROR,
2026  (errcode(ERRCODE_E_R_I_E_EVENT_TRIGGER_PROTOCOL_VIOLATED),
2027  errmsg("%s can only be called in an event trigger function",
2028  "pg_event_trigger_ddl_commands()")));
2029 
2030  /* Build tuplestore to hold the result rows */
2031  InitMaterializedSRF(fcinfo, 0);
2032 
2034  {
2035  CollectedCommand *cmd = lfirst(lc);
2036  Datum values[9];
2037  bool nulls[9] = {0};
2038  ObjectAddress addr;
2039  int i = 0;
2040 
2041  /*
2042  * For IF NOT EXISTS commands that attempt to create an existing
2043  * object, the returned OID is Invalid. Don't return anything.
2044  *
2045  * One might think that a viable alternative would be to look up the
2046  * Oid of the existing object and run the deparse with that. But
2047  * since the parse tree might be different from the one that created
2048  * the object in the first place, we might not end up in a consistent
2049  * state anyway.
2050  */
2051  if (cmd->type == SCT_Simple &&
2052  !OidIsValid(cmd->d.simple.address.objectId))
2053  continue;
2054 
2055  switch (cmd->type)
2056  {
2057  case SCT_Simple:
2058  case SCT_AlterTable:
2059  case SCT_AlterOpFamily:
2060  case SCT_CreateOpClass:
2061  case SCT_AlterTSConfig:
2062  {
2063  char *identity;
2064  char *type;
2065  char *schema = NULL;
2066 
2067  if (cmd->type == SCT_Simple)
2068  addr = cmd->d.simple.address;
2069  else if (cmd->type == SCT_AlterTable)
2070  ObjectAddressSet(addr,
2071  cmd->d.alterTable.classId,
2072  cmd->d.alterTable.objectId);
2073  else if (cmd->type == SCT_AlterOpFamily)
2074  addr = cmd->d.opfam.address;
2075  else if (cmd->type == SCT_CreateOpClass)
2076  addr = cmd->d.createopc.address;
2077  else if (cmd->type == SCT_AlterTSConfig)
2078  addr = cmd->d.atscfg.address;
2079 
2080  /*
2081  * If an object was dropped in the same command we may end
2082  * up in a situation where we generated a message but can
2083  * no longer look for the object information, so skip it
2084  * rather than failing. This can happen for example with
2085  * some subcommand combinations of ALTER TABLE.
2086  */
2087  identity = getObjectIdentity(&addr, true);
2088  if (identity == NULL)
2089  continue;
2090 
2091  /* The type can never be NULL. */
2092  type = getObjectTypeDescription(&addr, true);
2093 
2094  /*
2095  * Obtain schema name, if any ("pg_temp" if a temp
2096  * object). If the object class is not in the supported
2097  * list here, we assume it's a schema-less object type,
2098  * and thus "schema" remains set to NULL.
2099  */
2101  {
2102  AttrNumber nspAttnum;
2103 
2104  nspAttnum = get_object_attnum_namespace(addr.classId);
2105  if (nspAttnum != InvalidAttrNumber)
2106  {
2107  Relation catalog;
2108  HeapTuple objtup;
2109  Oid schema_oid;
2110  bool isnull;
2111 
2112  catalog = table_open(addr.classId, AccessShareLock);
2113  objtup = get_catalog_object_by_oid(catalog,
2115  addr.objectId);
2116  if (!HeapTupleIsValid(objtup))
2117  elog(ERROR, "cache lookup failed for object %u/%u",
2118  addr.classId, addr.objectId);
2119  schema_oid =
2120  heap_getattr(objtup, nspAttnum,
2121  RelationGetDescr(catalog), &isnull);
2122  if (isnull)
2123  elog(ERROR,
2124  "invalid null namespace in object %u/%u/%d",
2125  addr.classId, addr.objectId, addr.objectSubId);
2126  schema = get_namespace_name_or_temp(schema_oid);
2127 
2128  table_close(catalog, AccessShareLock);
2129  }
2130  }
2131 
2132  /* classid */
2133  values[i++] = ObjectIdGetDatum(addr.classId);
2134  /* objid */
2135  values[i++] = ObjectIdGetDatum(addr.objectId);
2136  /* objsubid */
2137  values[i++] = Int32GetDatum(addr.objectSubId);
2138  /* command tag */
2140  /* object_type */
2142  /* schema */
2143  if (schema == NULL)
2144  nulls[i++] = true;
2145  else
2146  values[i++] = CStringGetTextDatum(schema);
2147  /* identity */
2148  values[i++] = CStringGetTextDatum(identity);
2149  /* in_extension */
2150  values[i++] = BoolGetDatum(cmd->in_extension);
2151  /* command */
2152  values[i++] = PointerGetDatum(cmd);
2153  }
2154  break;
2155 
2157  /* classid */
2158  nulls[i++] = true;
2159  /* objid */
2160  nulls[i++] = true;
2161  /* objsubid */
2162  nulls[i++] = true;
2163  /* command tag */
2165  /* object_type */
2167  /* schema */
2168  nulls[i++] = true;
2169  /* identity */
2170  nulls[i++] = true;
2171  /* in_extension */
2172  values[i++] = BoolGetDatum(cmd->in_extension);
2173  /* command */
2174  values[i++] = PointerGetDatum(cmd);
2175  break;
2176 
2177  case SCT_Grant:
2178  /* classid */
2179  nulls[i++] = true;
2180  /* objid */
2181  nulls[i++] = true;
2182  /* objsubid */
2183  nulls[i++] = true;
2184  /* command tag */
2185  values[i++] = CStringGetTextDatum(cmd->d.grant.istmt->is_grant ?
2186  "GRANT" : "REVOKE");
2187  /* object_type */
2188  values[i++] = CStringGetTextDatum(stringify_grant_objtype(cmd->d.grant.istmt->objtype));
2189  /* schema */
2190  nulls[i++] = true;
2191  /* identity */
2192  nulls[i++] = true;
2193  /* in_extension */
2194  values[i++] = BoolGetDatum(cmd->in_extension);
2195  /* command */
2196  values[i++] = PointerGetDatum(cmd);
2197  break;
2198  }
2199 
2200  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc,
2201  values, nulls);
2202  }
2203 
2204  PG_RETURN_VOID();
2205 }
2206 
2207 /*
2208  * Return the ObjectType as a string, as it would appear in GRANT and
2209  * REVOKE commands.
2210  */
2211 static const char *
2213 {
2214  switch (objtype)
2215  {
2216  case OBJECT_COLUMN:
2217  return "COLUMN";
2218  case OBJECT_TABLE:
2219  return "TABLE";
2220  case OBJECT_SEQUENCE:
2221  return "SEQUENCE";
2222  case OBJECT_DATABASE:
2223  return "DATABASE";
2224  case OBJECT_DOMAIN:
2225  return "DOMAIN";
2226  case OBJECT_FDW:
2227  return "FOREIGN DATA WRAPPER";
2228  case OBJECT_FOREIGN_SERVER:
2229  return "FOREIGN SERVER";
2230  case OBJECT_FUNCTION:
2231  return "FUNCTION";
2232  case OBJECT_LANGUAGE:
2233  return "LANGUAGE";
2234  case OBJECT_LARGEOBJECT:
2235  return "LARGE OBJECT";
2236  case OBJECT_SCHEMA:
2237  return "SCHEMA";
2238  case OBJECT_PARAMETER_ACL:
2239  return "PARAMETER";
2240  case OBJECT_PROCEDURE:
2241  return "PROCEDURE";
2242  case OBJECT_ROUTINE:
2243  return "ROUTINE";
2244  case OBJECT_TABLESPACE:
2245  return "TABLESPACE";
2246  case OBJECT_TYPE:
2247  return "TYPE";
2248  /* these currently aren't used */
2249  case OBJECT_ACCESS_METHOD:
2250  case OBJECT_AGGREGATE:
2251  case OBJECT_AMOP:
2252  case OBJECT_AMPROC:
2253  case OBJECT_ATTRIBUTE:
2254  case OBJECT_CAST:
2255  case OBJECT_COLLATION:
2256  case OBJECT_CONVERSION:
2257  case OBJECT_DEFAULT:
2258  case OBJECT_DEFACL:
2259  case OBJECT_DOMCONSTRAINT:
2260  case OBJECT_EVENT_TRIGGER:
2261  case OBJECT_EXTENSION:
2262  case OBJECT_FOREIGN_TABLE:
2263  case OBJECT_INDEX:
2264  case OBJECT_MATVIEW:
2265  case OBJECT_OPCLASS:
2266  case OBJECT_OPERATOR:
2267  case OBJECT_OPFAMILY:
2268  case OBJECT_POLICY:
2269  case OBJECT_PUBLICATION:
2272  case OBJECT_ROLE:
2273  case OBJECT_RULE:
2274  case OBJECT_STATISTIC_EXT:
2275  case OBJECT_SUBSCRIPTION:
2276  case OBJECT_TABCONSTRAINT:
2277  case OBJECT_TRANSFORM:
2278  case OBJECT_TRIGGER:
2280  case OBJECT_TSDICTIONARY:
2281  case OBJECT_TSPARSER:
2282  case OBJECT_TSTEMPLATE:
2283  case OBJECT_USER_MAPPING:
2284  case OBJECT_VIEW:
2285  elog(ERROR, "unsupported object type: %d", (int) objtype);
2286  }
2287 
2288  return "???"; /* keep compiler quiet */
2289 }
2290 
2291 /*
2292  * Return the ObjectType as a string; as above, but use the spelling
2293  * in ALTER DEFAULT PRIVILEGES commands instead. Generally this is just
2294  * the plural.
2295  */
2296 static const char *
2298 {
2299  switch (objtype)
2300  {
2301  case OBJECT_COLUMN:
2302  return "COLUMNS";
2303  case OBJECT_TABLE:
2304  return "TABLES";
2305  case OBJECT_SEQUENCE:
2306  return "SEQUENCES";
2307  case OBJECT_DATABASE:
2308  return "DATABASES";
2309  case OBJECT_DOMAIN:
2310  return "DOMAINS";
2311  case OBJECT_FDW:
2312  return "FOREIGN DATA WRAPPERS";
2313  case OBJECT_FOREIGN_SERVER:
2314  return "FOREIGN SERVERS";
2315  case OBJECT_FUNCTION:
2316  return "FUNCTIONS";
2317  case OBJECT_LANGUAGE:
2318  return "LANGUAGES";
2319  case OBJECT_LARGEOBJECT:
2320  return "LARGE OBJECTS";
2321  case OBJECT_SCHEMA:
2322  return "SCHEMAS";
2323  case OBJECT_PROCEDURE:
2324  return "PROCEDURES";
2325  case OBJECT_ROUTINE:
2326  return "ROUTINES";
2327  case OBJECT_TABLESPACE:
2328  return "TABLESPACES";
2329  case OBJECT_TYPE:
2330  return "TYPES";
2331  /* these currently aren't used */
2332  case OBJECT_ACCESS_METHOD:
2333  case OBJECT_AGGREGATE:
2334  case OBJECT_AMOP:
2335  case OBJECT_AMPROC:
2336  case OBJECT_ATTRIBUTE:
2337  case OBJECT_CAST:
2338  case OBJECT_COLLATION:
2339  case OBJECT_CONVERSION:
2340  case OBJECT_DEFAULT:
2341  case OBJECT_DEFACL:
2342  case OBJECT_DOMCONSTRAINT:
2343  case OBJECT_EVENT_TRIGGER:
2344  case OBJECT_EXTENSION:
2345  case OBJECT_FOREIGN_TABLE:
2346  case OBJECT_INDEX:
2347  case OBJECT_MATVIEW:
2348  case OBJECT_OPCLASS:
2349  case OBJECT_OPERATOR:
2350  case OBJECT_OPFAMILY:
2351  case OBJECT_PARAMETER_ACL:
2352  case OBJECT_POLICY:
2353  case OBJECT_PUBLICATION:
2356  case OBJECT_ROLE:
2357  case OBJECT_RULE:
2358  case OBJECT_STATISTIC_EXT:
2359  case OBJECT_SUBSCRIPTION:
2360  case OBJECT_TABCONSTRAINT:
2361  case OBJECT_TRANSFORM:
2362  case OBJECT_TRIGGER:
2364  case OBJECT_TSDICTIONARY:
2365  case OBJECT_TSPARSER:
2366  case OBJECT_TSTEMPLATE:
2367  case OBJECT_USER_MAPPING:
2368  case OBJECT_VIEW:
2369  elog(ERROR, "unsupported object type: %d", (int) objtype);
2370  }
2371 
2372  return "???"; /* keep compiler quiet */
2373 }
@ ACLCHECK_NOT_OWNER
Definition: acl.h:184
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:2701
bool object_ownercheck(Oid classid, Oid objectid, Oid roleid)
Definition: aclchk.c:4132
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
Definition: arrayfuncs.c:3375
ArrayType * construct_empty_array(Oid elmtype)
Definition: arrayfuncs.c:3562
int16 AttrNumber
Definition: attnum.h:21
#define InvalidAttrNumber
Definition: attnum.h:23
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:523
#define bms_is_empty(a)
Definition: bitmapset.h:105
static int32 next
Definition: blutils.c:221
static Datum values[MAXATTR]
Definition: bootstrap.c:156
#define CStringGetTextDatum(s)
Definition: builtins.h:97
#define NameStr(name)
Definition: c.h:735
#define OidIsValid(objectId)
Definition: c.h:764
Oid GetNewOidWithIndex(Relation relation, Oid indexId, AttrNumber oidcolumn)
Definition: catalog.c:393
CommandTag GetCommandTagEnum(const char *commandname)
Definition: cmdtag.c:84
bool command_tag_event_trigger_ok(CommandTag commandTag)
Definition: cmdtag.c:67
bool command_tag_table_rewrite_ok(CommandTag commandTag)
Definition: cmdtag.c:73
const char * GetCommandTagName(CommandTag commandTag)
Definition: cmdtag.c:48
CommandTag
Definition: cmdtag.h:23
@ SCT_Simple
@ SCT_AlterTSConfig
@ SCT_AlterDefaultPrivileges
@ SCT_Grant
@ SCT_CreateOpClass
@ SCT_AlterOpFamily
@ SCT_AlterTable
ObjectClass getObjectClass(const ObjectAddress *object)
Definition: dependency.c:2843
@ DEPENDENCY_NORMAL
Definition: dependency.h:33
ObjectClass
Definition: dependency.h:89
@ OCLASS_OPERATOR
Definition: dependency.h:100
@ OCLASS_PARAMETER_ACL
Definition: dependency.h:124
@ OCLASS_LARGEOBJECT
Definition: dependency.h:99
@ OCLASS_FDW
Definition: dependency.h:118
@ OCLASS_OPFAMILY
Definition: dependency.h:102
@ OCLASS_DEFACL
Definition: dependency.h:121
@ OCLASS_TSPARSER
Definition: dependency.h:110
@ OCLASS_TRIGGER
Definition: dependency.h:107
@ OCLASS_DEFAULT
Definition: dependency.h:97
@ OCLASS_TSTEMPLATE
Definition: dependency.h:112
@ OCLASS_AMPROC
Definition: dependency.h:105
@ OCLASS_TBLSPACE
Definition: dependency.h:117
@ OCLASS_TSCONFIG
Definition: dependency.h:113
@ OCLASS_TYPE
Definition: dependency.h:92
@ OCLASS_LANGUAGE
Definition: dependency.h:98
@ OCLASS_CAST
Definition: dependency.h:93
@ OCLASS_SUBSCRIPTION
Definition: dependency.h:129
@ OCLASS_PUBLICATION_NAMESPACE
Definition: dependency.h:127
@ OCLASS_EXTENSION
Definition: dependency.h:122
@ OCLASS_COLLATION
Definition: dependency.h:94
@ OCLASS_FOREIGN_SERVER
Definition: dependency.h:119
@ OCLASS_REWRITE
Definition: dependency.h:106
@ OCLASS_STATISTIC_EXT
Definition: dependency.h:109
@ OCLASS_PROC
Definition: dependency.h:91
@ OCLASS_OPCLASS
Definition: dependency.h:101
@ OCLASS_CONVERSION
Definition: dependency.h:96
@ OCLASS_DATABASE
Definition: dependency.h:116
@ OCLASS_ROLE_MEMBERSHIP
Definition: dependency.h:115
@ OCLASS_SCHEMA
Definition: dependency.h:108
@ OCLASS_EVENT_TRIGGER
Definition: dependency.h:123
@ OCLASS_CLASS
Definition: dependency.h:90
@ OCLASS_TRANSFORM
Definition: dependency.h:130
@ OCLASS_ROLE
Definition: dependency.h:114
@ OCLASS_CONSTRAINT
Definition: dependency.h:95
@ OCLASS_POLICY
Definition: dependency.h:125
@ OCLASS_USER_MAPPING
Definition: dependency.h:120
@ OCLASS_PUBLICATION_REL
Definition: dependency.h:128
@ OCLASS_AM
Definition: dependency.h:103
@ OCLASS_TSDICT
Definition: dependency.h:111
@ OCLASS_PUBLICATION
Definition: dependency.h:126
@ OCLASS_AMOP
Definition: dependency.h:104
int errhint(const char *fmt,...)
Definition: elog.c:1322
int errcode(int sqlerrcode)
Definition: elog.c:860
int errmsg(const char *fmt,...)
Definition: elog.c:1075
#define PG_TRY(...)
Definition: elog.h:370
#define PG_END_TRY(...)
Definition: elog.h:395
#define DEBUG1
Definition: elog.h:30
#define ERROR
Definition: elog.h:39
#define PG_FINALLY(...)
Definition: elog.h:387
#define ereport(elevel,...)
Definition: elog.h:149
void EventTriggerUndoInhibitCommandCollection(void)
void EventTriggerSQLDropAddObject(const ObjectAddress *object, bool original, bool normal)
static void AlterEventTriggerOwner_internal(Relation rel, HeapTuple tup, Oid newOwnerId)
void EventTriggerAlterTableStart(Node *parsetree)
void EventTriggerOnLogin(void)
void EventTriggerCollectAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt)
bool trackDroppedObjectsNeeded(void)
Datum pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
void EventTriggerDDLCommandStart(Node *parsetree)
static void SetDatatabaseHasLoginEventTriggers(void)
static List * EventTriggerCommonSetup(Node *parsetree, EventTriggerEvent event, const char *eventstr, EventTriggerData *trigdata, bool unfiltered)
void EventTriggerInhibitCommandCollection(void)
bool EventTriggerBeginCompleteQuery(void)
static bool filter_event_trigger(CommandTag tag, EventTriggerCacheItem *item)
void EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason)
bool EventTriggerSupportsObjectType(ObjectType obtype)
Oid CreateEventTrigger(CreateEventTrigStmt *stmt)
static void validate_table_rewrite_tags(const char *filtervar, List *taglist)
Oid AlterEventTrigger(AlterEventTrigStmt *stmt)
static const char * stringify_adefprivs_objtype(ObjectType objtype)
void EventTriggerCollectGrant(InternalGrant *istmt)
struct EventTriggerQueryState EventTriggerQueryState
Datum pg_event_trigger_table_rewrite_reason(PG_FUNCTION_ARGS)
void EventTriggerSQLDrop(Node *parsetree)
Datum pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
static CommandTag EventTriggerGetTag(Node *parsetree, EventTriggerEvent event)
void EventTriggerEndCompleteQuery(void)
Datum pg_event_trigger_table_rewrite_oid(PG_FUNCTION_ARGS)
static void validate_ddl_tags(const char *filtervar, List *taglist)
void AlterEventTriggerOwner_oid(Oid trigOid, Oid newOwnerId)
void EventTriggerAlterTableRelid(Oid objectId)
void EventTriggerCollectAlterTSConfig(AlterTSConfigurationStmt *stmt, Oid cfgId, Oid *dictIds, int ndicts)
static EventTriggerQueryState * currentEventTriggerState
Definition: event_trigger.c:78
struct SQLDropObject SQLDropObject
void EventTriggerAlterTableEnd(void)
void EventTriggerCollectAlterOpFam(AlterOpFamilyStmt *stmt, Oid opfamoid, List *operators, List *procedures)
bool event_triggers
Definition: event_trigger.c:81
void EventTriggerCollectCreateOpClass(CreateOpClassStmt *stmt, Oid opcoid, List *operators, List *procedures)
static void error_duplicate_filter_variable(const char *defname)
bool EventTriggerSupportsObjectClass(ObjectClass objclass)
void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)
static const char * stringify_grant_objtype(ObjectType objtype)
void EventTriggerDDLCommandEnd(Node *parsetree)
static Oid insert_event_trigger_tuple(const char *trigname, const char *eventname, Oid evtOwner, Oid funcoid, List *taglist)
void EventTriggerCollectAlterTableSubcmd(Node *subcmd, ObjectAddress address)
Oid get_event_trigger_oid(const char *trigname, bool missing_ok)
ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId)
static void EventTriggerInvoke(List *fn_oid_list, EventTriggerData *trigdata)
static Datum filter_list_to_array(List *filterlist)
List * EventCacheLookup(EventTriggerEvent event)
Definition: evtcache.c:64
EventTriggerEvent
Definition: evtcache.h:21
@ EVT_SQLDrop
Definition: evtcache.h:24
@ EVT_Login
Definition: evtcache.h:26
@ EVT_DDLCommandEnd
Definition: evtcache.h:23
@ EVT_DDLCommandStart
Definition: evtcache.h:22
@ EVT_TableRewrite
Definition: evtcache.h:25
bool creating_extension
Definition: extension.c:73
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:127
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
#define FunctionCallInvoke(fcinfo)
Definition: fmgr.h:172
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_RETURN_OID(x)
Definition: fmgr.h:360
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition: funcapi.c:76
void systable_endscan(SysScanDesc sysscan)
Definition: genam.c:599
HeapTuple systable_getnext(SysScanDesc sysscan)
Definition: genam.c:506
SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)
Definition: genam.c:387
bool MyDatabaseHasLoginEventTriggers
Definition: globals.c:94
bool IsUnderPostmaster
Definition: globals.c:116
Oid MyDatabaseId
Definition: globals.c:90
void heap_inplace_update(Relation relation, HeapTuple tuple)
Definition: heapam.c:5893
HeapTuple heap_copytuple(HeapTuple tuple)
Definition: heaptuple.c:777
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
Definition: heaptuple.c:1117
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static Datum heap_getattr(HeapTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
Definition: htup_details.h:792
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
static void slist_init(slist_head *head)
Definition: ilist.h:986
static bool slist_is_empty(const slist_head *head)
Definition: ilist.h:995
static void slist_push_head(slist_head *head, slist_node *node)
Definition: ilist.h:1006
#define slist_container(type, membername, ptr)
Definition: ilist.h:1106
#define slist_foreach(iter, lhead)
Definition: ilist.h:1132
#define stmt
Definition: indent_codes.h:59
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Definition: indexing.c:313
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
Definition: indexing.c:233
static struct @148 value
int i
Definition: isn.c:73
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
Definition: list.c:339
List * lappend_oid(List *list, Oid datum)
Definition: list.c:375
List * list_copy(const List *oldlist)
Definition: list.c:1573
void list_free(List *list)
Definition: list.c:1546
void LockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1046
bool ConditionalLockSharedObject(Oid classid, Oid objid, uint16 objsubid, LOCKMODE lockmode)
Definition: lmgr.c:1070
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define AccessShareLock
Definition: lockdefs.h:36
#define RowExclusiveLock
Definition: lockdefs.h:38
char * get_namespace_name_or_temp(Oid nspid)
Definition: lsyscache.c:3345
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3321
Oid get_func_rettype(Oid funcid)
Definition: lsyscache.c:1632
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:330
char * pstrdup(const char *in)
Definition: mcxt.c:1619
void pfree(void *pointer)
Definition: mcxt.c:1431
MemoryContext TopMemoryContext
Definition: mcxt.c:141
void * palloc0(Size size)
Definition: mcxt.c:1232
MemoryContext CurrentMemoryContext
Definition: mcxt.c:135
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1034
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:403
void * palloc(Size size)
Definition: mcxt.c:1201
#define AllocSetContextCreate
Definition: memutils.h:128
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:152
Oid GetUserId(void)
Definition: miscinit.c:515
int namestrcmp(Name name, const char *str)
Definition: name.c:247
void namestrcpy(Name name, const char *str)
Definition: name.c:233
bool isTempNamespace(Oid namespaceId)
Definition: namespace.c:3634
bool isAnyTempNamespace(Oid namespaceId)
Definition: namespace.c:3672
char * NameListToString(const List *names)
Definition: namespace.c:3579
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
#define copyObject(obj)
Definition: nodes.h:223
#define InvokeObjectPostCreateHook(classId, objectId, subId)
Definition: objectaccess.h:173
#define InvokeObjectPostAlterHook(classId, objectId, subId)
Definition: objectaccess.h:197
bool get_object_namensp_unique(Oid class_id)
ArrayType * strlist_to_textarray(List *list)
HeapTuple get_catalog_object_by_oid(Relation catalog, AttrNumber oidcol, Oid objectId)
AttrNumber get_object_attnum_oid(Oid class_id)
AttrNumber get_object_attnum_namespace(Oid class_id)
AttrNumber get_object_attnum_name(Oid class_id)
char * getObjectIdentity(const ObjectAddress *object, bool missing_ok)
char * getObjectTypeDescription(const ObjectAddress *object, bool missing_ok)
char * getObjectIdentityParts(const ObjectAddress *object, List **objname, List **objargs, bool missing_ok)
bool is_objectclass_supported(Oid class_id)
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
Oid LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool missing_ok)
Definition: parse_func.c:2143
ObjectType
Definition: parsenodes.h:2095
@ OBJECT_EVENT_TRIGGER
Definition: parsenodes.h:2110
@ OBJECT_FDW
Definition: parsenodes.h:2112
@ OBJECT_TSPARSER
Definition: parsenodes.h:2143
@ OBJECT_COLLATION
Definition: parsenodes.h:2103
@ OBJECT_USER_MAPPING
Definition: parsenodes.h:2146
@ OBJECT_ACCESS_METHOD
Definition: parsenodes.h:2096
@ OBJECT_OPCLASS
Definition: parsenodes.h:2120
@ OBJECT_DEFACL
Definition: parsenodes.h:2107
@ OBJECT_AGGREGATE
Definition: parsenodes.h:2097
@ OBJECT_MATVIEW
Definition: parsenodes.h:2119
@ OBJECT_SCHEMA
Definition: parsenodes.h:2132
@ OBJECT_POLICY
Definition: parsenodes.h:2124
@ OBJECT_OPERATOR
Definition: parsenodes.h:2121
@ OBJECT_FOREIGN_TABLE
Definition: parsenodes.h:2114
@ OBJECT_TSCONFIGURATION
Definition: parsenodes.h:2141
@ OBJECT_OPFAMILY
Definition: parsenodes.h:2122
@ OBJECT_DOMAIN
Definition: parsenodes.h:2108
@ OBJECT_COLUMN
Definition: parsenodes.h:2102
@ OBJECT_TABLESPACE
Definition: parsenodes.h:2138
@ OBJECT_ROLE
Definition: parsenodes.h:2129
@ OBJECT_ROUTINE
Definition: parsenodes.h:2130
@ OBJECT_LARGEOBJECT
Definition: parsenodes.h:2118
@ OBJECT_PUBLICATION_NAMESPACE
Definition: parsenodes.h:2127
@ OBJECT_PROCEDURE
Definition: parsenodes.h:2125
@ OBJECT_EXTENSION
Definition: parsenodes.h:2111
@ OBJECT_INDEX
Definition: parsenodes.h:2116
@ OBJECT_DEFAULT
Definition: parsenodes.h:2106
@ OBJECT_DATABASE
Definition: parsenodes.h:2105
@ OBJECT_SEQUENCE
Definition: parsenodes.h:2133
@ OBJECT_TSTEMPLATE
Definition: parsenodes.h:2144
@ OBJECT_LANGUAGE
Definition: parsenodes.h:2117
@ OBJECT_AMOP
Definition: parsenodes.h:2098
@ OBJECT_PUBLICATION_REL
Definition: parsenodes.h:2128
@ OBJECT_FOREIGN_SERVER
Definition: parsenodes.h:2113
@ OBJECT_TSDICTIONARY
Definition: parsenodes.h:2142
@ OBJECT_ATTRIBUTE
Definition: parsenodes.h:2100
@ OBJECT_PUBLICATION
Definition: parsenodes.h:2126
@ OBJECT_RULE
Definition: parsenodes.h:2131
@ OBJECT_CONVERSION
Definition: parsenodes.h:2104
@ OBJECT_AMPROC
Definition: parsenodes.h:2099
@ OBJECT_TABLE
Definition: parsenodes.h:2137
@ OBJECT_VIEW
Definition: parsenodes.h:2147
@ OBJECT_PARAMETER_ACL
Definition: parsenodes.h:2123
@ OBJECT_TYPE
Definition: parsenodes.h:2145
@ OBJECT_FUNCTION
Definition: parsenodes.h:2115
@ OBJECT_TABCONSTRAINT
Definition: parsenodes.h:2136
@ OBJECT_DOMCONSTRAINT
Definition: parsenodes.h:2109
@ OBJECT_SUBSCRIPTION
Definition: parsenodes.h:2134
@ OBJECT_STATISTIC_EXT
Definition: parsenodes.h:2135
@ OBJECT_CAST
Definition: parsenodes.h:2101
@ OBJECT_TRIGGER
Definition: parsenodes.h:2140
@ OBJECT_TRANSFORM
Definition: parsenodes.h:2139
int16 attnum
Definition: pg_attribute.h:74
const void * data
FormData_pg_database * Form_pg_database
Definition: pg_database.h:96
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
Definition: pg_depend.c:44
void recordDependencyOnCurrentExtension(const ObjectAddress *object, bool isReplace)
Definition: pg_depend.c:192
FormData_pg_event_trigger * Form_pg_event_trigger
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define lfirst_oid(lc)
Definition: pg_list.h:174
void changeDependencyOnOwner(Oid classId, Oid objectId, Oid newOwnerId)
Definition: pg_shdepend.c:313
void recordDependencyOnOwner(Oid classId, Oid objectId, Oid owner)
Definition: pg_shdepend.c:165
void pgstat_init_function_usage(FunctionCallInfo fcinfo, PgStat_FunctionCallUsage *fcu)
void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
unsigned char pg_ascii_toupper(unsigned char ch)
Definition: pgstrcasecmp.c:135
void check_stack_depth(void)
Definition: postgres.c:3523
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static Name DatumGetName(Datum X)
Definition: postgres.h:360
uintptr_t Datum
Definition: postgres.h:64
static Oid DatumGetObjectId(Datum X)
Definition: postgres.h:242
static Datum BoolGetDatum(bool X)
Definition: postgres.h:102
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static Datum NameGetDatum(const NameData *X)
Definition: postgres.h:373
static Datum CStringGetDatum(const char *X)
Definition: postgres.h:350
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
static Datum CharGetDatum(char X)
Definition: postgres.h:122
#define InvalidOid
Definition: postgres_ext.h:36
unsigned int Oid
Definition: postgres_ext.h:31
static color newsub(struct colormap *cm, color co)
Definition: regc_color.c:389
#define RelationGetDescr(relation)
Definition: rel.h:530
void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)
Definition: scankey.c:76
Snapshot GetTransactionSnapshot(void)
Definition: snapmgr.c:223
void PushActiveSnapshot(Snapshot snapshot)
Definition: snapmgr.c:655
void PopActiveSnapshot(void)
Definition: snapmgr.c:750
#define BTEqualStrategyNumber
Definition: stratnum.h:31
#define ERRCODE_DUPLICATE_OBJECT
Definition: streamutil.c:32
struct CollectedCommand::@112::@113 simple
struct CollectedCommand::@112::@116 opfam
CollectedCommandType type
union CollectedCommand::@112 d
struct CollectedCommand::@112::@115 grant
struct CollectedCommand * parent
struct CollectedCommand::@112::@119 defprivs
struct CollectedCommand::@112::@118 atscfg
struct CollectedCommand::@112::@117 createopc
struct CollectedCommand::@112::@114 alterTable
char * defname
Definition: parsenodes.h:802
Node * arg
Definition: parsenodes.h:803
Bitmapset * tagset
Definition: evtcache.h:33
CommandTag tag
Definition: event_trigger.h:29
const char * event
Definition: event_trigger.h:27
struct EventTriggerQueryState * previous
Definition: event_trigger.c:75
CollectedCommand * currentCommand
Definition: event_trigger.c:72
Definition: fmgr.h:57
ItemPointerData t_self
Definition: htup.h:65
Definition: pg_list.h:54
Definition: nodes.h:129
TupleDesc rd_att
Definition: rel.h:112
TupleDesc setDesc
Definition: execnodes.h:340
Tuplestorestate * setResult
Definition: execnodes.h:339
ObjectAddress address
Definition: event_trigger.c:86
const char * schemaname
Definition: event_trigger.c:87
slist_node next
Definition: event_trigger.c:96
const char * objidentity
Definition: event_trigger.c:89
const char * objecttype
Definition: event_trigger.c:90
List * addrnames
Definition: event_trigger.c:91
const char * objname
Definition: event_trigger.c:88
Definition: c.h:730
Definition: regguts.h:323
bool superuser_arg(Oid roleid)
Definition: superuser.c:56
bool superuser(void)
Definition: superuser.c:46
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:219
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:86
#define GetSysCacheOid1(cacheId, oidcol, key1)
Definition: syscache.h:104
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
int SessionReplicationRole
Definition: trigger.c:70
#define SESSION_REPLICATION_ROLE_REPLICA
Definition: trigger.h:141
#define TRIGGER_FIRES_ON_ORIGIN
Definition: trigger.h:149
#define TRIGGER_DISABLED
Definition: trigger.h:152
#define TRIGGER_FIRES_ON_REPLICA
Definition: trigger.h:151
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition: tuplestore.c:750
CommandTag CreateCommandTag(Node *parsetree)
Definition: utility.c:2367
static const char * CreateCommandName(Node *parsetree)
Definition: utility.h:103
#define strVal(v)
Definition: value.h:82
text * cstring_to_text(const char *s)
Definition: varlena.c:184
const char * type
const char * name
void CommandCounterIncrement(void)
Definition: xact.c:1078
void StartTransactionCommand(void)
Definition: xact.c:2953
void CommitTransactionCommand(void)
Definition: xact.c:3050