From: Michael Paquier Date: Wed, 17 Jul 2024 02:50:36 +0000 (+0900) Subject: Make write of pgstats file durable at shutdown X-Git-Tag: REL_18_BETA1~2387 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=ec678692f6d0a8b05b86ca08e96b51e4063cba32;p=postgresql.git 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 --- diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c index ed7baa6e046..2e22bf27078 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -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); } }