Fix DROP {DATABASE,TABLESPACE} on Windows.
authorThomas Munro <[email protected]>
Fri, 11 Feb 2022 21:21:23 +0000 (10:21 +1300)
committerThomas Munro <[email protected]>
Fri, 11 Feb 2022 21:21:23 +0000 (10:21 +1300)
commit4eb2176318d0561846c1f9fb3c68bede799d640f
treeae824847ecc96384f9fbcd7010a854cf50ec3e8c
parente5691cc9170bcd6c684715c2755d919c5a16fea2
Fix DROP {DATABASE,TABLESPACE} on Windows.

Previously, it was possible for DROP DATABASE, DROP TABLESPACE and ALTER
DATABASE SET TABLESPACE to fail because other backends still had file
handles open for dropped tables.  Windows won't allow a directory
containing unlinked-but-still-open files to be unlinked.  Tackle this
problem by forcing all backends to close all smgr fds.  No change for
Unix systems, which don't suffer from the problem, but the new code path
can be tested by Unix-based developers by defining
USE_BARRIER_SMGRRELEASE explicitly.

It's possible that PROCSIGNAL_BARRIER_SMGRRELEASE will have more
bug-fixing applications soon (under discussion).  Note that this is the
first user of the ProcSignalBarrier mechanism from commit 16a4e4aec.  It
could in principle be back-ed as far as 14, but since field
complaints are rare and ProcSignalBarrier hasn't been battle-tested,
that seems like a bad idea.  Fix in master only, where these failures
have started to show up in automated testing due to new tests.

Suggested-by: Andres Freund <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Reviewed-by: Robert Haas <[email protected]>
Discussion: https://postgr.es/m/CA+hUKGLdemy2gBm80kz20GTe6hNVwoErE8KwcJk6-U56oStjtg@mail.gmail.com
src/backend/commands/dbcommands.c
src/backend/commands/tablespace.c
src/backend/storage/ipc/procsignal.c
src/backend/storage/smgr/md.c
src/backend/storage/smgr/smgr.c
src/include/pg_config_manual.h
src/include/storage/md.h
src/include/storage/procsignal.h
src/include/storage/smgr.h