postgresql/src
Amit Kapila 6c6d6ba3ee Fix the Drop Database hang.
The drop database command waits for the logical replication sync worker to
accept ProcSignalBarrier and the worker's slot creation waits for the drop
database to finish which leads to a deadlock. This happens because the
tablesync worker holds interrupts while creating a slot.

We prevent cancel/die interrupts while creating a slot in the table sync
worker because it is possible that before the server finishes this
command, a concurrent drop subscription happens which would complete
without removing this slot and that leads to the slot existing until the
end of walsender. However, the slot will eventually get dropped at the
walsender exit time, so there is no danger of the dangling slot.

This patch reallows cancel/die interrupts while creating a slot and
modifies the test to wait for slots to become zero to prevent finding an
ephemeral slot.

The reported hang doesn't happen in PG14 as the drop database starts to
wait for ProcSignalBarrier with PG15 (commits 4eb2176318 and e2f65f4255)
but it is good to backpatch this till PG14 as it is not a good idea to
prevent interrupts during a network call that could block indefinitely.

Reported-by: Lakshmi Narayanan Sreethar
Diagnosed-by: Andres Freund
Author: Hou Zhijie
Reviewed-by: Vignesh C, Amit Kapila
Backpatch-through: 14, where it was introduced in commit 6b67d72b60
Discussion: https://postgr.es/m/CA+kvmZELXQ4ZD3U=XCXuG3KvFgkuPoN1QrEj8c-rMRodrLOnsg@mail.gmail.com
2023-01-24 09:25:36 +05:30
..
backend Fix the Drop Database hang. 2023-01-24 09:25:36 +05:30
bin Zero initialize uses of instr_time about to trigger compiler warnings 2023-01-20 21:16:47 -08:00
common Use appendStringInfoSpaces in more places 2023-01-20 13:07:24 +13:00
fe_utils Refactor code for restoring files via shell commands 2023-01-18 11:15:48 +09:00
include Add helper library for use of libpq inside the server environment 2023-01-23 19:25:23 -08:00
interfaces Update copyright for 2023 2023-01-02 15:00:37 -05:00
makefiles Update copyright for 2023 2023-01-02 15:00:37 -05:00
pl New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
port Update copyright for 2023 2023-01-02 15:00:37 -05:00
template Use unnamed POSIX semaphores on Cygwin. 2023-01-06 10:33:28 +13:00
test Fix the Drop Database hang. 2023-01-24 09:25:36 +05:30
timezone Update copyright for 2023 2023-01-02 15:00:37 -05:00
tools Fix pgindent --show-diff option. 2023-01-23 13:50:49 -05:00
tutorial Update copyright for 2023 2023-01-02 15:00:37 -05:00
.gitignore
DEVELOPERS
Makefile Remove the option to build thread_test.c outside configure. 2020-10-21 12:08:48 -04:00
Makefile.global.in autoconf: Move export_dynamic determination to configure 2022-12-06 18:55:28 -08:00
Makefile.shlib autoconf: Rely on ar supporting index creation 2022-10-07 11:53:39 -07:00
meson.build Update copyright for 2023 2023-01-02 15:00:37 -05:00
nls-global.mk Fix for make unportability 2022-07-13 09:15:01 +02:00