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

Skip to content

Commit e8b4a23

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 4d1dd8d commit e8b4a23

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/backend/utils/init/miscinit.c

Lines changed: 19 additions & 1 deletion
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.137.4.3 2009/12/09 21:58:55 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.137.4.4 2010/08/16 17:33:22 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -787,6 +787,17 @@ CreateLockFile(const char *filename, bool amPostmaster,
787787
(errcode_for_file_access(),
788788
errmsg("could not write lock file \"%s\": %m", filename)));
789789
}
790+
if (pg_fsync(fd))
791+
{
792+
int save_errno = errno;
793+
794+
close(fd);
795+
unlink(filename);
796+
errno = save_errno;
797+
ereport(FATAL,
798+
(errcode_for_file_access(),
799+
errmsg("could not write lock file \"%s\": %m", filename)));
800+
}
790801
if (close(fd))
791802
{
792803
int save_errno = errno;
@@ -950,6 +961,13 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
950961
close(fd);
951962
return;
952963
}
964+
if (pg_fsync(fd))
965+
{
966+
ereport(LOG,
967+
(errcode_for_file_access(),
968+
errmsg("could not write to file \"%s\": %m",
969+
directoryLockFile)));
970+
}
953971
if (close(fd))
954972
{
955973
ereport(LOG,

0 commit comments

Comments
 (0)
0