pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: pgsql-committers@postgresql.org
Subject: pgsql: Allow on-the-fly capture of DDL event details
Date: Mon, 11 May 2015 22:16:25 +0000
Message-ID: <E1Yrvzt-0002QX-54@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


view thread (13+ messages)  latest in thread

Message-ID: <E1Yrvzt-0002QX-54@gemulon.postgresql.org>
Permalink:  ../E1Yrvzt-0002QX-54@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1Yrvzt-0002QX-54@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: alvherre@alvh.no-ip.org
  Subject: Re: pgsql: Allow on-the-fly capture of DDL event details
  In-Reply-To: <E1Yrvzt-0002QX-54@gemulon.postgresql.org>
  References: <E1Yrvzt-0002QX-54@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox