pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jonathan S. Katz <jkatz@postgresql.org>
To: Pg Docs <pgsql-docs@lists.postgresql.org>
Subject: clarifying trigger/rule behavior on logical replication subscribers
Date: Tue, 6 Jun 2023 09:58:14 -0400
Message-ID: <5bb2c9a2-499f-e1a2-6e33-5ce96b35cc4a@postgresql.org> (raw)

Hi,

While answering a question on "do triggers fire on a logical replication 
subscriber by default?" I tried to look up a reference to this behavior 
in the docs. There wasn't a clear reference point, but on the 
architecture page[1], I found this line that was closest to the answer:

"The apply process on the subscriber database always runs with 
session_replication_role set to replica, which produces the usual 
effects on triggers and constraints."

which assumes that the reader knows what the "usual effects" are.

Attached is a patch that disambiguates this.

Two additional items:

1. I do think this should be backpatched because it clarifies an 
existing behavior.

2. I don't know if we want to add a note about the trigger/rule behavior 
elsewhere in the logical replication section. I don't know if a reader 
would be expecting to find this in the "architecture" section.

Thanks,

Jonathan

[1] 
https://www.postgresql.org/docs/devel/logical-replication-architecture.html

From 23aaa7fe401d85736ebf426626b063075a75c918 Mon Sep 17 00:00:00 2001
From: "Jonathan S. Katz" <jonathan.katz@excoventures.com>
Date: Tue, 6 Jun 2023 09:51:32 -0400
Subject: [PATCH] doc: Clarify behavior of triggers/rules in a logical
 subscriber

By default, triggers and rules do not fire on a logical replication
subscriber based on the "session_replication_role" GUC being set to
"replica". However, the docs in the logical replication section assumed
that the reader understood how this GUC worked. This modifies the docs to
be more explicit, and link back to the GUC itself.
---
 doc/src/sgml/logical-replication.sgml | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml
index 59cf92e6a9..b18cff73ed 100644
--- a/doc/src/sgml/logical-replication.sgml
+++ b/doc/src/sgml/logical-replication.sgml
@@ -1654,9 +1654,13 @@ CONTEXT:  processing remote data for replication origin "pg_16395" during "INSER
 
   <para>
    The apply process on the subscriber database always runs with
-   <varname>session_replication_role</varname> set
-   to <literal>replica</literal>, which produces the usual effects on triggers
-   and constraints.
+   <link linkend="guc-session-replication-role"><varname>session_replication_role</varname></link>
+   set to <literal>replica</literal>. This means that, by default,
+   triggers and rules will not fire on a replica. Users can optionally choose to
+   enable triggers and rules on a table using the
+   <link linkend="sql-altertable"><command>ALTER TABLE</command></link> command
+   and the literal>ENABLE TRIGGER</literal> and <literal>ENABLE RULE</literal>
+   clauses.
   </para>
 
   <para>
-- 
2.37.1 (Apple Git-137.1)



Attachments:

  [text/plain] v1-0001-doc-Clarify-behavior-of-triggers-rules-in-a-logical-.patch (1.7K, ../5bb2c9a2-499f-e1a2-6e33-5ce96b35cc4a@postgresql.org/2-v1-0001-doc-Clarify-behavior-of-triggers-rules-in-a-logical-.patch)
  download | inline diff:
From 23aaa7fe401d85736ebf426626b063075a75c918 Mon Sep 17 00:00:00 2001
From: "Jonathan S. Katz" <jonathan.katz@excoventures.com>
Date: Tue, 6 Jun 2023 09:51:32 -0400
Subject: [PATCH] doc: Clarify behavior of triggers/rules in a logical
 subscriber

By default, triggers and rules do not fire on a logical replication
subscriber based on the "session_replication_role" GUC being set to
"replica". However, the docs in the logical replication section assumed
that the reader understood how this GUC worked. This modifies the docs to
be more explicit, and link back to the GUC itself.
---
 doc/src/sgml/logical-replication.sgml | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/doc/src/sgml/logical-replication.sgml b/doc/src/sgml/logical-replication.sgml
index 59cf92e6a9..b18cff73ed 100644
--- a/doc/src/sgml/logical-replication.sgml
+++ b/doc/src/sgml/logical-replication.sgml
@@ -1654,9 +1654,13 @@ CONTEXT:  processing remote data for replication origin "pg_16395" during "INSER
 
   <para>
    The apply process on the subscriber database always runs with
-   <varname>session_replication_role</varname> set
-   to <literal>replica</literal>, which produces the usual effects on triggers
-   and constraints.
+   <link linkend="guc-session-replication-role"><varname>session_replication_role</varname></link>
+   set to <literal>replica</literal>. This means that, by default,
+   triggers and rules will not fire on a replica. Users can optionally choose to
+   enable triggers and rules on a table using the
+   <link linkend="sql-altertable"><command>ALTER TABLE</command></link> command
+   and the literal>ENABLE TRIGGER</literal> and <literal>ENABLE RULE</literal>
+   clauses.
   </para>
 
   <para>
-- 
2.37.1 (Apple Git-137.1)



  [application/pgp-signature] OpenPGP_signature (839B, ../5bb2c9a2-499f-e1a2-6e33-5ce96b35cc4a@postgresql.org/3-OpenPGP_signature)
  download

view thread (8+ messages)  latest in thread

Message-ID: <5bb2c9a2-499f-e1a2-6e33-5ce96b35cc4a@postgresql.org>
Permalink:  ../5bb2c9a2-499f-e1a2-6e33-5ce96b35cc4a@postgresql.org/
Also on:    postgresql.org/message-id/5bb2c9a2-499f-e1a2-6e33-5ce96b35cc4a@postgresql.org

 ·  · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: jkatz@postgresql.org, pgsql-docs@lists.postgresql.org
  Subject: Re: clarifying trigger/rule behavior on logical replication subscribers
  In-Reply-To: <5bb2c9a2-499f-e1a2-6e33-5ce96b35cc4a@postgresql.org>

* 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