pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: ekocjan@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #13594: pg_ctl.exe redirects stderr to Windows Events Log if stderr is redirected to pipe
Date: Fri, 28 Aug 2015 10:46:58 +0000
Message-ID: <20150828104658.2089.83265@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      13594
Logged by:          Egon Kocjan
Email address:      ekocjan@gmail.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
inline patch 1: postgresql-9.3.6\src\bin\pg_ctl\pg_ctl.c (+1/-1 lines) download inline-1.patch--- 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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs

view thread (20+ messages)  latest in thread

Message-ID: <20150828104658.2089.83265@wrigleys.postgresql.org>
Permalink:  ../20150828104658.2089.83265@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20150828104658.2089.83265@wrigleys.postgresql.org

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: ekocjan@gmail.com
  Subject: Re: BUG #13594: pg_ctl.exe redirects stderr to Windows Events Log if stderr is redirected to pipe
  In-Reply-To: <20150828104658.2089.83265@wrigleys.postgresql.org>
  References: <20150828104658.2089.83265@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox