Make write of pgstats file durable at shutdown
This switches the pgstats write code to use durable_rename() rather than rename(). This ensures that the stats file's data is durable when the statistics are written, which is something only happening at shutdown now with the checkpointer doing the job. This could cause the statistics to be lost even after PostgreSQL is shut down, should a host failure happen, for example. Suggested-by: Konstantin Knizhnik Reviewed-by: Bertrand Drouvot Discussion: https://postgr.es/m/ZpDQTZ0cAz0WEbh7@paquier.xyz
This commit is contained in:
parent
4b74ebf726
commit
ec678692f6
@ -1478,12 +1478,9 @@ pgstat_write_statsfile(void)
|
||||
tmpfile)));
|
||||
unlink(tmpfile);
|
||||
}
|
||||
else if (rename(tmpfile, statfile) < 0)
|
||||
else if (durable_rename(tmpfile, statfile, LOG) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not rename temporary statistics file \"%s\" to \"%s\": %m",
|
||||
tmpfile, statfile)));
|
||||
/* durable_rename already emitted log message */
|
||||
unlink(tmpfile);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user