pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode
9+ messages / 5 participants
[nested] [flat]
Commits from this thread:
2017-07-14 8046465c2e cedd25ae88 f20d58a6f7 240299806e f3633689f2 4b994a96c7 Fix pg_basebackup output to stdout on Windows.
* BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode
@ 2017-04-28 08:28 henry_boehlert@agilent.com
0 siblings, 1 reply; 9+ messages in thread
From: henry_boehlert@agilent.com @ 2017-04-28 08:28 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
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.
https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: [BUGS] BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode
@ 2017-05-03 04:32 Haribabu Kommi <kommi.haribabu@gmail.com>
parent: henry_boehlert@agilent.com
0 siblings, 2 replies; 9+ messages in thread
From: Haribabu Kommi @ 2017-05-03 04:32 UTC (permalink / raw)
To: henry_boehlert@agilent.com; +Cc: pgsql-bugs; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
[Adding -hackers mailing list]
On Fri, Apr 28, 2017 at 6:28 PM, <henry_boehlert@agilent.com> wrote:
> The following bug has been logged on the website:
>
> 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.
>
> https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx
>
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.
Regards,
Hari Babu
Fujitsu Australia
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Attachments:
pg_basebackup_tar_to_stdout_windows_fix.patch (application/octet-stream, 448B) download
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index e2a2ebb..86e015c 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -954,6 +954,10 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
*/
if (strcmp(basedir, "-") == 0)
{
+#ifdef WIN32
+ _setmode(fileno(stdout), _O_BINARY);
+#endif
+
#ifdef HAVE_LIBZ
if (compresslevel != 0)
{
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: [HACKERS] Re: BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode
@ 2017-05-03 05:20 Craig Ringer <craig@2ndquadrant.com>
parent: Haribabu Kommi <kommi.haribabu@gmail.com>
1 sibling, 2 replies; 9+ messages in thread
From: Craig Ringer @ 2017-05-03 05:20 UTC (permalink / raw)
To: Haribabu Kommi <kommi.haribabu@gmail.com>; +Cc: pgsql-bugs; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
On 3 May 2017 at 12:32, Haribabu Kommi <kommi.haribabu@gmail.com> wrote:
> [Adding -hackers mailing list]
>
> On Fri, Apr 28, 2017 at 6:28 PM, <henry_boehlert@agilent.com> wrote:
>>
>> The following bug has been logged on the website:
>>
>> 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.
>>
>> https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx
>
>
> 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.
We should do the same for pg_dump in -Fc mode.
--
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Re: [BUGS] BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode
@ 2017-05-03 12:33 Haribabu Kommi <kommi.haribabu@gmail.com>
parent: Craig Ringer <craig@2ndquadrant.com>
1 sibling, 0 replies; 9+ messages in thread
From: Haribabu Kommi @ 2017-05-03 12:33 UTC (permalink / raw)
To: Craig Ringer <craig@2ndquadrant.com>; +Cc: pgsql-bugs; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
On Wed, May 3, 2017 at 3:20 PM, Craig Ringer <craig@2ndquadrant.com> wrote:
> On 3 May 2017 at 12:32, Haribabu Kommi <kommi.haribabu@gmail.com> wrote:
> > [Adding -hackers mailing list]
> >
> > On Fri, Apr 28, 2017 at 6:28 PM, <henry_boehlert@agilent.com> wrote:
> >>
> >> The following bug has been logged on the website:
> >>
> >> 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.
> >>
> >> https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx
> >
> >
> > 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.
>
> We should do the same for pg_dump in -Fc mode.
There are no "CR LF" characters that are present in the dump file
that is created with custom format.
what is the problem do you see in custom format that needs similar
handling like pg_basebackup?
Regards,
Hari Babu
Fujitsu Australia
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: [HACKERS] Re: BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode
@ 2017-05-03 12:44 Ashutosh Sharma <ashu.coek88@gmail.com>
parent: Craig Ringer <craig@2ndquadrant.com>
1 sibling, 1 reply; 9+ messages in thread
From: Ashutosh Sharma @ 2017-05-03 12:44 UTC (permalink / raw)
To: Craig Ringer <craig@2ndquadrant.com>; +Cc: Haribabu Kommi <kommi.haribabu@gmail.com>; pgsql-bugs; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Hi Craig,
On Wed, May 3, 2017 at 10:50 AM, Craig Ringer <craig@2ndquadrant.com> wrote:
> On 3 May 2017 at 12:32, Haribabu Kommi <kommi.haribabu@gmail.com> wrote:
>> [Adding -hackers mailing list]
>>
>> On Fri, Apr 28, 2017 at 6:28 PM, <henry_boehlert@agilent.com> wrote:
>>>
>>> The following bug has been logged on the website:
>>>
>>> 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.
>>>
>>> https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx
>>
>>
>> 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.
>
> We should do the same for pg_dump in -Fc mode.
Did you meant -Fp mode. I think we are already setting stdout file to
binary mode if the output format is custom. Please refer to the
following code in parseArchiveFormat() and _allocAH() respectively
static ArchiveFormat
parseArchiveFormat(const char *format, ArchiveMode *mode)
{
...............
...............
else if (pg_strcasecmp(format, "c") == 0)
archiveFormat = archCustom;
else if (pg_strcasecmp(format, "custom") == 0)
archiveFormat = archCustom;
else if (pg_strcasecmp(format, "p") == 0)
archiveFormat = archNull;
else if (pg_strcasecmp(format, "plain") == 0)
archiveFormat = archNull;
...............
...............
}
static ArchiveHandle *
_allocAH(const char *FileSpec, const ArchiveFormat fmt,
const int compression, bool dosync, ArchiveMode mode,
SetupWorkerPtrType setupWorkerPtr)
{
...............
...............
#ifdef WIN32
if (fmt != archNull &&
(AH->fSpec == NULL || strcmp(AH->fSpec, "") == 0))
{
if (mode == archModeWrite)
setmode(fileno(stdout), O_BINARY);
else
setmode(fileno(stdin), O_BINARY);
}
#endif
..................
..................
}
Please confirm.
Meanwhile, I have unit tested the patch submitted by Hari upthread on
postgresql v10 and it works fine. Below are the steps that i have
followed to test Hari's patch.
Without patch:
==============
C:\Users\ashu\postgresql\TMP\test\bin>.\pg_basebackup.exe -D - -F t -X
none > base.tar
NOTICE: WAL archiving is not enabled; you must ensure that all required WAL seg
ments are copied through other means to complete the backup
C:\Users\ashu\postgresql\TMP\test\bin>tar -xf base.tar
tar: Skipping to next header
tar: Exiting with failure status due to previous errors
With patch:
===========
C:\Users\ashu\git-clone-postgresql\postgresql\TMP\test\bin>.\pg_basebackup.exe
-D - -F t -X none > base.tar
NOTICE: WAL archiving is not enabled; you must ensure that all required WAL seg
ments are copied through other means to complete the backup
C:\Users\ashu\postgresql\TMP\test\bin>cp base.tar ..\basebakup
C:\Users\ashu\postgresql\TMP\test\basebakup>tar -xf base.tar
C:\Users\ashu\postgresql\TMP\test\basebakup>ls
PG_VERSION pg_commit_ts pg_multixact pg_stat pg_wal
backup_label pg_dynshmem pg_notify pg_stat_tmp pg_xact
base pg_hba.conf pg_replslot pg_subtrans postgresql.auto.conf
base.tar pg_ident.conf pg_serial pg_tblspc postgresql.conf
global pg_logical pg_snapshots pg_twophase tablespace_map
--
With Regards,
Ashutosh Sharma
EnterpriseDB:http://www.enterprisedb.com
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: Re: [BUGS] BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode
@ 2017-05-04 00:30 Haribabu Kommi <kommi.haribabu@gmail.com>
parent: Ashutosh Sharma <ashu.coek88@gmail.com>
0 siblings, 0 replies; 9+ messages in thread
From: Haribabu Kommi @ 2017-05-04 00:30 UTC (permalink / raw)
To: Ashutosh Sharma <ashu.coek88@gmail.com>; +Cc: Craig Ringer <craig@2ndquadrant.com>; pgsql-bugs; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
On Wed, May 3, 2017 at 10:44 PM, Ashutosh Sharma <ashu.coek88@gmail.com>
wrote:
> Hi Craig,
>
> On Wed, May 3, 2017 at 10:50 AM, Craig Ringer <craig@2ndquadrant.com>
> wrote:
> > On 3 May 2017 at 12:32, Haribabu Kommi <kommi.haribabu@gmail.com> wrote:
> >> [Adding -hackers mailing list]
> >>
> >> On Fri, Apr 28, 2017 at 6:28 PM, <henry_boehlert@agilent.com> wrote:
> >>>
> >>> The following bug has been logged on the website:
> >>>
> >>> 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.
> >>>
> >>> https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx
> >>
> >>
> >> 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.
> >
> > We should do the same for pg_dump in -Fc mode.
>
> Did you meant -Fp mode. I think we are already setting stdout file to
> binary mode if the output format is custom. Please refer to the
> following code in parseArchiveFormat() and _allocAH() respectively
>
> static ArchiveFormat
> parseArchiveFormat(const char *format, ArchiveMode *mode)
> {
> ...............
> ...............
> else if (pg_strcasecmp(format, "c") == 0)
> archiveFormat = archCustom;
> else if (pg_strcasecmp(format, "custom") == 0)
> archiveFormat = archCustom;
>
> else if (pg_strcasecmp(format, "p") == 0)
> archiveFormat = archNull;
> else if (pg_strcasecmp(format, "plain") == 0)
> archiveFormat = archNull;
> ...............
> ...............
> }
>
> static ArchiveHandle *
> _allocAH(const char *FileSpec, const ArchiveFormat fmt,
> const int compression, bool dosync, ArchiveMode mode,
> SetupWorkerPtrType setupWorkerPtr)
> {
>
> ...............
> ...............
> #ifdef WIN32
> if (fmt != archNull &&
> (AH->fSpec == NULL || strcmp(AH->fSpec, "") == 0))
> {
> if (mode == archModeWrite)
> setmode(fileno(stdout), O_BINARY);
> else
> setmode(fileno(stdin), O_BINARY);
> }
> #endif
> ..................
> ..................
> }
>
> Please confirm.
>
I also think it is the plain text mode. There is no problem with text
mode file that contains the CR LF characters.
Meanwhile, I have unit tested the patch submitted by Hari upthread on
> postgresql v10 and it works fine. Below are the steps that i have
> followed to test Hari's patch.
>
> Without patch:
> ==============
> C:\Users\ashu\postgresql\TMP\test\bin>.\pg_basebackup.exe -D - -F t -X
> none > base.tar
> NOTICE: WAL archiving is not enabled; you must ensure that all required
> WAL seg
> ments are copied through other means to complete the backup
>
> C:\Users\ashu\postgresql\TMP\test\bin>tar -xf base.tar
> tar: Skipping to next header
> tar: Exiting with failure status due to previous errors
>
>
> With patch:
> ===========
> C:\Users\ashu\git-clone-postgresql\postgresql\TMP\
> test\bin>.\pg_basebackup.exe
> -D - -F t -X none > base.tar
> NOTICE: WAL archiving is not enabled; you must ensure that all required
> WAL seg
> ments are copied through other means to complete the backup
>
> C:\Users\ashu\postgresql\TMP\test\bin>cp base.tar ..\basebakup
>
> C:\Users\ashu\postgresql\TMP\test\basebakup>tar -xf base.tar
>
> C:\Users\ashu\postgresql\TMP\test\basebakup>ls
> PG_VERSION pg_commit_ts pg_multixact pg_stat pg_wal
> backup_label pg_dynshmem pg_notify pg_stat_tmp pg_xact
> base pg_hba.conf pg_replslot pg_subtrans
> postgresql.auto.conf
> base.tar pg_ident.conf pg_serial pg_tblspc postgresql.conf
> global pg_logical pg_snapshots pg_twophase tablespace_map
>
>
Thanks for the tests to verify the patch.
Regards,
Hari Babu
Fujitsu Australia
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: [BUGS] BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode
@ 2017-07-13 16:54 Heikki Linnakangas <hlinnaka@iki.fi>
parent: Haribabu Kommi <kommi.haribabu@gmail.com>
1 sibling, 1 reply; 9+ messages in thread
From: Heikki Linnakangas @ 2017-07-13 16:54 UTC (permalink / raw)
To: Haribabu Kommi <kommi.haribabu@gmail.com>; henry_boehlert@agilent.com; +Cc: pgsql-bugs; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
On 05/03/2017 07:32 AM, Haribabu Kommi wrote:
> [Adding -hackers mailing list]
>
> On Fri, Apr 28, 2017 at 6:28 PM, <henry_boehlert@agilent.com> wrote:
>
>> The following bug has been logged on the website:
>>
>> 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.
>>
>> https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx
>>
>
> 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?
- Heikki
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: [BUGS] BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode
@ 2017-07-14 02:27 Haribabu Kommi <kommi.haribabu@gmail.com>
parent: Heikki Linnakangas <hlinnaka@iki.fi>
0 siblings, 1 reply; 9+ messages in thread
From: Haribabu Kommi @ 2017-07-14 02:27 UTC (permalink / raw)
To: Heikki Linnakangas <hlinnaka@iki.fi>; +Cc: pgsql-bugs; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
On Fri, Jul 14, 2017 at 2:54 AM, Heikki Linnakangas <hlinnaka@iki.fi> wrote:
> On 05/03/2017 07:32 AM, Haribabu Kommi wrote:
>
>> [Adding -hackers mailing list]
>>
>> On Fri, Apr 28, 2017 at 6:28 PM, <henry_boehlert@agilent.com> wrote:
>>
>> The following bug has been logged on the website:
>>>
>>> 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.
>>>
>>> https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx
>>>
>>>
>> 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.
[1] -
https://docs.microsoft.com/en-gb/cpp/c-runtime-library/reference/posix-setmode
Regards,
Hari Babu
Fujitsu Australia
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Attachments: download all (2 files, .tar.gz)
0002-Replace-setmode-with-_setmode-function.patch (application/octet-stream, 1.1K) download
From df0399a5537fd876c7f8cde65307bf8b84b3b024 Mon Sep 17 00:00:00 2001
From: Hari <haribabuk@fast.au.fujitsu.com>
Date: Fri, 14 Jul 2017 11:34:21 +1000
Subject: [PATCH 2/2] Replace setmode with _setmode function
The Posix setmode function is deprecated in windows
and suggested to use _setmode function[1]. There is no
functionality change, just to make sure that we are
using _setmode in every place.
[1] - https://docs.microsoft.com/en-gb/cpp/c-runtime-library/reference/posix-setmode
---
src/bin/pg_dump/pg_backup_archiver.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c
index c24a0f0..b9d063a 100644
--- a/src/bin/pg_dump/pg_backup_archiver.c
+++ b/src/bin/pg_dump/pg_backup_archiver.c
@@ -2346,9 +2346,9 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
(AH->fSpec == NULL || strcmp(AH->fSpec, "") == 0))
{
if (mode == archModeWrite)
- setmode(fileno(stdout), O_BINARY);
+ _setmode(fileno(stdout), O_BINARY);
else
- setmode(fileno(stdin), O_BINARY);
+ _setmode(fileno(stdin), O_BINARY);
}
#endif
--
2.7.4.windows.1
0001-pg_basebackup-windows-tar-mode-to-stdout-fix.patch (application/octet-stream, 1.1K) download
From 8f201640af74c47918f5e9aee3a3e8ceeabe8eff Mon Sep 17 00:00:00 2001
From: Hari <haribabuk@fast.au.fujitsu.com>
Date: Fri, 14 Jul 2017 11:26:30 +1000
Subject: [PATCH 1/2] pg_basebackup windows tar mode to stdout fix
pg_basebackup with tar mode to stdout writes the
data to stdout in open text mode, that introduces the
CR LF characters that gets generated. Because of these
CR LF characters, the generated tar format cannot be
extracted.
To Fix this problem, change the stdout file into a
binary mode instead of text mode, that solves the problem
of geneating CR LF characters.
---
src/bin/pg_basebackup/pg_basebackup.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/bin/pg_basebackup/pg_basebackup.c b/src/bin/pg_basebackup/pg_basebackup.c
index 3ad0699..dfb9b5d 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -954,6 +954,10 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
*/
if (strcmp(basedir, "-") == 0)
{
+#ifdef WIN32
+ _setmode(fileno(stdout), _O_BINARY);
+#endif
+
#ifdef HAVE_LIBZ
if (compresslevel != 0)
{
--
2.7.4.windows.1
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode
@ 2017-07-14 13:07 Heikki Linnakangas <hlinnaka@iki.fi>
parent: Haribabu Kommi <kommi.haribabu@gmail.com>
0 siblings, 0 replies; 9+ messages in thread
From: Heikki Linnakangas @ 2017-07-14 13:07 UTC (permalink / raw)
To: Haribabu Kommi <kommi.haribabu@gmail.com>; +Cc: pgsql-bugs; pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
On 07/14/2017 05:27 AM, Haribabu Kommi wrote:
> On Fri, Jul 14, 2017 at 2:54 AM, Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>
>> On 05/03/2017 07:32 AM, Haribabu Kommi wrote:
>>
>>> [Adding -hackers mailing list]
>>>
>>> On Fri, Apr 28, 2017 at 6:28 PM, <henry_boehlert@agilent.com> wrote:
>>>
>>>> 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.
>>>>
>>>> https://msdn.microsoft.com/en-us/library/tw4k6df8.aspx
>>>
>>> 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.
Ok, committed and backpatched both patches. Thanks!
- Heikki
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2017-07-14 13:07 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-04-28 08:28 BUG #14634: On Windows pg_basebackup should write tar to stdout in binary mode henry_boehlert@agilent.com
2017-05-03 04:32 ` Haribabu Kommi <kommi.haribabu@gmail.com>
2017-05-03 05:20 ` Craig Ringer <craig@2ndquadrant.com>
2017-05-03 12:33 ` Haribabu Kommi <kommi.haribabu@gmail.com>
2017-05-03 12:44 ` Ashutosh Sharma <ashu.coek88@gmail.com>
2017-05-04 00:30 ` Haribabu Kommi <kommi.haribabu@gmail.com>
2017-07-13 16:54 ` Heikki Linnakangas <hlinnaka@iki.fi>
2017-07-14 02:27 ` Haribabu Kommi <kommi.haribabu@gmail.com>
2017-07-14 13:07 ` Heikki Linnakangas <hlinnaka@iki.fi>
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