pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Александър Шопов <lists@kambanaria.org>
To: pgsql-jdbc@postgresql.org
Subject: Workarounds for getBinaryStream returning ByteArrayInputStream on bytea
Date: Wed, 24 Nov 2010 22:50:46 +0200
Message-ID: <1290631846.3659.9.camel@dalgonosko> (raw)

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





view thread (7+ messages)  latest in thread

Message-ID: <1290631846.3659.9.camel@dalgonosko>
Permalink:  ../1290631846.3659.9.camel@dalgonosko/
Also on:    postgresql.org/message-id/1290631846.3659.9.camel@dalgonosko

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: lists@kambanaria.org
  Subject: Re: Workarounds for getBinaryStream returning ByteArrayInputStream on bytea
  In-Reply-To: <1290631846.3659.9.camel@dalgonosko>
  References: <1290631846.3659.9.camel@dalgonosko>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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