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

Commitee0e525

Browse files
committed
Arrange to fsync the contents of lockfiles (both postmaster.pid and the
socket lockfile) when writing them. The lack of an fsync here may wellexplain two different reports we've seen of corrupted lockfile contents,which doesn't particularly bother the running server but can prevent anew server from starting if the old one crashes. Per suggestion fromAlvaro.Back-patch to all supported versions.
1 parent66b1403 commitee0e525

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

‎src/backend/utils/init/miscinit.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.184 2010/04/20 23:48:47 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.185 2010/08/16 17:32:46 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -818,6 +818,9 @@ CreateLockFile(const char *filename, bool amPostmaster,
818818
* admin) but has left orphan backends behind.Check for this by
819819
* looking to see if there is an associated shmem segment that is
820820
* still in use.
821+
*
822+
* Note: because postmaster.pid is written in two steps, we might not
823+
* find the shmem ID values in it; we can't treat that as an error.
821824
*/
822825
if (isDDLock)
823826
{
@@ -881,7 +884,18 @@ CreateLockFile(const char *filename, bool amPostmaster,
881884
(errcode_for_file_access(),
882885
errmsg("could not write lock file \"%s\": %m",filename)));
883886
}
884-
if (close(fd))
887+
if (pg_fsync(fd)!=0)
888+
{
889+
intsave_errno=errno;
890+
891+
close(fd);
892+
unlink(filename);
893+
errno=save_errno;
894+
ereport(FATAL,
895+
(errcode_for_file_access(),
896+
errmsg("could not write lock file \"%s\": %m",filename)));
897+
}
898+
if (close(fd)!=0)
885899
{
886900
intsave_errno=errno;
887901

@@ -1042,7 +1056,14 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
10421056
close(fd);
10431057
return;
10441058
}
1045-
if (close(fd))
1059+
if (pg_fsync(fd)!=0)
1060+
{
1061+
ereport(LOG,
1062+
(errcode_for_file_access(),
1063+
errmsg("could not write to file \"%s\": %m",
1064+
DIRECTORY_LOCK_FILE)));
1065+
}
1066+
if (close(fd)!=0)
10461067
{
10471068
ereport(LOG,
10481069
(errcode_for_file_access(),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp