aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2008-10-09 10:34:22 +0000
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2008-10-09 10:34:22 +0000
commit95f3c355bd0c2f6d4bbd4314cdf14b8019d03892 (patch)
tree7dad281a559fc122784df0d1934a36e23e5be229 /src
parent3c66048adbdc0ab95b9f8e8efc55eb6cb65dca08 (diff)
downloadpostgresql-95f3c355bd0c2f6d4bbd4314cdf14b8019d03892.tar.gz
postgresql-95f3c355bd0c2f6d4bbd4314cdf14b8019d03892.zip
Force a checkpoint in CREATE DATABASE before starting to copy the files,
to process any pending unlinks for the source database. Before, if you dropped a relation in the template database just before CREATE DATABASE, and a checkpoint happened during copydir(), the checkpoint might delete a file that we're just about to copy, causing lstat() in copydir() to fail with ENOENT. Backpatch to 8.3, where the pending unlinks were introduced. Per report by Matthew Wakeling and analysis by Tom Lane.
Diffstat (limited to 'src')
-rw-r--r--src/backend/commands/dbcommands.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 3869b041966..df86095b1a1 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.204.2.3 2008/04/18 17:05:53 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.204.2.4 2008/10/09 10:34:22 heikki Exp $
*
*-------------------------------------------------------------------------
*/
@@ -450,10 +450,15 @@ createdb(const CreatedbStmt *stmt)
copyTemplateDependencies(src_dboid, dboid);
/*
- * Force dirty buffers out to disk, to ensure source database is
- * up-to-date for the copy.
+ * Force a checkpoint before starting the copy. This will force dirty
+ * buffers out to disk, to ensure source database is up-to-date on disk
+ * for the copy. FlushDatabaseBuffers() would suffice for that, but we
+ * also want to process any pending unlink requests. Otherwise, if a
+ * checkpoint happened while we're copying files, a file might be deleted
+ * just when we're about to copy it, causing the lstat() call in copydir()
+ * to fail with ENOENT.
*/
- FlushDatabaseBuffers(src_dboid);
+ RequestCheckpoint(CHECKPOINT_IMMEDIATE | CHECKPOINT_FORCE | CHECKPOINT_WAIT);
/*
* Once we start copying subdirectories, we need to be able to clean 'em