summaryrefslogtreecommitdiffstats
path: root/src/backend/commands/dbcommands.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/backend/commands/dbcommands.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index 93f0c73..5ced6da 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -461,35 +461,12 @@ CreateDirAndVersionFile(char *dbpath, Oid dbid, Oid tsid, bool isRedo)
char buf[16];
/*
- * Prepare version data before starting a critical section.
- *
- * Note that we don't have to copy this from the source database; there's
- * only one legal value.
+ * Note that we don't have to copy version data from the source database;
+ * there's only one legal value.
*/
sprintf(buf, "%s\n", PG_MAJORVERSION);
nbytes = strlen(PG_MAJORVERSION) + 1;
- /* If we are not in WAL replay then write the WAL. */
- if (!isRedo)
- {
- xl_dbase_create_wal_log_rec xlrec;
- XLogRecPtr lsn;
-
- START_CRIT_SECTION();
-
- xlrec.db_id = dbid;
- xlrec.tablespace_id = tsid;
-
- XLogBeginInsert();
- XLogRegisterData((char *) (&xlrec),
- sizeof(xl_dbase_create_wal_log_rec));
-
- lsn = XLogInsert(RM_DBASE_ID, XLOG_DBASE_CREATE_WAL_LOG);
-
- /* As always, WAL must hit the disk before the data update does. */
- XLogFlush(lsn);
- }
-
/* Create database directory. */
if (MakePGDirectory(dbpath) < 0)
{
@@ -530,12 +507,35 @@ CreateDirAndVersionFile(char *dbpath, Oid dbid, Oid tsid, bool isRedo)
}
pgstat_report_wait_end();
+ pgstat_report_wait_start(WAIT_EVENT_VERSION_FILE_SYNC);
+ if (pg_fsync(fd) != 0)
+ ereport(data_sync_elevel(ERROR),
+ (errcode_for_file_access(),
+ errmsg("could not fsync file \"%s\": %m", versionfile)));
+ fsync_fname(dbpath, true);
+ pgstat_report_wait_end();
+
/* Close the version file. */
CloseTransientFile(fd);
- /* Critical section done. */
+ /* If we are not in WAL replay then write the WAL. */
if (!isRedo)
+ {
+ xl_dbase_create_wal_log_rec xlrec;
+
+ START_CRIT_SECTION();
+
+ xlrec.db_id = dbid;
+ xlrec.tablespace_id = tsid;
+
+ XLogBeginInsert();
+ XLogRegisterData((char *) (&xlrec),
+ sizeof(xl_dbase_create_wal_log_rec));
+
+ (void) XLogInsert(RM_DBASE_ID, XLOG_DBASE_CREATE_WAL_LOG);
+
END_CRIT_SECTION();
+ }
}
/*