pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Kapila <akapila@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix deadlock for multiple replicating truncates of the same tabl
Date: Fri, 21 May 2021 03:31:35 +0000
Message-ID: <E1ljvst-00074e-8E@gemulon.postgresql.org> (raw)

Fix deadlock for multiple replicating truncates of the same table.

While applying the truncate change, the logical apply worker acquires
RowExclusiveLock on the relation being truncated. This allowed truncate on
the relation at a time by two apply workers which lead to a deadlock. The
reason was that one of the workers after updating the pg_class tuple tries
to acquire SHARE lock on the relation and started to wait for the second
worker which has acquired RowExclusiveLock on the relation. And when the
second worker tries to update the pg_class tuple, it starts to wait for
the first worker which leads to a deadlock. Fix it by acquiring
AccessExclusiveLock on the relation before applying the truncate change as
we do for normal truncate operation.

Author: Peter Smith, test case by Haiying Tang
Reviewed-by: Dilip Kumar, Amit Kapila
Backpatch-through: 11
Discussion: https://postgr.es/m/CAHut+PsNm43p0jM+idTvWwiGZPcP0hGrHMPK9TOAkc+a4UpUqw@mail.gmail.com

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c83c0257e4c3ec3503f8d72698d70829af979803

Modified Files
--------------
src/backend/replication/logical/worker.c |  9 +++---
src/test/subscription/t/010_truncate.pl  | 53 +++++++++++++++++++++++++++++++-
2 files changed, 57 insertions(+), 5 deletions(-)



view thread (4+ messages)  latest in thread

Message-ID: <E1ljvst-00074e-8E@gemulon.postgresql.org>
Permalink:  ../E1ljvst-00074e-8E@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1ljvst-00074e-8E@gemulon.postgresql.org

 · 

reply

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 deadlock for multiple replicating truncates of the same tabl
  In-Reply-To: <E1ljvst-00074e-8E@gemulon.postgresql.org>
  References: <E1ljvst-00074e-8E@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