Re: Fwd: Tracking DDL and DML changes in Postgresql and differentversions of database (advance) - Mailing list pgsql-general

From pavan95
Subject Re: Fwd: Tracking DDL and DML changes in Postgresql and differentversions of database (advance)
Date
Msg-id 1527669639980-0.post@n3.nabble.com
Whole thread Raw
In response to Fwd: Tracking DDL and DML changes in Postgresql and differentversions of database (advance)  (Łukasz Jarych <jaryszek@gmail.com>)
List pgsql-general
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


pgsql-general by date:

Previous
From: Łukasz Jarych
Date:
Subject: Fwd: Tracking DDL and DML changes in Postgresql and differentversions of database (advance)
Next
From: Stéphane Dunand
Date:
Subject: Re: Pgagent is not reading pgpass file either in Windows or Linux.