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

Commit8fa4a1a

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 parentd493bed commit8fa4a1a

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

‎doc/src/sgml/monitoring.sgml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,11 @@ postgres 27093 0.0 0.0 30096 2752 ? Ss 11:34 0:00 postgres: ser
15191519
<entry><literal>TwophaseFileWrite</literal></entry>
15201520
<entry>Waiting for a write of a two phase state file.</entry>
15211521
</row>
1522+
<row>
1523+
<entry><literal>VersionFileSync</literal></entry>
1524+
<entry>Waiting for the version file to reach durable storage while
1525+
creating a database.</entry>
1526+
</row>
15221527
<row>
15231528
<entry><literal>VersionFileWrite</literal></entry>
15241529
<entry>Waiting for the version file to be written while creating a database.</entry>

‎src/backend/commands/dbcommands.c

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

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

‎src/backend/utils/activity/wait_event.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,9 @@ pgstat_get_wait_io(WaitEventIO w)
702702
caseWAIT_EVENT_TWOPHASE_FILE_WRITE:
703703
event_name="TwophaseFileWrite";
704704
break;
705+
caseWAIT_EVENT_VERSION_FILE_SYNC:
706+
event_name="VersionFileSync";
707+
break;
705708
caseWAIT_EVENT_VERSION_FILE_WRITE:
706709
event_name="VersionFileWrite";
707710
break;

‎src/include/utils/wait_event.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ typedef enum
229229
WAIT_EVENT_WAL_READ,
230230
WAIT_EVENT_WAL_SYNC,
231231
WAIT_EVENT_WAL_SYNC_METHOD_ASSIGN,
232-
WAIT_EVENT_WAL_WRITE
232+
WAIT_EVENT_WAL_WRITE,
233+
WAIT_EVENT_VERSION_FILE_SYNC
233234
}WaitEventIO;
234235

235236

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp