From: | Amit Kapila <akapila(at)postgresql(dot)org> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Fix Logical Replication of Truncate in synchronous commit mode. |
Date: | 2021-04-27 03:10:55 |
Message-ID: | E1lbE7j-0001cH-29@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
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(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Amit Kapila | 2021-04-27 03:50:30 | pgsql: Use HTAB for replication slot statistics. |
Previous Message | Alvaro Herrera | 2021-04-26 20:22:20 | pgsql: psql: tab-complete ALTER ... DETACH CONCURRENTLY / FINALIZE |