2012-07-18 16:16:16 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* event_trigger.h
|
|
|
|
* Declarations for command trigger handling.
|
|
|
|
*
|
2017-01-03 19:48:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
|
2012-07-18 16:16:16 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
* src/include/commands/event_trigger.h
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef EVENT_TRIGGER_H
|
|
|
|
#define EVENT_TRIGGER_H
|
|
|
|
|
2013-04-11 16:59:47 +02:00
|
|
|
#include "catalog/dependency.h"
|
Add sql_drop event for event triggers
This event takes place just before ddl_command_end, and is fired if and
only if at least one object has been dropped by the command. (For
instance, DROP TABLE IF EXISTS of a table that does not in fact exist
will not lead to such a trigger firing). Commands that drop multiple
objects (such as DROP SCHEMA or DROP OWNED BY) will cause a single event
to fire. Some firings might be surprising, such as
ALTER TABLE DROP COLUMN.
The trigger is fired after the drop has taken place, because that has
been deemed the safest design, to avoid exposing possibly-inconsistent
internal state (system catalogs as well as current transaction) to the
user function code. This means that careful tracking of object
identification is required during the object removal phase.
Like other currently existing events, there is support for tag
filtering.
To support the new event, add a new pg_event_trigger_dropped_objects()
set-returning function, which returns a set of rows comprising the
objects affected by the command. This is to be used within the user
function code, and is mostly modelled after the recently introduced
pg_identify_object() function.
Catalog version bumped due to the new function.
Dimitri Fontaine and Álvaro Herrera
Review by Robert Haas, Tom Lane
2013-03-27 20:02:10 +01:00
|
|
|
#include "catalog/objectaddress.h"
|
2012-07-18 16:16:16 +02:00
|
|
|
#include "catalog/pg_event_trigger.h"
|
|
|
|
#include "nodes/parsenodes.h"
|
Allow on-the-fly capture of DDL event details
This feature lets user code inspect and take action on DDL events.
Whenever a ddl_command_end event trigger is installed, DDL actions
executed are saved to a list which can be inspected during execution of
a function attached to ddl_command_end.
The set-returning function pg_event_trigger_ddl_commands can be used to
list actions so captured; it returns data about the type of command
executed, as well as the affected object. This is sufficient for many
uses of this feature. For the cases where it is not, we also provide a
"command" column of a new pseudo-type pg_ddl_command, which is a
pointer to a C structure that can be accessed by C code. The struct
contains all the info necessary to completely inspect and even
reconstruct the executed command.
There is no actual deparse code here; that's expected to come later.
What we have is enough infrastructure that the deparsing can be done in
an external extension. The intention is that we will add some deparsing
code in a later release, as an in-core extension.
A new test module is included. It's probably insufficient as is, but it
should be sufficient as a starting point for a more complete and
future-proof approach.
Authors: Álvaro Herrera, with some help from Andres Freund, Ian Barwick,
Abhijit Menon-Sen.
Reviews by Andres Freund, Robert Haas, Amit Kapila, Michael Paquier,
Craig Ringer, David Steele.
Additional input from Chris Browne, Dimitri Fontaine, Stephen Frost,
Petr Jelínek, Tom Lane, Jim Nasby, Steven Singer, Pavel Stěhule.
Based on original work by Dimitri Fontaine, though I didn't use his
code.
Discussion:
https://www.postgresql.org/message-id/m2txrsdzxa.fsf@2ndQuadrant.fr
https://www.postgresql.org/message-id/20131108153322.GU5809@eldon.alvh.no-ip.org
https://www.postgresql.org/message-id/20150215044814.GL3391@alvh.no-ip.org
2015-05-12 00:14:31 +02:00
|
|
|
#include "utils/aclchk_internal.h"
|
|
|
|
#include "tcop/deparse_utility.h"
|
2012-07-18 16:16:16 +02:00
|
|
|
|
2012-07-20 17:38:47 +02:00
|
|
|
typedef struct EventTriggerData
|
|
|
|
{
|
|
|
|
NodeTag type;
|
2013-05-29 22:58:43 +02:00
|
|
|
const char *event; /* event name */
|
|
|
|
Node *parsetree; /* parse tree */
|
|
|
|
const char *tag; /* command tag */
|
2012-07-20 17:38:47 +02:00
|
|
|
} EventTriggerData;
|
|
|
|
|
2014-12-07 16:55:28 +01:00
|
|
|
#define AT_REWRITE_ALTER_PERSISTENCE 0x01
|
|
|
|
#define AT_REWRITE_DEFAULT_VAL 0x02
|
|
|
|
#define AT_REWRITE_COLUMN_REWRITE 0x04
|
|
|
|
#define AT_REWRITE_ALTER_OID 0x08
|
|
|
|
|
2012-07-20 17:38:47 +02:00
|
|
|
/*
|
|
|
|
* EventTriggerData is the node type that is passed as fmgr "context" info
|
|
|
|
* when a function is called by the event trigger manager.
|
|
|
|
*/
|
|
|
|
#define CALLED_AS_EVENT_TRIGGER(fcinfo) \
|
|
|
|
((fcinfo)->context != NULL && IsA((fcinfo)->context, EventTriggerData))
|
|
|
|
|
2013-05-29 22:58:43 +02:00
|
|
|
extern Oid CreateEventTrigger(CreateEventTrigStmt *stmt);
|
2012-07-18 16:16:16 +02:00
|
|
|
extern void RemoveEventTriggerById(Oid ctrigOid);
|
|
|
|
extern Oid get_event_trigger_oid(const char *trigname, bool missing_ok);
|
|
|
|
|
2013-05-29 22:58:43 +02:00
|
|
|
extern Oid AlterEventTrigger(AlterEventTrigStmt *stmt);
|
Change many routines to return ObjectAddress rather than OID
The changed routines are mostly those that can be directly called by
ProcessUtilitySlow; the intention is to make the affected object
information more precise, in support for future event trigger changes.
Originally it was envisioned that the OID of the affected object would
be enough, and in most cases that is correct, but upon actually
implementing the event trigger changes it turned out that ObjectAddress
is more widely useful.
Additionally, some command execution routines grew an output argument
that's an object address which provides further info about the executed
command. To wit:
* for ALTER DOMAIN / ADD CONSTRAINT, it corresponds to the address of
the new constraint
* for ALTER OBJECT / SET SCHEMA, it corresponds to the address of the
schema that originally contained the object.
* for ALTER EXTENSION {ADD, DROP} OBJECT, it corresponds to the address
of the object added to or dropped from the extension.
There's no user-visible change in this commit, and no functional change
either.
Discussion: 20150218213255.GC6717@tamriel.snowman.net
Reviewed-By: Stephen Frost, Andres Freund
2015-03-03 18:10:50 +01:00
|
|
|
extern ObjectAddress AlterEventTriggerOwner(const char *name, Oid newOwnerId);
|
2012-07-18 16:16:16 +02:00
|
|
|
extern void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId);
|
|
|
|
|
2012-07-20 17:38:47 +02:00
|
|
|
extern bool EventTriggerSupportsObjectType(ObjectType obtype);
|
2013-04-11 16:59:47 +02:00
|
|
|
extern bool EventTriggerSupportsObjectClass(ObjectClass objclass);
|
2015-02-23 18:22:42 +01:00
|
|
|
extern bool EventTriggerSupportsGrantObjectType(GrantObjectType objtype);
|
2012-07-20 17:38:47 +02:00
|
|
|
extern void EventTriggerDDLCommandStart(Node *parsetree);
|
2013-01-22 00:00:24 +01:00
|
|
|
extern void EventTriggerDDLCommandEnd(Node *parsetree);
|
Add sql_drop event for event triggers
This event takes place just before ddl_command_end, and is fired if and
only if at least one object has been dropped by the command. (For
instance, DROP TABLE IF EXISTS of a table that does not in fact exist
will not lead to such a trigger firing). Commands that drop multiple
objects (such as DROP SCHEMA or DROP OWNED BY) will cause a single event
to fire. Some firings might be surprising, such as
ALTER TABLE DROP COLUMN.
The trigger is fired after the drop has taken place, because that has
been deemed the safest design, to avoid exposing possibly-inconsistent
internal state (system catalogs as well as current transaction) to the
user function code. This means that careful tracking of object
identification is required during the object removal phase.
Like other currently existing events, there is support for tag
filtering.
To support the new event, add a new pg_event_trigger_dropped_objects()
set-returning function, which returns a set of rows comprising the
objects affected by the command. This is to be used within the user
function code, and is mostly modelled after the recently introduced
pg_identify_object() function.
Catalog version bumped due to the new function.
Dimitri Fontaine and Álvaro Herrera
Review by Robert Haas, Tom Lane
2013-03-27 20:02:10 +01:00
|
|
|
extern void EventTriggerSQLDrop(Node *parsetree);
|
2014-12-07 16:55:28 +01:00
|
|
|
extern void EventTriggerTableRewrite(Node *parsetree, Oid tableOid, int reason);
|
Add sql_drop event for event triggers
This event takes place just before ddl_command_end, and is fired if and
only if at least one object has been dropped by the command. (For
instance, DROP TABLE IF EXISTS of a table that does not in fact exist
will not lead to such a trigger firing). Commands that drop multiple
objects (such as DROP SCHEMA or DROP OWNED BY) will cause a single event
to fire. Some firings might be surprising, such as
ALTER TABLE DROP COLUMN.
The trigger is fired after the drop has taken place, because that has
been deemed the safest design, to avoid exposing possibly-inconsistent
internal state (system catalogs as well as current transaction) to the
user function code. This means that careful tracking of object
identification is required during the object removal phase.
Like other currently existing events, there is support for tag
filtering.
To support the new event, add a new pg_event_trigger_dropped_objects()
set-returning function, which returns a set of rows comprising the
objects affected by the command. This is to be used within the user
function code, and is mostly modelled after the recently introduced
pg_identify_object() function.
Catalog version bumped due to the new function.
Dimitri Fontaine and Álvaro Herrera
Review by Robert Haas, Tom Lane
2013-03-27 20:02:10 +01:00
|
|
|
|
|
|
|
extern bool EventTriggerBeginCompleteQuery(void);
|
|
|
|
extern void EventTriggerEndCompleteQuery(void);
|
|
|
|
extern bool trackDroppedObjectsNeeded(void);
|
2014-12-19 19:00:45 +01:00
|
|
|
extern void EventTriggerSQLDropAddObject(const ObjectAddress *object,
|
|
|
|
bool original, bool normal);
|
2012-07-20 17:38:47 +02:00
|
|
|
|
Allow on-the-fly capture of DDL event details
This feature lets user code inspect and take action on DDL events.
Whenever a ddl_command_end event trigger is installed, DDL actions
executed are saved to a list which can be inspected during execution of
a function attached to ddl_command_end.
The set-returning function pg_event_trigger_ddl_commands can be used to
list actions so captured; it returns data about the type of command
executed, as well as the affected object. This is sufficient for many
uses of this feature. For the cases where it is not, we also provide a
"command" column of a new pseudo-type pg_ddl_command, which is a
pointer to a C structure that can be accessed by C code. The struct
contains all the info necessary to completely inspect and even
reconstruct the executed command.
There is no actual deparse code here; that's expected to come later.
What we have is enough infrastructure that the deparsing can be done in
an external extension. The intention is that we will add some deparsing
code in a later release, as an in-core extension.
A new test module is included. It's probably insufficient as is, but it
should be sufficient as a starting point for a more complete and
future-proof approach.
Authors: Álvaro Herrera, with some help from Andres Freund, Ian Barwick,
Abhijit Menon-Sen.
Reviews by Andres Freund, Robert Haas, Amit Kapila, Michael Paquier,
Craig Ringer, David Steele.
Additional input from Chris Browne, Dimitri Fontaine, Stephen Frost,
Petr Jelínek, Tom Lane, Jim Nasby, Steven Singer, Pavel Stěhule.
Based on original work by Dimitri Fontaine, though I didn't use his
code.
Discussion:
https://www.postgresql.org/message-id/m2txrsdzxa.fsf@2ndQuadrant.fr
https://www.postgresql.org/message-id/20131108153322.GU5809@eldon.alvh.no-ip.org
https://www.postgresql.org/message-id/20150215044814.GL3391@alvh.no-ip.org
2015-05-12 00:14:31 +02:00
|
|
|
extern void EventTriggerInhibitCommandCollection(void);
|
|
|
|
extern void EventTriggerUndoInhibitCommandCollection(void);
|
|
|
|
|
|
|
|
extern void EventTriggerCollectSimpleCommand(ObjectAddress address,
|
|
|
|
ObjectAddress secondaryObject,
|
|
|
|
Node *parsetree);
|
|
|
|
|
|
|
|
extern void EventTriggerAlterTableStart(Node *parsetree);
|
|
|
|
extern void EventTriggerAlterTableRelid(Oid objectId);
|
|
|
|
extern void EventTriggerCollectAlterTableSubcmd(Node *subcmd,
|
2015-05-24 03:35:49 +02:00
|
|
|
ObjectAddress address);
|
Allow on-the-fly capture of DDL event details
This feature lets user code inspect and take action on DDL events.
Whenever a ddl_command_end event trigger is installed, DDL actions
executed are saved to a list which can be inspected during execution of
a function attached to ddl_command_end.
The set-returning function pg_event_trigger_ddl_commands can be used to
list actions so captured; it returns data about the type of command
executed, as well as the affected object. This is sufficient for many
uses of this feature. For the cases where it is not, we also provide a
"command" column of a new pseudo-type pg_ddl_command, which is a
pointer to a C structure that can be accessed by C code. The struct
contains all the info necessary to completely inspect and even
reconstruct the executed command.
There is no actual deparse code here; that's expected to come later.
What we have is enough infrastructure that the deparsing can be done in
an external extension. The intention is that we will add some deparsing
code in a later release, as an in-core extension.
A new test module is included. It's probably insufficient as is, but it
should be sufficient as a starting point for a more complete and
future-proof approach.
Authors: Álvaro Herrera, with some help from Andres Freund, Ian Barwick,
Abhijit Menon-Sen.
Reviews by Andres Freund, Robert Haas, Amit Kapila, Michael Paquier,
Craig Ringer, David Steele.
Additional input from Chris Browne, Dimitri Fontaine, Stephen Frost,
Petr Jelínek, Tom Lane, Jim Nasby, Steven Singer, Pavel Stěhule.
Based on original work by Dimitri Fontaine, though I didn't use his
code.
Discussion:
https://www.postgresql.org/message-id/m2txrsdzxa.fsf@2ndQuadrant.fr
https://www.postgresql.org/message-id/20131108153322.GU5809@eldon.alvh.no-ip.org
https://www.postgresql.org/message-id/20150215044814.GL3391@alvh.no-ip.org
2015-05-12 00:14:31 +02:00
|
|
|
extern void EventTriggerAlterTableEnd(void);
|
|
|
|
|
|
|
|
extern void EventTriggerCollectGrant(InternalGrant *istmt);
|
|
|
|
extern void EventTriggerCollectAlterOpFam(AlterOpFamilyStmt *stmt,
|
|
|
|
Oid opfamoid, List *operators,
|
|
|
|
List *procedures);
|
|
|
|
extern void EventTriggerCollectCreateOpClass(CreateOpClassStmt *stmt,
|
|
|
|
Oid opcoid, List *operators,
|
|
|
|
List *procedures);
|
|
|
|
extern void EventTriggerCollectAlterTSConfig(AlterTSConfigurationStmt *stmt,
|
|
|
|
Oid cfgId, Oid *dictIds, int ndicts);
|
|
|
|
extern void EventTriggerCollectAlterDefPrivs(AlterDefaultPrivilegesStmt *stmt);
|
|
|
|
|
Phase 2 of pgindent updates.
Change pg_bsd_indent to follow upstream rules for placement of comments
to the right of code, and remove pgindent hack that caused comments
following #endif to not obey the general rule.
Commit e3860ffa4dd0dad0dd9eea4be9cc1412373a8c89 wasn't actually using
the published version of pg_bsd_indent, but a hacked-up version that
tried to minimize the amount of movement of comments to the right of
code. The situation of interest is where such a comment has to be
moved to the right of its default placement at column 33 because there's
code there. BSD indent has always moved right in units of tab stops
in such cases --- but in the previous incarnation, indent was working
in 8-space tab stops, while now it knows we use 4-space tabs. So the
net result is that in about half the cases, such comments are placed
one tab stop left of before. This is better all around: it leaves
more room on the line for comment text, and it means that in such
cases the comment uniformly starts at the next 4-space tab stop after
the code, rather than sometimes one and sometimes two tabs after.
Also, ensure that comments following #endif are indented the same
as comments following other preprocessor commands such as #else.
That inconsistency turns out to have been self-inflicted damage
from a poorly-thought-through post-indent "fixup" in pgindent.
This patch is much less interesting than the first round of indent
changes, but also bulkier, so I thought it best to separate the effects.
Discussion: https://postgr.es/m/E1dAmxK-0006EE-1r@gemulon.postgresql.org
Discussion: https://postgr.es/m/30527.1495162840@sss.pgh.pa.us
2017-06-21 21:18:54 +02:00
|
|
|
#endif /* EVENT_TRIGGER_H */
|