Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 879251337B64 for ; Wed, 24 Nov 2010 16:50:56 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 88947-08 for ; Wed, 24 Nov 2010 20:50:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.openintegra.com (mail.openintegra.com [193.68.120.3]) by mail.postgresql.org (Postfix) with ESMTP id DA2201337B34 for ; Wed, 24 Nov 2010 16:50:48 -0400 (AST) Received: from [10.142.89.106] (78-83-48-61.spectrumnet.bg [78.83.48.61]) (authenticated bits=0) by mail.openintegra.com (8.13.8/8.13.8) with ESMTP id oAOKolbn015943 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 24 Nov 2010 22:50:48 +0200 Subject: Workarounds for getBinaryStream returning ByteArrayInputStream on bytea From: =?UTF-8?Q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A=D1=80_?= =?UTF-8?Q?=D0=A8=D0=BE=D0=BF=D0=BE=D0=B2?= To: pgsql-jdbc@postgresql.org Content-Type: text/plain; charset="UTF-8" Date: Wed, 24 Nov 2010 22:50:46 +0200 Message-ID: <1290631846.3659.9.camel@dalgonosko> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 (2.32.1-1.fc14) Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201011/86 X-Sequence-Number: 21207 Hi everyone, I have a table containing file contents in bytea columns. The functionality I am trying to achieve is having a result set containing such columns, iterating over them and streaming them while zipping them. The problem is that I get ByteArrayInputStream from ResultSet.getBinaryStream. Thus iterating over many rows, each containing more than 10MB of data smashes the heap. In peak times I will have several such processes. I am using postgresql-8.4-702.jdbc3.jar against a PG 8.4.5 installation. I looked at the current source of driver. Jdbc3ResultSet extends AbstractJdbc3ResultSet extends AbstractJdbc2ResultSet which is the place that provides implementation for getBinaryStream which returns ByteArrayInputStream on bytea columns, and BlobInputStream on blob columns. On skimming it seems that BlobInputStream does indeed stream the bytes instead of reading them in memory (chunks for reads are 4k). So what am I options? Refactor the DB schema to use blobs rather than bytea? Is it impossible to have bytea read in chunks? Kind regards: al_shopov