Skip to content

Commit 0b6517a

Browse files
committed
Sync PG_VERSION file in CREATE DATABASE.
An OS crash could leave PG_VERSION empty or missing. The same symptom appeared in a backup by block device snapshot, taken after the next checkpoint and before the OS flushes the PG_VERSION blocks. Device snapshots are not a documented backup method, however. Back-patch to v15, where commit 9c08aea introduced STRATEGY=WAL_LOG and made it the default. Discussion: https://postgr.es/m/20240130195003.0a.nmisch@google.com
1 parent df22071 commit 0b6517a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/backend/commands/dbcommands.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ CreateDirAndVersionFile(char *dbpath, Oid dbid, Oid tsid, bool isRedo)
508508
}
509509
pgstat_report_wait_end();
510510

511+
pgstat_report_wait_start(WAIT_EVENT_VERSION_FILE_SYNC);
512+
if (pg_fsync(fd) != 0)
513+
ereport(data_sync_elevel(ERROR),
514+
(errcode_for_file_access(),
515+
errmsg("could not fsync file \"%s\": %m", versionfile)));
516+
fsync_fname(dbpath, true);
517+
pgstat_report_wait_end();
518+
511519
/* Close the version file. */
512520
CloseTransientFile(fd);
513521

src/backend/utils/activity/wait_event_names.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ TIMELINE_HISTORY_WRITE "Waiting for a write of a newly created timeline history
236236
TWOPHASE_FILE_READ "Waiting for a read of a two phase state file."
237237
TWOPHASE_FILE_SYNC "Waiting for a two phase state file to reach durable storage."
238238
TWOPHASE_FILE_WRITE "Waiting for a write of a two phase state file."
239+
VERSION_FILE_SYNC "Waiting for the version file to reach durable storage while creating a database."
239240
VERSION_FILE_WRITE "Waiting for the version file to be written while creating a database."
240241
WALSENDER_TIMELINE_HISTORY_READ "Waiting for a read from a timeline history file during a walsender timeline command."
241242
WAL_BOOTSTRAP_SYNC "Waiting for WAL to reach durable storage during bootstrapping."

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy