BUG #13594: pg_ctl.exe redirects stderr to Windows Events Log if stderr is redirected to pipe

From: ekocjan(at)gmail(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #13594: pg_ctl.exe redirects stderr to Windows Events Log if stderr is redirected to pipe
Date: 2015-08-28 10:46:58
Message-ID: 20150828104658.2089.83265@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 13594
Logged by: Egon Kocjan
Email address: ekocjan(at)gmail(dot)com
PostgreSQL version: 9.5alpha2
Operating system: Windows 8.1
Description:

Hello

Context:

I run PostgreSQL as a part of a larger software package, pg_ctl is used to
control PostgreSQL. I capture all subprocess stderr logs to make a complete
report.

Problem:

On Windows (but not Unix!), PostgreSQL (any version) pg_ctl stops writing
into stderr if stderr is not a character device. As a result, it's not
possible to capture stderr of pg_ctl when using CreateProcess and
STARTUPINFO.hStdError. It might be possible to create a workaround with a
console buffer, but I think it's quite ugly:
http://www.codeproject.com/Articles/16163/Real-Time-Console-Output-Redirection

Solution:

Fix pg_ctl to write into stderr, if stderr is available and not just a
character device. Possibly, add a flag to force stderr. I don't have the big
picture, but this is the quick solution that I use right now:

diff -ur postgresql-9.3.6.orig\src\bin\pg_ctl\pg_ctl.c
postgresql-9.3.6\src\bin\pg_ctl\pg_ctl.c
--- postgresql-9.3.6.orig\src\bin\pg_ctl\pg_ctl.c Mon Feb 02 22:43:50 2015
+++ postgresql-9.3.6\src\bin\pg_ctl\pg_ctl.c Fri Aug 28 08:21:01 2015
@@ -215,7 +215,7 @@
* On Win32, we print to stderr if running on a console, or write to
* eventlog if running as a service
*/
- if (!isatty(fileno(stderr))) /* Running as a service */
+ if (getenv("PG_CTL_STDERR") == NULL && !isatty(fileno(stderr))) /* Running
as a service */
{
char errbuf[2048]; /* Arbitrary size? */

Then in my main process: _putenv("PG_CTL_STDERR=1")

I also noticed, that write_stderr() in src/backend/utils/error/elog.c uses a
different check (not isatty):

if (pgwin32_is_service()) /* Running as a service */

Thank you

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Martijn Meijer 2015-08-28 11:14:55 Possible data corruption
Previous Message Tatsuo Ishii 2015-08-28 07:09:21 Re: BUG #13593: ERROR: cannot find xlog functions