Fix old-fd issues using global barriers everywhere.
authorThomas Munro <[email protected]>
Sat, 7 May 2022 03:19:52 +0000 (15:19 +1200)
committerThomas Munro <[email protected]>
Sat, 7 May 2022 04:47:29 +0000 (16:47 +1200)
commite2f65f42555ff531c6d7c8f151526b4ef7c016f8
tree98c40e19efc4aa3c8670317c34261835d75f60c1
parentb74e94dc27fdbb13954f230b1d1298430afa6c0c
Fix old-fd issues using global barriers everywhere.

Commits 4eb21763 and b74e94dc introduced a way to force every backend to
close all relation files, to fix an ancient Windows-only bug.

This commit extends that behavior to all operating systems and adds
a couple of extra barrier points, to fix a totally different class of
bug: the reuse of relfilenodes in scenarios that have no other kind of
cache invalidation to prevent file descriptor mix-ups.

In all releases, data corruption could occur when you moved a database
to another tablespace and then back again.  Despite that, no back-patch
for now as the infrastructure required is too new and invasive.  In
master only, since commit aa010514, it could also happen when using
CREATE DATABASE with a user-supplied OID or via pg_upgrade.

Author: Andres Freund <[email protected]>
Reviewed-by: Robert Haas <[email protected]>
Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://postgr.es/m/20220209220004.kb3dgtn2x2k2gtdm%40alap3.anarazel.de
src/backend/commands/dbcommands.c
src/backend/commands/tablespace.c
src/include/pg_config_manual.h
src/test/recovery/Makefile
src/test/recovery/t/032_relfilenode_reuse.pl [new file with mode: 0644]