Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b6517a

Browse files
committed
Sync PG_VERSION file in CREATE DATABASE.
An OS crash could leave PG_VERSION empty or missing. The same symptomappeared in a backup by block device snapshot, taken after the nextcheckpoint and before the OS flushes the PG_VERSION blocks. Devicesnapshots are not a documented backup method, however. Back-patch tov15, where commit9c08aea introducedSTRATEGY=WAL_LOG and made it the default.Discussion:https://postgr.es/m/20240130195003.0a.nmisch@google.com
1 parentdf22071 commit0b6517a

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)

[8]ページ先頭

©2009-2025 Movatter.jp