Skip to content

Commit e6f9bf9

Browse files
committed
On Windows, force a checkpoint just before dropping a database's physical
files and directories. This ensures that the bgwriter will close any open file references it is holding for files therein, which is needed for the rmdir() to succeed. Andrew Dunstan and Tom Lane.
1 parent a7049b5 commit e6f9bf9

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/backend/commands/dbcommands.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.145 2004/10/17 20:47:20 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.146 2004/10/28 00:39:58 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -32,6 +32,7 @@
3232
#include "commands/tablespace.h"
3333
#include "mb/pg_wchar.h"
3434
#include "miscadmin.h"
35+
#include "postmaster/bgwriter.h"
3536
#include "storage/fd.h"
3637
#include "storage/freespace.h"
3738
#include "storage/sinval.h"
@@ -624,6 +625,14 @@ dropdb(const char *dbname)
624625
*/
625626
FreeSpaceMapForgetDatabase(db_id);
626627

628+
/*
629+
* On Windows, force a checkpoint so that the bgwriter doesn't hold any
630+
* open files, which would cause rmdir() to fail.
631+
*/
632+
#ifdef WIN32
633+
RequestCheckpoint(true);
634+
#endif
635+
627636
/*
628637
* Remove all tablespace subdirs belonging to the database.
629638
*/

src/backend/postmaster/bgwriter.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.9 2004/10/12 21:54:40 petere Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.10 2004/10/28 00:39:59 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -346,6 +346,15 @@ BackgroundWriterMain(void)
346346

347347
CreateCheckPoint(false, force_checkpoint);
348348

349+
/*
350+
* After any checkpoint, close all smgr files. This is so we
351+
* won't hang onto smgr references to deleted files
352+
* indefinitely. (It is safe to do this because this process
353+
* does not have a relcache, and so no dangling references
354+
* could remain.)
355+
*/
356+
smgrcloseall();
357+
349358
/*
350359
* Indicate checkpoint completion to any waiting backends.
351360
*/
@@ -359,15 +368,6 @@ BackgroundWriterMain(void)
359368
*/
360369
last_checkpoint_time = now;
361370

362-
/*
363-
* After any checkpoint, close all smgr files. This is so we
364-
* won't hang onto smgr references to deleted files
365-
* indefinitely. (It is safe to do this because this process
366-
* does not have a relcache, and so no dangling references
367-
* could remain.)
368-
*/
369-
smgrcloseall();
370-
371371
/* Nap for configured time before rechecking */
372372
n = 1;
373373
}

0 commit comments

Comments
 (0)