8000 Arrange to fsync the contents of lockfiles (both postmaster.pid and the · home201448/postgres@28d27cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 28d27cf

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 well explain two different reports we've seen of corrupted lockfile contents, which doesn't particularly bother the running server but can prevent a new server from starting if the old one crashes. Per suggestion from Alvaro. Back-patch to all supported versions.
1 parent 9217dee commit 28d27cf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/backend/utils/init/miscinit.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.116.2.2 2009/12/09 21:59:07 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.116.2.3 2010/08/16 17:33:30 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -721,6 +721,7 @@ CreateLockFile(const char *filename, bool amPostmaster,
721721
(errcode_for_file_access(),
722722
errmsg("could not write lock file \"%s\": %m", filename)));
723723
}
724+
pg_fsync(fd);
724725
close(fd);
725726

726727
/*
@@ -875,6 +876,7 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
875876
close(fd);
876877
return;
877878
}
879+
pg_fsync(fd);
878880
close(fd);
879881
}
880882

0 commit comments

Comments
 (0)
0