Bug reference: 14634 Logged by: Henry Boehlert Email address: henry_boehlert@agilent.com PostgreSQL version: 9.6.2 Operating system: Windows Server 2012 R2 6.3.9600 Description:
Executing command pg_basebackup -D -F t writes its output to stdout, which is open in text mode, causing LF to be converted to CR LF thus corrupting the resulting archive.
To write the tar to stdout, on Windows stdout's mode should be temporarily switched to binary.
Thanks for reporting the issue. With the attached patch, I was able to extract the tar file that gets generated when the tar file is written into stdout. I tested the the compressed tar also.
This bug needs to be fixed in back branches also.
Seems reasonable. One question:
In the patch, you used "_setmode" function, while the calls in src/bin/pg_dump/pg_backup_archiver.c use "setmode". There are a few places in the backend that also use "_setmode". What's the difference? Should we change some of them to be consistent?
Actually there is no functional difference between these two functions.
one is a POSIX variant and another one is ISO C++ variant [1]. The support
of POSIX variant is deprecated in windows, because of this reason we should
use the _setmode instead of setmode.
I attached the patch to change the pg_dump code to use _setmode function
instead of _setmode to be consistent with other functions.