From f90306b4a3d3339d87d099c2392fda3c45736d53 Mon Sep 17 00:00:00 2001 From: Osumi Takamichi Date: Thu, 10 Jun 2021 23:17:35 +0000 Subject: [PATCH v05] deadlock documentation of synchronous logical decoding In synchronous logical setup, some scenarios to lock [user] catalog tables can cause deadlock hazards, which must be documented. This is because logical decoding of transactions can lock catalog tables to access them, but such tables can be locked by the transactions in advance. Which means that output plugin is locked out and subscriber synchronization hangs. This patch fixes some documentations to notify users of those hazards. Author: Takamichi Osumi Reviewed-by: Amit Kapila Reviewed-by: Vignesh C Discussion: https://www.postgresql.org/message-id/20210222222847.tpnb6eg3yiykzpky%40alap3.anarazel.de Backpatch-through: 9.6 --- doc/src/sgml/logicaldecoding.sgml | 81 ++++++++++++++++++++++++++++++--------- 1 file changed, 63 insertions(+), 18 deletions(-) diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml index 42c004f..7d6a09b 100644 --- a/doc/src/sgml/logicaldecoding.sgml +++ b/doc/src/sgml/logicaldecoding.sgml @@ -691,27 +691,72 @@ OutputPluginWrite(ctx, true); Synchronous Replication Support for Logical Decoding + + Overview - - Logical decoding can be used to build - synchronous - replication solutions with the same user interface as synchronous - replication for streaming - replication. To do this, the streaming replication interface - (see ) must be used to stream out - data. Clients have to send Standby status update (F) - (see ) messages, just like streaming - replication clients do. - + + Overview + - - A synchronous replica receiving changes via logical decoding will work in - the scope of a single database. Since, in contrast to - that, synchronous_standby_names currently is - server wide, this means this technique will not work properly if more - than one database is actively used. + Logical decoding can be used to build + synchronous + replication solutions with the same user interface as synchronous + replication for streaming + replication. To do this, the streaming replication interface + (see ) must be used to stream out + data. Clients have to send Standby status update (F) + (see ) messages, just like streaming + replication clients do. + + + + + A synchronous replica receiving changes via logical decoding will work in + the scope of a single database. Since, in contrast to + that, synchronous_standby_names currently is + server wide, this means this technique will not work properly if more + than one database is actively used. - + + + + + Caveats + + + Caveats + + + + In synchronous replication setup, a deadlock can happen, if the transaction + has locked [user] catalog tables exclusively. This is because logical decoding of + transactions can lock catalog tables to access them. To avoid this users + must refrain from taking an exclusive lock on [user] catalog tables. This can + happen in the following ways: + + + + + Issuing an explicit LOCK on pg_class + (or any other catalog table) in a transaction. + + + + + + Reordering pg_class by CLUSTER + command in a transaction. + + + + + + Executing TRUNCATE on user_catalog_table in a transaction. + + + + + -- 2.2.0