Re: BUG #18958: "pg_ctl start" allows subsequent CTRL-C key in cmd.exe to unexpectedly terminate cluster on Windows

Seva Zaslavsky <szaslavsky@mpcapitallp.com>

From: Seva Zaslavsky <szaslavsky@mpcapitallp.com>
To: "David G. Johnston" <david.g.johnston@gmail.com>, pgsql-bugs@lists.postgresql.org
Date: 2025-06-13T14:51:14Z
Lists: pgsql-bugs
Using the -l flag with "pg_ctl start"  resolves this issue.  This was a 
significant behavior change since PG 13.18.

David - Thank you for the quick response.  Would appreciate if you have 
any thoughts on another logging bug (or behavior change since PG 13.18) 
that I documented on June 11 in #18955.

On 6/13/2025 9:46 AM, David G. Johnston wrote:
> On Fri, Jun 13, 2025 at 6:34 AM PG Bug reporting form 
> <noreply@postgresql.org> wrote:
>
>     The following bug has been logged on the website:
>
>     Bug reference:      18958
>     Logged by:          Seva Zaslavsky
>     Email address: szaslavsky@mpcapitallp.com
>     PostgreSQL version: 17.5
>     Operating system:   Windows Server 2019
>     Description:
>
>     J:\Users\Public\PostgreSQL\data>"c:\Program
>     Files\PostgreSQL\17.5\bin\pg_ctl" start -D
>     "J:\Users\Public\PostgreSQL\data\5438" -o "-p 5438"
>     waiting for server to start....2025-06-13 08:44:06.019 EDT [10020]
>     [] LOG:
>     redirecting log output to logging collector process
>     2025-06-13 08:44:06.019 EDT [10020] [] HINT:  Future log output
>     will appear
>     in directory "pg_log".
>      done
>     server started
>
>
> A bit surprising I suppose, but documented.
>
> """
> start mode launches a new server. The server is started in the 
> background, and its standard input is attached to /dev/null (or nul on 
> Windows). On Unix-like systems, by default, the server's standard 
> output and standard error are sent to pg_ctl's standard output (not 
> standard error). The standard output of pg_ctl should then be 
> redirected to a file or piped to another process such as a log 
> rotating program like rotatelogs; otherwise postgres will write its 
> output to the controlling terminal (from the background) and will not 
> leave the shell's process group. On Windows, by default the server's 
> standard output and standard error are sent to the terminal. These 
> default behaviors can be changed by using -l to append the server's 
> output to a log file. Use of either -l or output redirection is 
> recommended.
> """
>
> Note the final sentence, neither of which was done here.
>
> In short, while the server configuration stopped sending log data to 
> stdout/stderr due to the log_collector directive pg_ctl has no 
> awareness of that happening and so keeps itself attached to the 
> process that launched it so the operator can see those streams.
>
> David J.
>