diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2015-05-11 19:14:31 -0300 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2015-05-11 19:14:31 -0300 |
commit | b488c580aef4e05f39be5daaab6464da5b22a494 (patch) | |
tree | 79e7605ff000293710de977a5389a8fbf615f702 /src/backend/utils/adt | |
parent | fa2642438f189c2b169ace3ac1df19533b9c7781 (diff) | |
download | postgresql-b488c580aef4e05f39be5daaab6464da5b22a494.tar.gz postgresql-b488c580aef4e05f39be5daaab6464da5b22a494.zip |
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
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r-- | src/backend/utils/adt/format_type.c | 3 | ||||
-rw-r--r-- | src/backend/utils/adt/pseudotypes.c | 65 |
2 files changed, 66 insertions, 2 deletions
diff --git a/src/backend/utils/adt/format_type.c b/src/backend/utils/adt/format_type.c index 2f0f0a1d895..a8519835cc6 100644 --- a/src/backend/utils/adt/format_type.c +++ b/src/backend/utils/adt/format_type.c @@ -96,6 +96,9 @@ format_type_be(Oid type_oid) return format_type_internal(type_oid, -1, false, false, false); } +/* + * This version returns a name which is always qualified. + */ char * format_type_be_qualified(Oid type_oid) { diff --git a/src/backend/utils/adt/pseudotypes.c b/src/backend/utils/adt/pseudotypes.c index 6e663c7a2bb..9ad460abfbd 100644 --- a/src/backend/utils/adt/pseudotypes.c +++ b/src/backend/utils/adt/pseudotypes.c @@ -522,11 +522,12 @@ pg_node_tree_in(PG_FUNCTION_ARGS) */ ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot accept a value of type pg_node_tree"))); + errmsg("cannot accept a value of type %s", "pg_node_tree"))); PG_RETURN_VOID(); /* keep compiler quiet */ } + /* * pg_node_tree_out - output routine for type PG_NODE_TREE. * @@ -546,7 +547,7 @@ pg_node_tree_recv(PG_FUNCTION_ARGS) { ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot accept a value of type pg_node_tree"))); + errmsg("cannot accept a value of type %s", "pg_node_tree"))); PG_RETURN_VOID(); /* keep compiler quiet */ } @@ -559,3 +560,63 @@ pg_node_tree_send(PG_FUNCTION_ARGS) { return textsend(fcinfo); } + +/* + * pg_ddl_command_in - input routine for type PG_DDL_COMMAND. + * + * Like pg_node_tree, pg_ddl_command isn't really a pseudotype; it's here for + * the same reasons as that one. + */ +Datum +pg_ddl_command_in(PG_FUNCTION_ARGS) +{ + /* + * Disallow input of pg_ddl_command value. + */ + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot accept a value of type %s", "pg_ddl_command"))); + + PG_RETURN_VOID(); /* keep compiler quiet */ +} + +/* + * pg_ddl_command_out - output routine for type PG_DDL_COMMAND. + * + * We don't have any good way to output this type directly, so punt. + */ +Datum +pg_ddl_command_out(PG_FUNCTION_ARGS) +{ + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot output a value of type %s", "pg_ddl_command"))); + + PG_RETURN_VOID(); +} + +/* + * pg_ddl_command_recv - binary input routine for type PG_DDL_COMMAND. + */ +Datum +pg_ddl_command_recv(PG_FUNCTION_ARGS) +{ + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot accept a value of type %s", "pg_ddl_command"))); + + PG_RETURN_VOID(); +} + +/* + * pg_ddl_command_send - binary output routine for type PG_DDL_COMMAND. + */ +Datum +pg_ddl_command_send(PG_FUNCTION_ARGS) +{ + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("cannot output a value of type %s", "pg_ddl_command"))); + + PG_RETURN_VOID(); +} |