From: | Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Allow on-the-fly capture of DDL event details |
Date: | 2015-05-11 22:16:25 |
Message-ID: | E1Yrvzt-0002QX-54@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
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
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/b488c580aef4e05f39be5daaab6464da5b22a494
Modified Files
--------------
doc/src/sgml/event-trigger.sgml | 11 +-
doc/src/sgml/func.sgml | 93 ++-
src/backend/catalog/aclchk.c | 37 +-
src/backend/commands/event_trigger.c | 706 +++++++++++++++++++-
src/backend/commands/opclasscmds.c | 63 +-
src/backend/commands/schemacmds.c | 12 +
src/backend/commands/tablecmds.c | 11 +-
src/backend/commands/tsearchcmds.c | 5 +
src/backend/nodes/copyfuncs.c | 1 +
src/backend/nodes/equalfuncs.c | 1 +
src/backend/parser/gram.y | 6 +
src/backend/tcop/utility.c | 274 +++++---
src/backend/utils/adt/format_type.c | 3 +
src/backend/utils/adt/pseudotypes.c | 65 +-
src/include/catalog/catversion.h | 2 +-
src/include/catalog/opfam_internal.h | 28 +
src/include/catalog/pg_proc.h | 11 +
src/include/catalog/pg_type.h | 4 +
src/include/commands/defrem.h | 1 +
src/include/commands/event_trigger.h | 26 +
src/include/commands/extension.h | 2 +-
src/include/nodes/parsenodes.h | 10 +
src/include/tcop/deparse_utility.h | 105 +++
src/include/utils/aclchk_internal.h | 45 ++
src/include/utils/builtins.h | 5 +
src/test/modules/Makefile | 5 +-
src/test/modules/test_ddl_deparse/Makefile | 19 +
.../test_ddl_deparse/expected/alter_function.out | 15 +
.../test_ddl_deparse/expected/alter_sequence.out | 15 +
.../test_ddl_deparse/expected/alter_table.out | 18 +
.../test_ddl_deparse/expected/alter_type_enum.out | 7 +
.../test_ddl_deparse/expected/comment_on.out | 25 +
.../expected/create_conversion.out | 6 +
.../test_ddl_deparse/expected/create_domain.out | 11 +
.../test_ddl_deparse/expected/create_extension.out | 5 +
.../test_ddl_deparse/expected/create_rule.out | 30 +
.../test_ddl_deparse/expected/create_schema.out | 19 +
.../expected/create_sequence_1.out | 11 +
.../test_ddl_deparse/expected/create_table.out | 160 +++++
.../test_ddl_deparse/expected/create_trigger.out | 18 +
.../test_ddl_deparse/expected/create_type.out | 24 +
.../test_ddl_deparse/expected/create_view.out | 19 +
.../modules/test_ddl_deparse/expected/defprivs.out | 6 +
.../modules/test_ddl_deparse/expected/matviews.out | 8 +
.../modules/test_ddl_deparse/expected/opfamily.out | 67 ++
.../test_ddl_deparse/expected/test_ddl_deparse.out | 40 ++
src/test/modules/test_ddl_deparse/regress_schedule | 21 +
.../test_ddl_deparse/sql/alter_function.sql | 17 +
.../test_ddl_deparse/sql/alter_sequence.sql | 17 +
.../modules/test_ddl_deparse/sql/alter_table.sql | 13 +
.../test_ddl_deparse/sql/alter_type_enum.sql | 6 +
.../modules/test_ddl_deparse/sql/comment_on.sql | 17 +
.../test_ddl_deparse/sql/create_conversion.sql | 6 +
.../modules/test_ddl_deparse/sql/create_domain.sql | 10 +
.../test_ddl_deparse/sql/create_extension.sql | 6 +
.../modules/test_ddl_deparse/sql/create_rule.sql | 31 +
.../modules/test_ddl_deparse/sql/create_schema.sql | 17 +
.../test_ddl_deparse/sql/create_sequence_1.sql | 12 +
.../modules/test_ddl_deparse/sql/create_table.sql | 142 ++++
.../test_ddl_deparse/sql/create_trigger.sql | 18 +
.../modules/test_ddl_deparse/sql/create_type.sql | 21 +
.../modules/test_ddl_deparse/sql/create_view.sql | 17 +
src/test/modules/test_ddl_deparse/sql/defprivs.sql | 6 +
src/test/modules/test_ddl_deparse/sql/matviews.sql | 8 +
src/test/modules/test_ddl_deparse/sql/opfamily.sql | 53 ++
.../test_ddl_deparse/sql/test_ddl_deparse.sql | 42 ++
.../test_ddl_deparse/test_ddl_deparse--1.0.sql | 16 +
.../modules/test_ddl_deparse/test_ddl_deparse.c | 267 ++++++++
.../test_ddl_deparse/test_ddl_deparse.control | 4 +
69 files changed, 2667 insertions(+), 155 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Eisentraut | 2015-05-12 00:41:44 | pgsql: Replace some appendStringInfo* calls with more appropriate varia |
Previous Message | Stephen Frost | 2015-05-11 19:44:16 | pgsql: Allow LOCK TABLE .. ROW EXCLUSIVE MODE with INSERT |