Re: Is this a bug in pg_current_logfile() on Windows?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Kellerer <shammat(at)gmx(dot)net>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Is this a bug in pg_current_logfile() on Windows?
Date: 2020-07-08 16:41:36
Message-ID: 1716646.1594226496@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Thomas Kellerer <shammat(at)gmx(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2020-07-08 16:43:59 Re: PostgreSQL 12 - ERROR: could not rename file "pg_logical/snapshots/1A-7C00D890.snap.13594.tmp" to "pg_logical/snapshots/1A-7C00D890.snap": No space left on device
Previous Message Adrian Klaver 2020-07-08 16:20:52 Re: BigSerial and txid issuance

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2020-07-08 16:49:49 Re: Multi-byte character case-folding
Previous Message Alvaro Herrera 2020-07-08 16:33:41 Re: Multi-byte character case-folding