Skip to content

Commit 5a45603

Browse files
author
Amit Kapila
committed
Document a few caveats in synchronous logical replication.
In a synchronous logical setup, locking [user] catalog tables can cause deadlock. This is because logical decoding of transactions can lock catalog tables to access them so exclusively locking those in transactions can lead to deadlock. To avoid this users must refrain from having exclusive locks on catalog tables. Author: Takamichi Osumi Reviewed-by: Vignesh C, Amit Kapila Backpatch-through: 9.6 Discussion: https://www.postgresql.org/message-id/20210222222847.tpnb6eg3yiykzpky%40alap3.anarazel.de
1 parent 8f32299 commit 5a45603

File tree

1 file changed

+57
-19
lines changed

1 file changed

+57
-19
lines changed

doc/src/sgml/logicaldecoding.sgml

+57-19
Original file line numberDiff line numberDiff line change
@@ -723,27 +723,65 @@ OutputPluginWrite(ctx, true);
723723

724724
<sect1 id="logicaldecoding-synchronous">
725725
<title>Synchronous Replication Support for Logical Decoding</title>
726+
<sect2>
727+
<title>Overview</title>
726728

727-
<para>
728-
Logical decoding can be used to build
729-
<link linkend="synchronous-replication">synchronous
730-
replication</link> solutions with the same user interface as synchronous
731-
replication for <link linkend="streaming-replication">streaming
732-
replication</link>. To do this, the streaming replication interface
733-
(see <xref linkend="logicaldecoding-walsender"/>) must be used to stream out
734-
data. Clients have to send <literal>Standby status update (F)</literal>
735-
(see <xref linkend="protocol-replication"/>) messages, just like streaming
736-
replication clients do.
737-
</para>
738-
739-
<note>
740729
<para>
741-
A synchronous replica receiving changes via logical decoding will work in
742-
the scope of a single database. Since, in contrast to
743-
that, <parameter>synchronous_standby_names</parameter> currently is
744-
server wide, this means this technique will not work properly if more
745-
than one database is actively used.
730+
Logical decoding can be used to build
731+
<link linkend="synchronous-replication">synchronous
732+
replication</link> solutions with the same user interface as synchronous
733+
replication for <link linkend="streaming-replication">streaming
734+
replication</link>. To do this, the streaming replication interface
735+
(see <xref linkend="logicaldecoding-walsender"/>) must be used to stream out
736+
data. Clients have to send <literal>Standby status update (F)</literal>
737+
(see <xref linkend="protocol-replication"/>) messages, just like streaming
738+
replication clients do.
739+
</para>
740+
741+
<note>
742+
<para>
743+
A synchronous replica receiving changes via logical decoding will work in
744+
the scope of a single database. Since, in contrast to
745+
that, <parameter>synchronous_standby_names</parameter> currently is
746+
server wide, this means this technique will not work properly if more
747+
than one database is actively used.
746748
</para>
747-
</note>
749+
</note>
750+
</sect2>
751+
752+
<sect2 id="logicaldecoding-synchronous-caveats">
753+
<title>Caveats</title>
754+
755+
<para>
756+
In synchronous replication setup, a deadlock can happen, if the transaction
757+
has locked [user] catalog tables exclusively. This is because logical decoding of
758+
transactions can lock catalog tables to access them. To avoid this users
759+
must refrain from taking an exclusive lock on [user] catalog tables. This can
760+
happen in the following ways:
761+
762+
<itemizedlist>
763+
<listitem>
764+
<para>
765+
Issuing an explicit <command>LOCK</command> on <structname>pg_class</structname>
766+
(or any other catalog table) in a transaction.
767+
</para>
768+
</listitem>
769+
770+
<listitem>
771+
<para>
772+
Perform <command>CLUSTER</command> on <structname>pg_class</structname> in a
773+
transaction.
774+
</para>
775+
</listitem>
776+
777+
<listitem>
778+
<para>
779+
Executing <command>TRUNCATE</command> on [user] catalog table in a
780+
transaction.
781+
</para>
782+
</listitem>
783+
</itemizedlist>
784+
</para>
785+
</sect2>
748786
</sect1>
749787
</chapter>

0 commit comments

Comments
 (0)