pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix deadlock for multiple replicating truncates of the same tabl 4+ messages / 1 participants [nested] [flat]
* pgsql: Fix deadlock for multiple replicating truncates of the same tabl @ 2021-05-21 03:31 Amit Kapila <akapila@postgresql.org> 0 siblings, 0 replies; 4+ messages in thread From: Amit Kapila @ 2021-05-21 03:31 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 ------ master Details ------- https://git.postgresql.org/pg/commitdiff/6d0eb38557155855539cd007f04736dc3b2ba16f Modified Files -------------- src/backend/replication/logical/worker.c | 9 ++--- src/test/subscription/t/010_truncate.pl | 57 +++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 5 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix deadlock for multiple replicating truncates of the same tabl @ 2021-05-21 03:31 Amit Kapila <akapila@postgresql.org> 0 siblings, 0 replies; 4+ messages in thread From: Amit Kapila @ 2021-05-21 03:31 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix deadlock for multiple replicating truncates of the same tabl @ 2021-05-21 03:31 Amit Kapila <akapila@postgresql.org> 0 siblings, 0 replies; 4+ messages in thread From: Amit Kapila @ 2021-05-21 03:31 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/18c6242b7c6da78341b6745bc9b0bcbca20d556b Modified Files -------------- src/backend/replication/logical/worker.c | 5 +-- src/test/subscription/t/010_truncate.pl | 53 +++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 3 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
* pgsql: Fix deadlock for multiple replicating truncates of the same tabl @ 2021-05-21 03:31 Amit Kapila <akapila@postgresql.org> 0 siblings, 0 replies; 4+ messages in thread From: Amit Kapila @ 2021-05-21 03:31 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/71787b23e3dc5510c5bb167abc8a086756811841 Modified Files -------------- src/backend/replication/logical/worker.c | 5 +-- src/test/subscription/t/010_truncate.pl | 53 +++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 3 deletions(-) ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2021-05-21 03:31 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-05-21 03:31 pgsql: Fix deadlock for multiple replicating truncates of the same tabl Amit Kapila <akapila@postgresql.org> 2021-05-21 03:31 pgsql: Fix deadlock for multiple replicating truncates of the same tabl Amit Kapila <akapila@postgresql.org> 2021-05-21 03:31 pgsql: Fix deadlock for multiple replicating truncates of the same tabl Amit Kapila <akapila@postgresql.org> 2021-05-21 03:31 pgsql: Fix deadlock for multiple replicating truncates of the same tabl Amit Kapila <akapila@postgresql.org>
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