Fix two race conditions between the pending unlink mechanism that was put in
commite3ccce08b98a874b0f17fb5295479e2c6ae75240
authorheikki <heikki>
Fri, 18 Apr 2008 06:48:38 +0000 (18 06:48 +0000)
committerheikki <heikki>
Fri, 18 Apr 2008 06:48:38 +0000 (18 06:48 +0000)
tree5c7b54e109fbae9886043f96d718f60fac5933d0
parentdbac7ae9628d2f6ae306687e582939cf0ec382e1
Fix two race conditions between the pending unlink mechanism that was put in
place to prevent reusing relation OIDs before next checkpoint, and DROP
DATABASE. First, if a database was dropped, bgwriter would still try to unlink
the files that the rmtree() call by the DROP DATABASE command has already
deleted, or is just about to delete. Second, if a database is dropped, and
another database is created with the same OID, bgwriter would in the worst
case delete a relation in the new database that happened to get the same OID
as a dropped relation in the old database.

To fix these race conditions:
- make rmtree() ignore ENOENT errors. This fixes the 1st race condition.
- make ForgetDatabaseFsyncRequests forget unlink requests as well.
- force checkpoint on in dropdb on all platforms

Since ForgetDatabaseFsyncRequests() is asynchronous, the 2nd change isn't
enough on its own to fix the problem of dropping and creating a database with
same OID, but forcing a checkpoint on DROP DATABASE makes it sufficient.

Per Tom Lane's bug report and proposal. Backpatch to 8.3.
src/backend/commands/dbcommands.c
src/backend/storage/smgr/md.c
src/port/dirmod.c