From: PegoraroF10 <marcos@f10.com.br>
To: pgsql-general@postgresql.org
Subject: Re: naming triggers for execution
Date: Fri, 15 Nov 2019 08:11:01 -0700 (MST)
Message-ID: <1573830661749-0.post@n3.nabble.com> (raw)
In-Reply-To: <CAOzAqu+dTGDH50YfOyt7HcKekxEPZt=HQ3pRk4g8yFXRyGuZWQ@mail.gmail.com>
References: <1573828269057-0.post@n3.nabble.com>
<CAOzAqu+dTGDH50YfOyt7HcKekxEPZt=HQ3pRk4g8yFXRyGuZWQ@mail.gmail.com>
well, my way of doing auditing is done on replica, so it´s a little different
on production server I do on before update
IF (tg_op = 'UPDATE') AND (new.* IS DISTINCT FROM old.*) THEN
new.userauditing = User_ID
new.datetimeauditing = current_timestamp;
END IF;
RETURN new;
Then, on replica server I do
IF (tg_op = 'INSERT') THEN
insert into auditingtable .... with insert data
ELSIF (tg_op = 'UPDATE') AND (new.datetimeauditing IS DISTINCT FROM
old.datetimeauditing) THEN
insert into auditingtable .... with old and new data
ELSIF (tg_op = 'DELETE') THEN
insert into auditingtable .... with old data
END IF;
That trigger on replica is configured to run on replica with ENABLE REPLICA
TRIGGER
With this approach I´m sure nothing will be audited if nothing was changed
and additionally all auditing will be done on replica which will frees the
production server for production and not auditing.
But, independently of my auditing is being different from yours, what do you
do when you have two triggers using same event on same table.
Another example I can give you is when you define a PK. Imagine you have a
function which creates your PK, but another trigger needs that pk value to
do something. Both are ran before insert but trigger which creates PK needs
to be the first. How can you sure this happens.
--
Sent from: https://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: marcos@f10.com.br
Subject: Re: naming triggers for execution
In-Reply-To: <1573830661749-0.post@n3.nabble.com>
References: <1573828269057-0.post@n3.nabble.com> <CAOzAqu+dTGDH50YfOyt7HcKekxEPZt=HQ3pRk4g8yFXRyGuZWQ@mail.gmail.com> <1573830661749-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