Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZWVWd-00005b-EA for pgsql-bugs@arkaria.postgresql.org; Mon, 31 Aug 2015 20:17:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZWVWd-0007Vi-0Y for pgsql-bugs@arkaria.postgresql.org; Mon, 31 Aug 2015 20:17:55 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZWQVD-0005gP-Uf for pgsql-bugs@postgresql.org; Mon, 31 Aug 2015 14:56:08 +0000 Received: from mail-wi0-x22a.google.com ([2a00:1450:400c:c05::22a]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZWQVB-0002rI-4O for pgsql-bugs@postgresql.org; Mon, 31 Aug 2015 14:56:06 +0000 Received: by wicmx12 with SMTP id mx12so2133842wic.0 for ; Mon, 31 Aug 2015 07:56:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=PrrUWRKXM3j1VGrYr4ZMUv99kvqCy5gPnadv9S1YIBw=; b=fPjrx0CUa2yDNkGwO2W0KxfPULo9H/QXXLfKM6jHBIjtzvuRjMh8Fpg7qdjBGOyWSN n8HEd412aZLaCIflS4ZGobLqh7u3dszSfdAJpxIWKr4LMOjugjdC0RwHcZk0mA2s50Qx LNWi8Rx4Bk1axmzgjkbC/Vl/IrB1R5zlnXUV7iFYO22/4P9oevTm16i/N/sTMsEaao8w WM+yjuxczSx2JRcLUpfdeeAZ+4Ibe6kMA/hrNGnmCn8Wh4v9aALmzscqtn6PR53Eilzz wcZbnBO4ya0pPTujVR7JMwSS1FFW++RyHyLB4ZOeeIvHIEaW3MVGA+l793NTPZgOIgmp Kuqw== X-Received: by 10.180.84.65 with SMTP id w1mr20478637wiy.62.1441032963628; Mon, 31 Aug 2015 07:56:03 -0700 (PDT) Received: from [192.168.1.38] (dsl-85-10-109-45.internet.lu. [85.10.109.45]) by smtp.googlemail.com with ESMTPSA id r19sm18396681wib.7.2015.08.31.07.56.02 for (version=TLSv1/SSLv3 cipher=OTHER); Mon, 31 Aug 2015 07:56:03 -0700 (PDT) Subject: Re: BUG #13594: pg_ctl.exe redirects stderr to Windows Events Log if stderr is redirected to pipe To: PostgreSQL mailing lists References: <20150828104658.2089.83265@wrigleys.postgresql.org> From: Egon Kocjan Message-ID: <55E46B04.7070102@gmail.com> Date: Mon, 31 Aug 2015 16:56:04 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 31.8.2015 8:51, Michael Paquier wrote: > On Fri, Aug 28, 2015 at 7:46 PM, wrote: >> 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 */ > > The last time I poked at that, switching to use pgwin32_is_service was > not that straight-forward as it is a backend-only routine, relying on > write_stderr, write_eventlog and write_console, and pg_ctl has its own > concept of those routines: > http://www.postgresql.org/message-id/CAB7nPqSxWcUFpzL4LaOZAt4k-FPM7fy6Et7p50w8S5NbRfCwFw@mail.gmail.com > But actually looking at it with fresh eyes it is not that complicated > if we switch backend/port/win32/security.c to port/win32security.c to > make pgwin32_is_service available as well for frontends. And it would > obviously still be an improvement to switch isatty() to > pgwin32_is_service() in pg_ctl.c, the trick being to remove the > dependency to write_stderr when pgwin32_is_admin is called from > frontend so as it does not interact badly with the existing logging > infrastructure of elog.c and the definition of write_stderr in > pg_ctl.c. Note that in any case we cannot rely on ereport when calling > pgwin32_is_service on backend because it is called very early at > process startup, so there is no need to dance with ifdef FRONTEND > there. > > This change is too invasive so I think that making it HEAD-only is > better, and that's a change of behavior. I should perhaps have split > the patch into two: one for the move to src/port, the other for pg_ctl > but it's not really a big deal. I'll add it to the next CF I think > that's worth considering it. > > Egon, would the patch attached help in your case? > I tested with these two changes: diff -ur postgresql-9.6devel.orig\src\bin\pg_ctl\pg_ctl.c postgresql-9.6devel\src\bin\pg_ctl\pg_ctl.c --- postgresql-9.6devel.orig\src\bin\pg_ctl\pg_ctl.c Mon Aug 31 13:16:51 2015 +++ postgresql-9.6devel\src\bin\pg_ctl\pg_ctl.c Mon Aug 31 15:12:54 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 (!pgwin32_is_service()) /* Running as a service */ + if (pgwin32_is_service()) /* Running as a service */ { char errbuf[2048]; /* Arbitrary size? */ @@ -2131,6 +2131,9 @@ progname = get_progname(argv[0]); set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_ctl")); start_time = time(NULL); + + write_stderr("%s: test test\n", + progname); /* * save argv[0] so do_start() can look for the postmaster if necessary. we 1) It now works ok for development under regular account. 2) However there is no output on stderr when pg_ctl is running as a subprocess of a service. So I would still have to patch pg_ctl if I want stderr. I haven't looked into elog.c yet, maybe stderr from there would be good to have as well? So far, pg_ctl output and pg_logs\* was enough for me to debug the installations. Technically, I could also monitor Windows event log and dump events on the fly into my report file. But it seems simpler to just patch PostgreSQL locally to force stderr and reuse all the logic from the Unix port... Thank you for looking into this, Egon -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs