postgresql/src/backend
Thomas Munro 51e760e5a6 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:21:19 +13:00
..
access Fix race between DROP TABLESPACE and checkpointing. 2022-03-16 17:21:19 +13:00
bootstrap Skip WAL for new relfilenodes, under wal_level=minimal. 2020-04-04 12:25:34 -07:00
catalog Fix temporary object cleanup failing due to toast access without snapshot. 2022-02-21 08:59:30 -08:00
commands Check syscache result in AlterStatistics 2022-01-23 03:20:32 +01:00
executor Fix memory leak in IndexScan node with reordering 2022-02-14 03:32:34 +03:00
foreign Update copyrights for 2020 2020-01-01 12:21:45 -05:00
jit Back-patch LLVM 14 API changes. 2022-03-16 11:41:13 +13:00
lib Fix typo in comment 2021-04-20 14:36:41 +02:00
libpq Allow root-owned SSL private keys in libpq, not only the backend. 2022-03-02 11:57:02 -05:00
main Add PostgreSQL home page to --help output 2020-02-28 13:12:21 +01:00
nodes Clean up assorted failures under clang's -fsanitize=undefined checks. 2022-03-03 18:13:24 -05:00
optimizer Don't use_physical_tlist for an IOS with non-returnable columns. 2022-02-11 15:23:52 -05:00
parser Fix failure to validate the result of select_common_type(). 2022-01-29 11:41:12 -05:00
partitioning Avoid using ambiguous word "non-negative" in error messages. 2021-07-28 01:21:52 +09:00
po Translation updates 2022-02-07 13:36:22 +01:00
port Reject huge_pages=on if shared_memory_type=sysv. 2021-10-26 13:04:40 +13:00
postmaster Fix waiting in RegisterSyncRequest(). 2022-03-16 15:37:15 +13:00
regex Make pg_regexec() robust against out-of-range search_start. 2021-09-11 15:19:49 -04:00
replication Fix limitations on what SQL commands can be issued to a walsender. 2022-01-24 15:33:34 -05:00
rewrite Fix rewriter to set hasModifyingCTE correctly on rewritten queries. 2021-09-08 12:05:43 -04:00
snowball Update copyrights for 2020 2020-01-01 12:21:45 -05:00
statistics Build inherited extended stats on partitioned tables 2022-01-15 19:14:00 +01:00
storage Fix race between DROP TABLESPACE and checkpointing. 2022-03-16 17:21:19 +13:00
tcop Suppress warning about stack_base_ptr with late-model GCC. 2022-02-17 22:45:34 -05:00
tsearch Don't leak compiled regex(es) when an ispell cache entry is dropped. 2021-03-18 21:44:43 -04:00
utils Clean up assorted failures under clang's -fsanitize=undefined checks. 2022-03-03 18:13:24 -05:00
.gitignore
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Update copyrights for 2020 2020-01-01 12:21:45 -05:00
nls.mk Translation updates 2020-09-14 13:14:53 +02:00