postgresql/src
Thomas Munro 46d9bfb0a6 Fix race between DROP TABLESPACE and checkpointing.
Commands like ALTER TABLE SET TABLESPACE may leave files for the next
checkpoint to clean up.  If such files are not removed by the time DROP
TABLESPACE is called, we request a checkpoint so that they are deleted.
However, there is presently a window before checkpoint start where new
unlink requests won't be scheduled until the following checkpoint.  This
means that the checkpoint forced by DROP TABLESPACE might not remove the
files we expect it to remove, and the following ERROR will be emitted:

	ERROR:  tablespace "mytblspc" is not empty

To fix, add a call to AbsorbSyncRequests() just before advancing the
unlink cycle counter.  This ensures that any unlink requests forwarded
prior to checkpoint start (i.e., when ckpt_started is incremented) will
be processed by the current checkpoint.  Since AbsorbSyncRequests()
performs memory allocations, it cannot be called within a critical
section, so we also need to move SyncPreCheckpoint() to before
CreateCheckPoint()'s critical section.

This is an old bug, so back-patch to all supported versions.

Author: Nathan Bossart <nathandbossart@gmail.com>
Reported-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Thomas Munro <thomas.munro@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20220215235845.GA2665318%40nathanxps13
2022-03-16 17:20:24 +13:00
..
backend Fix race between DROP TABLESPACE and checkpointing. 2022-03-16 17:20:24 +13:00
bin Change HAVE_LIBLZ4 and HAVE_LIBZSTD tests to USE_LZ4 and USE_ZSTD. 2022-03-15 13:06:25 -04:00
common Use bitwise rotate functions in more places 2022-02-20 13:22:08 +07:00
fe_utils Clean up assorted failures under clang's -fsanitize=undefined checks. 2022-03-03 18:13:24 -05:00
include Fix waiting in RegisterSyncRequest(). 2022-03-16 15:35:16 +13:00
interfaces Fix collection of typos in the code and the documentation 2022-03-15 11:29:35 +09:00
makefiles Add NO_INSTALL option to pgxs 2021-05-27 13:58:29 +02:00
pl plpython: Restore alternative output for plpython_error test. 2022-03-08 10:34:06 -08:00
port Simplify coding around path_contains_parent_reference(). 2022-01-31 13:53:38 -05:00
template Further tweaking of PG_SYSROOT heuristics for macOS. 2021-01-20 12:07:23 -05:00
test Fix collection of typos in the code and the documentation 2022-03-15 11:29:35 +09:00
timezone Update copyright for 2022 2022-01-07 19:04:57 -05:00
tools dshash: Add sequential scan support. 2022-03-10 12:57:05 -08:00
tutorial Update copyright for 2022 2022-01-07 19:04:57 -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 Run tap tests in src/interfaces/libpq. 2022-02-26 16:51:47 -08:00
Makefile.shlib AIX: Fix missing libpq symbols by respecting SHLIB_EXPORTS. 2021-09-06 11:27:59 -07:00
nls-global.mk Add errhint_plural() function and make use of it 2021-03-31 09:16:25 +02:00