Re: bytea size limit? - Mailing list pgsql-jdbc

From Dave Cramer
Subject Re: bytea size limit?
Date
Msg-id 1081735033.27404.496.camel@localhost.localdomain
Whole thread Raw
In response to Re: bytea size limit?  (Michael Privat <michael@ceci.mit.edu>)
Responses Re: bytea size limit?  (Oliver Jowett <oliver@opencloud.com>)
List 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@postgresql.org
> >>
>
--
Dave Cramer
519 939 0336
ICQ # 14675561


pgsql-jdbc by date:

Previous
From: Michael Privat
Date:
Subject: Re: bytea size limit?
Next
From: Oliver Jowett
Date:
Subject: Re: bytea size limit?