mirror of
https://github.com/postgres/postgres.git
synced 2025-06-23 14:01:44 +03:00
Avoid unlikely data-loss scenarios due to rename() without fsync.
Renaming a file using rename(2) is not guaranteed to be durable in face of crashes. Use the previously added durable_rename()/durable_link_or_rename() in various places where we previously just renamed files. Most of the changed call sites are arguably not critical, but it seems better to err on the side of too much durability. The most prominent known case where the previously missing fsyncs could cause data loss is crashes at the end of a checkpoint. After the actual checkpoint has been performed, old WAL files are recycled. When they're filled, their contents are fdatasynced, but we did not fsync the containing directory. An OS/hardware crash in an unfortunate moment could then end up leaving that file with its old name, but new content; WAL replay would thus not replay it. Reported-By: Tomas Vondra Author: Michael Paquier, Tomas Vondra, Andres Freund Discussion: 56583BDD.9060302@2ndquadrant.com Backpatch: All supported branches
This commit is contained in:
@ -741,11 +741,7 @@ pgss_shmem_shutdown(int code, Datum arg)
|
||||
/*
|
||||
* Rename file into place, so we atomically replace any old one.
|
||||
*/
|
||||
if (rename(PGSS_DUMP_FILE ".tmp", PGSS_DUMP_FILE) != 0)
|
||||
ereport(LOG,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not rename pg_stat_statement file \"%s\": %m",
|
||||
PGSS_DUMP_FILE ".tmp")));
|
||||
(void) durable_rename(PGSS_DUMP_FILE ".tmp", PGSS_DUMP_FILE, LOG);
|
||||
|
||||
/* Unlink query-texts file; it's not needed while shutdown */
|
||||
unlink(PGSS_TEXT_FILE);
|
||||
|
Reference in New Issue
Block a user