postgresql/src/backend
Amit Kapila 6d0eb38557 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
2021-05-21 07:54:27 +05:30
..
access Avoid detoasting failure after COMMIT inside a plpgsql FOR loop. 2021-05-20 18:32:37 -04:00
bootstrap Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
catalog Double-space commands in system_constraints.sql/system_functions.sql. 2021-05-12 18:41:39 -04:00
commands Allow compute_query_id to be set to 'auto' and make it default 2021-05-15 14:13:09 -04:00
executor Convert misleading while loop into an if condition 2021-05-14 12:26:11 +12:00
foreign Update copyright for 2021 2021-01-02 13:06:25 -05:00
jit Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
lib Fix typo in comment 2021-04-20 14:35:16 +02:00
libpq Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
main Update copyright for 2021 2021-01-02 13:06:25 -05:00
nodes Fix mishandling of resjunk columns in ON CONFLICT ... UPDATE tlists. 2021-05-10 11:02:29 -04:00
optimizer Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
parser Allow compute_query_id to be set to 'auto' and make it default 2021-05-15 14:13:09 -04:00
partitioning Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
po Translation updates 2021-05-17 14:30:27 +02:00
port Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
postmaster Fix issues in pg_stat_wal. 2021-05-19 11:38:34 +09:00
regex Fix performance issue in new regex match-all detection code. 2021-05-03 11:42:31 -04:00
replication Fix deadlock for multiple replicating truncates of the same table. 2021-05-21 07:54:27 +05:30
rewrite Remove unused function argument 2021-05-03 09:05:58 +02:00
snowball Update snowball 2021-02-19 08:10:15 +01:00
statistics Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
storage Fix typo and outdated information in README.barrier 2021-05-18 09:54:56 +12:00
tcop Allow compute_query_id to be set to 'auto' and make it default 2021-05-15 14:13:09 -04:00
tsearch Fix typos and grammar in comments and docs 2021-04-19 11:32:30 +09:00
utils Allow compute_query_id to be set to 'auto' and make it default 2021-05-15 14:13:09 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Use sort_template.h for qsort_tuple() and qsort_ssup(). 2021-03-03 17:02:32 +13:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Translation updates 2021-05-10 14:36:21 +02:00