]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix deadlock for multiple replicating truncates of the same table.
authorAmit Kapila <akapila@postgresql.org>
Fri, 21 May 2021 02:47:25 +0000 (08:17 +0530)
committerAmit Kapila <akapila@postgresql.org>
Fri, 21 May 2021 02:47:25 +0000 (08:17 +0530)
commit18c6242b7c6da78341b6745bc9b0bcbca20d556b
treee80f2efa7f1b3816dec76a7432baee2860facecf
parent8d341d6cb6c9b3f2ae29837f43857349c6684ab2
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
src/backend/replication/logical/worker.c
src/test/subscription/t/010_truncate.pl