From: pavan95 <pavan.postgresdba@gmail.com>
To: pgsql-general@postgresql.org
Subject: Re: Fwd: Tracking DDL and DML changes in Postgresql and different versions of database (advance)
Date: Wed, 30 May 2018 01:40:39 -0700 (MST)
Message-ID: <1527669639980-0.post@n3.nabble.com> (raw)
In-Reply-To: <CAGv31odQFphavktiCsEygB0OHbwzerGpY7=_M=Zp3Gcbmn9aJw@mail.gmail.com>
References: <CAGv31oeocf2dF5h394YAxG_OC2uen5pt-K=zWeuW2UBQTD=fmg@mail.gmail.com>
<CACh9nsa4CbsVzAHw-2z9VAsy35VWDa0tR5g7uWpf9xMFyYPHqA@mail.gmail.com>
<CAGv31odQFphavktiCsEygB0OHbwzerGpY7=_M=Zp3Gcbmn9aJw@mail.gmail.com>
Hi Luke,
>Thank you Pavan,
>I have a few questions.
>Could you please describe in more details about event triggers? Maybe some
examples how to start with this?
Please refer the below link for more detailed information about "Event
Triggers".
Link: https://www.postgresql.org/docs/10/static/sql-createeventtrigger.html
<https://www.postgresql.org/docs/10/static/sql-createeventtrigger.html;
You can find the below sample procedure along with the event trigger which
executes for every DDL against the database.
--Procedure
CREATE OR REPLACE FUNCTION snitch() RETURNS event_trigger AS $$
BEGIN
RAISE NOTICE 'snitch: % %', tg_event, tg_tag;
END;
$$ LANGUAGE plpgsql;
--Event Trigger
CREATE EVENT TRIGGER snitch ON ddl_command_start EXECUTE PROCEDURE snitch();
If you execute above code you can find that the event trigger snitch raises
a notice message whenever ddl fires on the database. Do let me know if you
face any problem.
>And regarding changes, how to create exact state of database and give the
version for it?
Instead of the notice message in the above procedure, you can simple insert
user info, timestamp at the time of ddl command start, actual query, and the
tag name(tg_tag=> whether to determine it is ALTER/CREATE/SECURITY
LABEL/DROP/COMMENT/GRANT or REVOKE).
Please feel free to write up if any queries persists.
--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
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-general@postgresql.org
Cc: pavan.postgresdba@gmail.com
Subject: Re: Fwd: Tracking DDL and DML changes in Postgresql and different versions of database (advance)
In-Reply-To: <1527669639980-0.post@n3.nabble.com>
References: <CAGv31oeocf2dF5h394YAxG_OC2uen5pt-K=zWeuW2UBQTD=fmg@mail.gmail.com> <CACh9nsa4CbsVzAHw-2z9VAsy35VWDa0tR5g7uWpf9xMFyYPHqA@mail.gmail.com> <CAGv31odQFphavktiCsEygB0OHbwzerGpY7=_M=Zp3Gcbmn9aJw@mail.gmail.com> <1527669639980-0.post@n3.nabble.com>
* 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