Tom Lane wrote:
>
>
>Try putting "RequestCheckpoint(true)" in dbcommands.c just before
>remove_dbtablespaces (about line 630).
>
>It looks like the bgwriter is not quite up-to-speed for this, either;
>you should rearrange things near line 350 of bgwriter.c so that
>smgrcloseall is performed before marking the checkpoint done in shmem.
>Else RequestCheckpoint could come back before the files are all closed.
>
>
seems to do the trick. patch attached.
>
>
>>I did wonder if there should be a call that instead of forcing a flush
>>could tell bgwriter just to forget about the file(s) because we're
>>discarding them. But that was just idle speculation - I haven't looked
>>at bgwriter at all.
>>
>>
>
>Not necessary, as long as you put the checkpoint after the DropBuffers
>call in dbcommands.c. The bgwriter won't find anything to write.
>
>
>
>
What about other databases? Or won't the forced checkpoint affect them?
cheers
andrew
Index: src/backend/commands/dbcommands.c
===================================================================
RCS file: /home/cvsmirror/pgsql/src/backend/commands/dbcommands.c,v
retrieving revision 1.145
diff -c -r1.145 dbcommands.c
*** src/backend/commands/dbcommands.c 17 Oct 2004 20:47:20 -0000 1.145
--- src/backend/commands/dbcommands.c 27 Oct 2004 23:48:10 -0000
***************
*** 32,37 ****
--- 32,38 ----
#include "commands/tablespace.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
+ #include "postmaster/bgwriter.h"
#include "storage/fd.h"
#include "storage/freespace.h"
#include "storage/sinval.h"
***************
*** 625,630 ****
--- 626,639 ----
FreeSpaceMapForgetDatabase(db_id);
/*
+ * On Windows, force a checkpoint so that the bgwriter doesn't hold any
+ * open files, which would cause rmdir() to fail.
+ */
+ #ifdef WIN32
+ RequestCheckpoint(true);
+ #endif
+
+ /*
* Remove all tablespace subdirs belonging to the database.
*/
remove_dbtablespaces(db_id);
Index: src/backend/postmaster/bgwriter.c
===================================================================
RCS file: /home/cvsmirror/pgsql/src/backend/postmaster/bgwriter.c,v
retrieving revision 1.9
diff -c -r1.9 bgwriter.c
*** src/backend/postmaster/bgwriter.c 12 Oct 2004 21:54:40 -0000 1.9
--- src/backend/postmaster/bgwriter.c 27 Oct 2004 23:05:10 -0000
***************
*** 347,352 ****
--- 347,361 ----
CreateCheckPoint(false, force_checkpoint);
/*
+ * After any checkpoint, close all smgr files. This is so we
+ * won't hang onto smgr references to deleted files
+ * indefinitely. (It is safe to do this because this process
+ * does not have a relcache, and so no dangling references
+ * could remain.)
+ */
+ smgrcloseall();
+
+ /*
* Indicate checkpoint completion to any waiting backends.
*/
BgWriterShmem->ckpt_done = BgWriterShmem->ckpt_started;
***************
*** 359,373 ****
*/
last_checkpoint_time = now;
- /*
- * After any checkpoint, close all smgr files. This is so we
- * won't hang onto smgr references to deleted files
- * indefinitely. (It is safe to do this because this process
- * does not have a relcache, and so no dangling references
- * could remain.)
- */
- smgrcloseall();
-
/* Nap for configured time before rechecking */
n = 1;
}
--- 368,373 ----