Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fNwf5-0004iv-0Z for pgsql-general@arkaria.postgresql.org; Wed, 30 May 2018 08:40:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fNwf0-0004hs-24 for pgsql-general@arkaria.postgresql.org; Wed, 30 May 2018 08:40:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fNwez-0004hi-QH for pgsql-general@lists.postgresql.org; Wed, 30 May 2018 08:40:45 +0000 Received: from n3.nabble.com ([162.255.23.22]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fNwew-0002NJ-HB for pgsql-general@postgresql.org; Wed, 30 May 2018 08:40:45 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id 05D7BD362C9A for ; Wed, 30 May 2018 01:40:40 -0700 (MST) Date: Wed, 30 May 2018 01:40:39 -0700 (MST) From: pavan95 To: pgsql-general@postgresql.org Message-ID: <1527669639980-0.post@n3.nabble.com> In-Reply-To: References: Subject: Re: Fwd: Tracking DDL and DML changes in Postgresql and different versions of database (advance) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 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