From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix Logical Replication of Truncate in synchronous commit mode.
Date: Tue, 27 Apr 2021 03:10:55 +0000
Message-ID: <E1lbE7j-0001cH-29@gemulon.postgresql.org> (raw)
Fix Logical Replication of Truncate in synchronous commit mode.
The Truncate operation acquires an exclusive lock on the target relation
and indexes. It then waits for logical replication of the operation to
finish at commit. Now because we are acquiring the shared lock on the
target index to get index attributes in pgoutput while sending the
changes for the Truncate operation, it leads to a deadlock.
Actually, we don't need to acquire a lock on the target index as we build
the cache entry using a historic snapshot and all the later changes are
absorbed while decoding WAL. So, we wrote a special purpose function for
logical replication to get a bitmap of replica identity attribute numbers
where we get that information without locking the target index.
We decided not to backpatch this as there doesn't seem to be any field
complaint about this issue since it was introduced in commit 5dfd1e5a in
v11.
Reported-by: Haiying Tang
Author: Takamichi Osumi, test case by Li Japin
Reviewed-by: Amit Kapila, Ajin Cherian
Discussion: https://postgr.es/m/OS0PR01MB6113C2499C7DC70EE55ADB82FB759@OS0PR01MB6113.jpnprd01.prod.outlook.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/e7eea52b2d61917fbbdac7f3f895e4ef636e935b
Modified Files
--------------
src/backend/replication/logical/proto.c | 3 +-
src/backend/utils/cache/relcache.c | 75 +++++++++++++++++++++++++++++++++
src/include/utils/relcache.h | 2 +
src/test/subscription/t/010_truncate.pl | 27 +++++++++++-
4 files changed, 104 insertions(+), 3 deletions(-)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: akapila@postgresql.org
Subject: Re: pgsql: Fix Logical Replication of Truncate in synchronous commit mode.
In-Reply-To: <E1lbE7j-0001cH-29@gemulon.postgresql.org>
References: <E1lbE7j-0001cH-29@gemulon.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