mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
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:
@ -1478,12 +1478,9 @@ pgstat_write_statsfile(void)
|
|||||||
tmpfile)));
|
tmpfile)));
|
||||||
unlink(tmpfile);
|
unlink(tmpfile);
|
||||||
}
|
}
|
||||||
else if (rename(tmpfile, statfile) < 0)
|
else if (durable_rename(tmpfile, statfile, LOG) < 0)
|
||||||
{
|
{
|
||||||
ereport(LOG,
|
/* durable_rename already emitted log message */
|
||||||
(errcode_for_file_access(),
|
|
||||||
errmsg("could not rename temporary statistics file \"%s\" to \"%s\": %m",
|
|
||||||
tmpfile, statfile)));
|
|
||||||
unlink(tmpfile);
|
unlink(tmpfile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user