Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0da33c7

Browse files
committed
In pg_ctl, work around ERROR_SHARING_VIOLATION on the postmaster log file.
On Windows, we use CMD.EXE to redirect the postmaster's stdout/stderrinto a log file. CMD.EXE will open that file with non-sharing-friendlyparameters, and the file will remain open for a short time after thepostmaster has removed postmaster.pid. This can result in anERROR_SHARING_VIOLATION failure if we attempt to start a new postmasterimmediately with the same log file (e.g. during "pg_ctl restart").This seems to explain intermittent buildfarm failures we've been seeingon Windows machines.To fix, just open and close the log file using our own pgwin32_open(),which will wait if necessary to avoid the failure. (Perhaps somedaywe should stop using CMD.EXE, but that would be a far more complexpatch, and it doesn't seem worth the trouble ... yet.)Back-patch to v12. This only solves the problem when frontend fopen()is redirected to pgwin32_fopen(), which has only been true since commit0ba06e0. Hence, no point in back-patching further, unless we careto back-patch that change too.Diagnosis and patch by Alexander Lakhin (bug #16154).Discussion:https://postgr.es/m/16154-1ccf0b537b24d5e0@postgresql.org
1 parent5a20b02 commit0da33c7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,29 @@ start_postmaster(void)
519519
comspec="CMD";
520520

521521
if (log_file!=NULL)
522+
{
523+
/*
524+
* First, touch the log file. The main value of this is that if the
525+
* file is still locked by a previous postmaster run, we'll wait until
526+
* it comes free, instead of failing with ERROR_SHARING_VIOLATION.
527+
* (It'd be better to open the file in a sharing-friendly mode, but we
528+
* can't use CMD.EXE to do that, so work around it. Note that the
529+
* previous postmaster will still have the file open for a short time
530+
* after removing postmaster.pid.)
531+
*/
532+
FILE*fd=fopen(log_file,"a");
533+
534+
if (fd==NULL)
535+
{
536+
write_stderr(_("%s: could not create log file \"%s\": %s\n"),
537+
progname,log_file,strerror(errno));
538+
exit(1);
539+
}
540+
fclose(fd);
541+
522542
snprintf(cmd,MAXPGPATH,"\"%s\" /C \"\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1\"",
523543
comspec,exec_path,pgdata_opt,post_opts,DEVNULL,log_file);
544+
}
524545
else
525546
snprintf(cmd,MAXPGPATH,"\"%s\" /C \"\"%s\" %s%s < \"%s\" 2>&1\"",
526547
comspec,exec_path,pgdata_opt,post_opts,DEVNULL);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp