Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YVzbJ-0001Ar-Ms for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Mar 2015 09:40:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YVzbJ-0005mO-4v for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Mar 2015 09:40:21 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YVzbI-0005lr-0T for pgsql-bugs@postgresql.org; Thu, 12 Mar 2015 09:40:20 +0000 Received: from mimolette.dalibo.net ([212.85.154.222]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YVzbE-0005JT-EI for pgsql-bugs@postgresql.org; Thu, 12 Mar 2015 09:40:18 +0000 Received: from dalibo.com (unknown [78.193.115.39]) by mimolette.dalibo.net (Postfix) with ESMTPSA id 93E8B5D000ED for ; Thu, 12 Mar 2015 10:40:14 +0100 (CET) From: Ronan Dunklau To: pgsql-bugs Subject: PGDump / copy bugs with "big lines" ? Date: Thu, 12 Mar 2015 10:39:01 +0100 Message-ID: <3859545.fB9yxixrjG@ronan.dunklau.fr> User-Agent: KMail/4.14.3 (Linux/3.19.0-gentoo; KDE/4.14.3; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart33961105.CbzQk5P09x"; micalg="pgp-sha256"; protocol="application/pgp-signature" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --nextPart33961105.CbzQk5P09x Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Hello. The documentation mentions the following limits for sizes: Maximum Field Size 1 GB Maximum Row Size 1.6 TB However, it seems like rows bigger than 1GB can't be COPYed out: ro=3D# create table test_text (c1 text, c2 text); CREATE TABLE ro=3D# insert into test_text (c1) VALUES (repeat('a', 536870912)); INSERT 0 1 ro=3D# update test_text set c2 =3D c1; UPDATE 1 Then, trying to dump or copy that results in the following error: ro=3D# COPY test_text TO '/tmp/test'; ERROR: out of memory D=C9TAIL : Cannot enlarge string buffer containing 536870913 bytes by 5= 36870912=20 more bytes. In fact, the same thing happens when using a dumb SELECT: ro=3D# select * from test_text ; ERROR: out of memory D=C9TAIL : Cannot enlarge string buffer containing 536870922 bytes by 5= 36870912=20 more bytes. In the case of COPY, the server uses a StringInfo to output the row. Th= e=20 problem is, a StringInfo is capped to MAX_ALLOC_SIZE (1GB - 1), but a r= ow=20 should be able to hold much more than that. So, is this a bug ? Or is there a caveat I would have missed in the=20 documentation ? We also hit a second issue, this time related to bytea encoding. This test case is a bit more complicated, since I had to use an externa= l=20 (client) program to insert my data. It involves inserting a string that= fit=20 into 1GB when encoded in escape format, but is larger than that in hex,= and=20 another string which fits in 1GB using the hex format, but is larger th= an that=20 in escape: from=20psycopg2 import connect from=20io import BytesIO conn =3D connect(dbname=3D"ro") cur =3D conn.cursor() fullcontent =3D BytesIO() # Write a binary string that weight less # than 1 GB when escape encoded, but more than # that if hex encoded for i in range(200): fullcontent.write(b"aaa" * 1000000) fullcontent.seek(0) cur.copy_from(fullcontent, "test_bytea") fullcontent.seek(0) fullcontent.truncate() # Write another binary string that weight # less than 1GB when hex encoded, but more than # that if escape encoded cur.execute("SET bytea_output =3D 'hex'") fullcontent.write(b"\\\\x") for i in range(300): fullcontent.write(b"00" * 1000000) fullcontent.seek(0) cur.copy_from(fullcontent, "test_bytea") cur.execute("COMMIT;") cur.close() I couldn't find an invocation of pg_dump which would allow me to dump b= oth=20 lines: ro@ronan_laptop /tmp % PGOPTIONS=3D"-c bytea_output=3Descape" pg_dump = =2DFc >=20 /dev/null pg_dump: Dumping the contents of table "test_bytea" failed: PQgetResult= ()=20 failed. pg_dump: Error message from server: ERROR: invalid memory alloc reques= t size=20 1200000001 pg_dump: The command was: COPY public.test_bytea (c1) TO stdout; ro@ronan_laptop /tmp % PGOPTIONS=3D"-c bytea_output=3Dhex" pg_dump -Fc= >=20 /dev/null pg_dump: Dumping the contents of table "test_bytea" failed: PQgetResult= ()=20 failed. pg_dump: Error message from server: ERROR: invalid memory alloc reques= t size=20 1200000003 pg_dump: The command was: COPY public.test_bytea (c1) TO stdout; Using a COPY with binary format works: ro=3D# COPY test_bytea TO '/tmp/test' WITH BINARY; I'm really surprised by those results: did I do anything wrong ? If it = is=20 indeed a bug, I'm surprised it wasn't discovered before. Thank you. =2D-=20 Ronan Dunklau http://dalibo.com - http://dalibo.org --nextPart33961105.CbzQk5P09x Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAABCAAGBQJVAV61AAoJEHSCNJt9TqXnpOIH+wWOjlsawwNCQl+Sbfl5YR69 vz53shbQut4yymdd+WpD99w6o5sfjQqDpKik9pTB9RNkxwXUlGr7pmanyY0+bBCF AP7k4z1+1lVb1B5kqOI0pYJzZjg5BV3rEhCdL9XUD2djPF8TFCBbDpppO5mfMZ/j MK8reH0UivE9qhG74e06QBAMtxaEy6Hf3T6i0XxcvXzHh255x5fb+49TrgbjD9LC ++T03qY+9A+H5ZpoDMa5S9uXFjTzjFg5UN7FT0J5ZB+DVpsex58dTluaVvPs8T/u qTpyUv7PwZzUzOmGu1hGSgOr6a3q1WSjyzTNcdB/30FFJ8RY/AJmSJpD8YX5OV4= =g4wr -----END PGP SIGNATURE----- --nextPart33961105.CbzQk5P09x--