pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Unable to copy large (>2GB) files using PostgreSQL 11 (Windows)
4+ messages / 3 participants
[nested] [flat]

* Unable to copy large (>2GB) files using PostgreSQL 11 (Windows)
@ 2018-11-02 18:46  Alistair Johnson <alistair.e.w.j@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Alistair Johnson @ 2018-11-02 18:46 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org

Hello,

I am unable to use psql's \COPY command to load in large text files on
Windows. Here are the steps I used to reproduce:

1. Install PostgreSQL 11.0 from enterprisedb
2. Create two files: test1.txt (2.4 GB) and test2.txt (1.8 GB) - content
doesn't matter
3. Run SQL Shell (psql)

postgres=# create table tbl (col int);
CREATE TABLE

postgres=# \COPY tbl FROM 'test1.txt'
could not stat file "test1.txt": Unknown error

postgres=# \COPY tbl from 'test2.txt'
(runs normally)

I believe the issue is related to `stat` not handling large files properly.
I installed PostgreSQL 10.5 Windows x86-64 from the EDB website, attempted
to reproduce, and *could not* reproduce the error, so I think this is a
PostgreSQL 11 specific bug.

-Alistair

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Unable to copy large (>2GB) files using PostgreSQL 11 (Windows)
@ 2018-11-02 23:35  Michael Paquier <michael@paquier.xyz>
  parent: Alistair Johnson <alistair.e.w.j@gmail.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Michael Paquier @ 2018-11-02 23:35 UTC (permalink / raw)
  To: Alistair Johnson <alistair.e.w.j@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org

On Fri, Nov 02, 2018 at 02:46:44PM -0400, Alistair Johnson wrote:
> I believe the issue is related to `stat` not handling large files properly.
> I installed PostgreSQL 10.5 Windows x86-64 from the EDB website, attempted
> to reproduce, and *could not* reproduce the error, so I think this is a
> PostgreSQL 11 specific bug.

You would be interested in this thread then:
https://www.postgresql.org/message-id/1803D792815FC24D871C00D17AE95905CF5099@g01jpexmbkw24

Windows portability problems with stat() makes this problem way harder
than it looks at first glance, because it also uses a "stat" structure
which is not able to store the size of files larger than 2GB.  I tried a
couple of solutions for that, but gave up because of how things got
easily dirty.  I don't think that we want to replace the "stat"
structure used all over the code for a "pg_stat" equivalent either, many
folks rely on the system definitions for many patches, so that would be
most likely forgotten and lead to extra bugs on Windows :(

If somebody is smart enough to design a patch for that one, please feel
free to send one..
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Unable to copy large (>2GB) files using PostgreSQL 11 (Windows)
@ 2018-11-03 11:11  Daniel Verite <daniel@manitou-mail.org>
  parent: Michael Paquier <michael@paquier.xyz>
  0 siblings, 1 reply; 4+ messages in thread

From: Daniel Verite @ 2018-11-03 11:11 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Alistair Johnson <alistair.e.w.j@gmail.com>; pgsql-bugs@lists.postgresql.org

	Michael Paquier wrote:

> Windows portability problems with stat() makes this problem way harder
> than it looks at first glance, because it also uses a "stat" structure
> which is not able to store the size of files larger than 2GB

FWIW I don't reproduce the problem with a self-compiled PostgreSQL 11.0
with the MSYS2/mingw64 toolchain on a Windows 10 64-bit desktop.

But I do get the error when using PG 11.0 packaged by
EDB and trying the same test on the same machine
(that is, \copy table from file with a file a bit over 2GB).

The error seems to be emited at the point of this fstat() call in
psql/copy.c:

	/* make sure the specified file is not a directory */
	if ((result = fstat(fileno(copystream), &st)) < 0)
		psql_error("could not stat file \"%s\": %s\n",
				   options->file, 

Note that it's fstat() rather than stat().
A quick git grep -w seems to show that fstat() doesn't go through
the same kind of aliasing that can make stat() a macro actually
calling pgwin32_safestat().


Best regards,
-- 
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Unable to copy large (>2GB) files using PostgreSQL 11 (Windows)
@ 2018-11-04 00:04  Michael Paquier <michael@paquier.xyz>
  parent: Daniel Verite <daniel@manitou-mail.org>
  0 siblings, 0 replies; 4+ messages in thread

From: Michael Paquier @ 2018-11-04 00:04 UTC (permalink / raw)
  To: Daniel Verite <daniel@manitou-mail.org>; +Cc: Alistair Johnson <alistair.e.w.j@gmail.com>; pgsql-bugs@lists.postgresql.org

On Sat, Nov 03, 2018 at 12:11:53PM +0100, Daniel Verite wrote:
> But I do get the error when using PG 11.0 packaged by
> EDB and trying the same test on the same machine
> (that is, \copy table from file with a file a bit over 2GB).

This API layer comes from MSVC compilation, mingw has its own way of
handling the stat() layer, which we could perhaps get inspiration
from..
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2018-11-04 00:04 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-11-02 18:46 Unable to copy large (>2GB) files using PostgreSQL 11 (Windows) Alistair Johnson <alistair.e.w.j@gmail.com>
2018-11-02 23:35 ` Michael Paquier <michael@paquier.xyz>
2018-11-03 11:11   ` Daniel Verite <daniel@manitou-mail.org>
2018-11-04 00:04     ` Michael Paquier <michael@paquier.xyz>

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