agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Eugene Yin <eugeneymail@ymail.com>
To: Andreas Joseph Krogh <andreas@visena.com>
Cc: Postgres List <pgsql-sql@postgresql.org>
Subject: Re: BYTEA
Date: Mon, 18 Jan 2016 15:40:26 +0000 (UTC)
Message-ID: <1592189786.7265044.1453131627096.JavaMail.yahoo@mail.yahoo.com> (raw)
In-Reply-To: <VisenaEmail.be.6d0348ce97ca0a34.15254ccbfe9@tc7-visena>
References: <VisenaEmail.be.6d0348ce97ca0a34.15254ccbfe9@tc7-visena>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
"if you only work with small-ish binary data, yes - BYTEA does the job."
--The goal is to save/retrieve the user's photos (JPEG, TIFF, GIF) and PDF files. The size of each file is less than
5 MB. For such purpose, is BYTEA ok? If not, then how about 1 MB each?
"whole byte-array is kept in memory, both in the JAVA-app and in PG"
--I believe in Java the GarbageCollector will clean it up (?). "Who" will then clean up the Pg side?
"whole byte-array is kept in memory, both in the JAVA-app and in PG"
--Does that mean for the OID, byte-array is NOT kept in memory (of JAVA-app or PG)? If so, where is it kept? And how they are got cleaned up?
Thanks
Eugene
On Monday, January 18, 2016 5:07 AM, Andreas Joseph Krogh <andreas@visena.com> wrote:
På søndag 17. januar 2016 kl. 23:13:09, skrev Thomas Kellerer <spam_eater@gmx.net>:
Andreas Joseph Krogh schrieb am 17.01.2016 um 23:09:
> > Do I really *Need to escape/encode binary data before sending to DB
> > then do the reverse after retrieving the data?*
> > *
> > *
> > If so, what (*Java*) codes should I use to achieve this goal (I am using
> > the Java to interface with the DB)?
>
> https://jdbc.postgresql.org/documentation/94/binary-data.html
>
> Save yourself the trouble and don't go this route. Use https://github.com/impossibl/pgjdbc-ng instead.
Can you elaborate?
Using the "official" JDBC driver with bytea column works just fine for me.
Depends on what "works" is.Using BLOBs (that is SQL-BLOB, not *ps.setBinaryStream etc.) with ps.setBlob/rs.getBlob and Connection.createBlob certainly doesn't work using the official driver. https://github.com/pgjdbc/pgjdbc/blob/master/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.j... public Blob createBlob() throws SQLException {
checkClosed();
throw org.postgresql.Driver.notImplemented(this.getClass(), "createBlob()");
} AFAIU this thread is about working with LARGE OBJECTS, not only binary data.Also, using BYTEA with LARGE objects (not just binary data) quickly leads to OutOfMemoryError. Which is why I recommend using pgjdbc-ng and real BLOBs (using OID) instead. It is true that get/setBinaryStream "works", in essence that it appears to do the jobb. The problem is that despite using get/setBinaryStream with BYTEA appears to use streams, it doesn't, and the whole byte-array is kept in memory, both in the JAVA-app and in PG. The only way to work with real streams all the way is using OID, not BYTEA. But, of course, if you only work with small-ish binary data, yes - BYTEA does the job. --Andreas Joseph KroghCTO / Partner - Visena ASMobile: +47 909 56 963andreas@visena.comwww.visena.com
=
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
view thread (17+ messages) latest in thread
Message-ID: <1592189786.7265044.1453131627096.JavaMail.yahoo@mail.yahoo.com>
Permalink: ../1592189786.7265044.1453131627096.JavaMail.yahoo@mail.yahoo.com/
Also on: postgresql.org/message-id/1592189786.7265044.1453131627096.JavaMail.yahoo@mail.yahoo.com
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: eugeneymail@ymail.com, andreas@visena.com
Subject: Re: BYTEA
In-Reply-To: <1592189786.7265044.1453131627096.JavaMail.yahoo@mail.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox