diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index 309378ae54..8527593dd1 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -4955,25 +4955,23 @@ pgstat_write_statsfiles(bool permanent, bool allDbs) (errcode_for_file_access(), errmsg("could not write temporary statistics file \"%s\": %m", tmpfile))); - FreeFile(fpout); - unlink(tmpfile); } - else if (FreeFile(fpout) < 0) + if (FreeFile(fpout) < 0) { ereport(LOG, (errcode_for_file_access(), errmsg("could not close temporary statistics file \"%s\": %m", tmpfile))); - unlink(tmpfile); } - else if (rename(tmpfile, statfile) < 0) + if (rename(tmpfile, statfile) < 0) { ereport(LOG, (errcode_for_file_access(), errmsg("could not rename temporary statistics file \"%s\" to \"%s\": %m", tmpfile, statfile))); - unlink(tmpfile); } + else + unlink(tmpfile); if (permanent) unlink(pgstat_stat_filename); @@ -5090,25 +5088,23 @@ pgstat_write_db_statsfile(PgStat_StatDBEntry *dbentry, bool permanent) (errcode_for_file_access(), errmsg("could not write temporary statistics file \"%s\": %m", tmpfile))); - FreeFile(fpout); - unlink(tmpfile); } - else if (FreeFile(fpout) < 0) + if (FreeFile(fpout) < 0) { ereport(LOG, (errcode_for_file_access(), errmsg("could not close temporary statistics file \"%s\": %m", tmpfile))); - unlink(tmpfile); } - else if (rename(tmpfile, statfile) < 0) + if (rename(tmpfile, statfile) < 0) { ereport(LOG, (errcode_for_file_access(), errmsg("could not rename temporary statistics file \"%s\" to \"%s\": %m", tmpfile, statfile))); - unlink(tmpfile); - } + } + else + unlink(tmpfile); if (permanent) {