Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVdFb-0005rB-4l for pgsql-general@arkaria.postgresql.org; Fri, 15 Nov 2019 15:11:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVdFZ-0006r1-Ow for pgsql-general@arkaria.postgresql.org; Fri, 15 Nov 2019 15:11:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVdFZ-0006qu-Bg for pgsql-general@lists.postgresql.org; Fri, 15 Nov 2019 15:11:05 +0000 Received: from n3.nabble.com ([162.255.23.22]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1iVdFW-00068S-SJ for pgsql-general@postgresql.org; Fri, 15 Nov 2019 15:11:04 +0000 Received: from n3.nabble.com (localhost [127.0.0.1]) by n3.nabble.com (Postfix) with ESMTP id C8C9318B6D30D for ; Fri, 15 Nov 2019 08:11:01 -0700 (MST) Date: Fri, 15 Nov 2019 08:11:01 -0700 (MST) From: PegoraroF10 To: pgsql-general@postgresql.org Message-ID: <1573830661749-0.post@n3.nabble.com> In-Reply-To: References: <1573828269057-0.post@n3.nabble.com> Subject: Re: naming triggers for execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk well, my way of doing auditing is done on replica, so it=C2=B4s a little di= fferent on production server I do on before update IF (tg_op =3D 'UPDATE') AND (new.* IS DISTINCT FROM old.*) THEN new.userauditing =3D User_ID new.datetimeauditing =3D current_timestamp; END IF; RETURN new; Then, on replica server I do IF (tg_op =3D 'INSERT') THEN insert into auditingtable .... with insert data ELSIF (tg_op =3D 'UPDATE') AND (new.datetimeauditing IS DISTINCT FROM old.datetimeauditing) THEN insert into auditingtable .... with old and new data ELSIF (tg_op =3D 'DELETE') THEN insert into auditingtable .... with old data END IF; That trigger on replica is configured to run on replica with ENABLE REPLICA TRIGGER=20 With this approach I=C2=B4m sure nothing will be audited if nothing was cha= nged 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 yo= u do when you have two triggers using same event on same table.=20 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.h= tml