pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Kellerer <shammat@gmx.net>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Is this a bug in pg_current_logfile() on Windows?
Date: Wed, 08 Jul 2020 12:41:36 -0400
Message-ID: <1716646.1594226496@sss.pgh.pa.us> (raw)
In-Reply-To: <412ae8da-76bb-640f-039a-f3513499e53d@gmx.net>
References: <412ae8da-76bb-640f-039a-f3513499e53d@gmx.net>

Thomas Kellerer <shammat@gmx.net> writes:
> I noticed the following strage output when running Postgres 12.3 (not psql) on Windows

>     postgres=# select pg_current_logfile();
>              pg_current_logfile
>     ------------------------------------
>      pg_log/postgresql-2020-07-08.log\r
>     (1 row)

> Note the "\r" at the end of the file name.

Yeah, that seems like a bug.  I think the reason is that syslogger.c
does this when writing the log metafile:

	fh = fopen(LOG_METAINFO_DATAFILE_TMP, "w");
...
#ifdef WIN32
		/* use CRLF line endings on Windows */
		_setmode(_fileno(fh), _O_TEXT);
#endif

while misc.c only does this when reading the file:

	fd = AllocateFile(LOG_METAINFO_DATAFILE, "r");

Somehow, the reading file is being left in binary mode and thus it's
failing to convert \r\n back to plain \n.

Now the weird thing about that is I'd have expected "r" and "w" modes
to imply Windows text mode already, so that I'd have figured that
_setmode call to be a useless no-op.  Apparently on some Windows libc
implementations, it's not.  How was your installation built exactly?

			regards, tom lane





view thread (18+ messages)  latest in thread

Message-ID: <1716646.1594226496@sss.pgh.pa.us>
Permalink:  ../1716646.1594226496@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1716646.1594226496@sss.pgh.pa.us

 · 

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-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, shammat@gmx.net
  Subject: Re: Is this a bug in pg_current_logfile() on Windows?
  In-Reply-To: <1716646.1594226496@sss.pgh.pa.us>
  References: <412ae8da-76bb-640f-039a-f3513499e53d@gmx.net> <1716646.1594226496@sss.pgh.pa.us>

* 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