Re: bytea size limit?

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Michael Privat <michael(at)ceci(dot)mit(dot)edu>
Cc: oliver(at)opencloud(dot)com, "pgsql-jdbc(at)postgresql(dot)org" <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: bytea size limit?
Date: 2004-04-12 01:57:13
Message-ID: 1081735033.27404.496.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Michael,

that doesn't surprise me, as the postgresql driver currently buffers
that internally, so you end up with two buffers of 1400000 bytes, have a
look through the archives for out of memory errors.

Dave
On Sun, 2004-04-11 at 21:48, Michael Privat wrote:
> Here's the full code sample for a minimalistic reproduction of the
> error. When you run it, if you increase the size (through the command
> line argument, you get an out of memory error. On my machine, after
> the size gets higher than about 1400000 bytes. I can make it happen every
> time.
>
> The DB table has two fields:
>
> id: integer
> data: bytea
>
>
> import java.sql.*;
> import java.io.*;
> import java.util.*;
>
> public class BlobTest {
> public static void main(String[] args) {
> Connection c = null;
> try {
> Class.forName("org.postgresql.Driver");
> String url = "jdbc:postgresql://myserver/mydb";
> c = DriverManager.getConnection(url, "myuser",
> "mypass");
>
> String sql = "INSERT INTO blobtest (id, data)
> VALUES(?,?)";
>
> int size = Integer.parseInt(args[0]);
>
> byte[] data = new byte[size];
>
> int id = Math.abs(new Random().nextInt());
>
> PreparedStatement stmt = c.prepareStatement(sql);
> stmt.setInt(1, id);
> stmt.setBinaryStream(2, new ByteArrayInputStream(data), data.length);
>
> stmt.executeUpdate();
>
> stmt.close();
> }
> catch(Throwable t) {
> t.printStackTrace();
> }
> finally {
> try { c.close(); } catch(Exception e) {}
> }
> }
> }
>
>
>
> Sunday, April 11, 2004, 9:42:16 PM, you wrote:
>
> DC> No, there is no size limit. However you may have better luck with
> DC> largeobjects.
> DC> Dave
> DC> On Sun, 2004-04-11 at 10:57, Michael Privat wrote:
> >> Hi. I have Java code that stores binary into the DB. When I use MS SQL
> >> Server 2000 (type image) it works fine. But when I use Postgres 7.4 it
> >> fails. Is there a size limit setting somewhere I need to set up?
> >>
> >> Thanks,
> >> Michael
> >>
> >>
> >> ---------------------------(end of
> >> broadcast)---------------------------
> >> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org
> >>
>
--
Dave Cramer
519 939 0336
ICQ # 14675561

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2004-04-12 02:44:47 Re: bytea size limit?
Previous Message Michael Privat 2004-04-12 01:48:42 Re: bytea size limit?