Skip to content

Commit 9f7bba2

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 d03a41d commit 9f7bba2

File tree

1 file changed

+57
-19
lines changed

1 file changed

+57
-19
lines changed

doc/src/sgml/logicaldecoding.sgml

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -724,27 +724,65 @@ OutputPluginWrite(ctx, true);
724724

725725
<sect1 id="logicaldecoding-synchronous">
726726
<title>Synchronous Replication Support for Logical Decoding</title>
727+
<sect2>
728+
<title>Overview</title>
727729

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

0 commit comments

Comments
 (0)