fyi: reading large BYTEA

Поиск
Список
Период
Сортировка
Искать

fyi: reading large BYTEA

От:
"Vance Maverick" <vmaverick@pgp.com>
Дата:
I'm working on reading large BYTEA fields from PostgreSQL 8.1.  As
various people have pointed out
,
ResultSet.getBinaryStream runs out of memory for large BYTEAs.
(PreparedStatement.setBinaryStream works fine.)

But there's a workaround: use the SUBSTRING function to read only a
chunk at a time, e.g.

  SELECT SUBSTRING(my_field FROM 1 FOR 10000) FROM my_table WHERE ...

This was suggested by Karsten Hilbert
.
I've had no trouble getting this to work -- as it happens, the chunkwise
reading strategy is consistent with what I was doing in the surrounding
code anyway.

In discussion today
, Tom
Lane pointed out that

  Recent releases will [perform better] if the column has been marked
  SET STORAGE EXTERNAL (before storing anything in it...)  See the
  ALTER TABLE reference page.

I tried this, and with the test sizes I was running (15 Mb data, 250K
chunk), the difference was not significant.  Reading was a bit faster,
but writing was considerably slower, adding up to a wash.  Your mileage
may vary.

    Vance
FAQ