Skip to content

Commit f8c81c5

Browse files
committed
In pg_upgrade, try a few times to open a log file.
If we call pg_ctl stop, the server might continue and thus hold a log file for a short time after it has deleted its pid file, (which is when pg_ctl will exit), and so a subsequent attempt to open the log file might fail. We therefore try to open it a few times, sleeping one second between tries, to give the server time to exit. This corrects an error that was observed on the buildfarm. Backpatched to 9.2,
1 parent 4c60b80 commit f8c81c5

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

contrib/pg_upgrade/exec.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,28 @@ exec_prog(const char *log_file, const char *opt_log_file,
6363
if (written >= MAXCMDLEN)
6464
pg_log(PG_FATAL, "command too long\n");
6565

66-
if ((log = fopen_priv(log_file, "a")) == NULL)
66+
log = fopen_priv(log_file, "a");
67+
68+
#ifdef WIN32
69+
{
70+
/*
71+
* "pg_ctl -w stop" might have reported that the server has
72+
* stopped because the postmaster.pid file has been removed,
73+
* but "pg_ctl -w start" might still be in the process of
74+
* closing and might still be holding its stdout and -l log
75+
* file descriptors open. Therefore, try to open the log
76+
* file a few more times.
77+
*/
78+
int iter;
79+
for (iter = 0; iter < 4 && log == NULL; iter++)
80+
{
81+
sleep(1);
82+
log = fopen_priv(log_file, "a");
83+
}
84+
}
85+
#endif
86+
87+
if (log == NULL)
6788
pg_log(PG_FATAL, "cannot write to log file %s\n", log_file);
6889
#ifdef WIN32
6990
fprintf(log, "\n\n");

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy