Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T7dBy-0005Fe-7p for pgsql-jdbc@postgresql.org; Sat, 01 Sep 2012 02:12:10 +0000 Received: from mbx.knossos.net.nz ([202.160.48.10]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T7dBt-00059D-WB for pgsql-jdbc@postgresql.org; Sat, 01 Sep 2012 02:12:09 +0000 Received: from [10.1.1.3] (60-234-150-59.bitstream.orcon.net.nz [60.234.150.59]) (authenticated bits=0) by mbx.knossos.net.nz (8.14.4/8.14.4) with ESMTP id q812Bi0c010357 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 1 Sep 2012 14:11:56 +1200 Message-ID: <50416EE0.7070408@archidevsys.co.nz> Date: Sat, 01 Sep 2012 14:11:44 +1200 From: Gavin Flower Organization: ArchiDevSys User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120824 Thunderbird/15.0 MIME-Version: 1.0 To: Craig Ringer CC: =?ISO-8859-1?Q?Werner_Donn=E9?= , pgsql-jdbc@postgresql.org Subject: Re: Streaming bytea implementation offered References: <6EA298B8-34D9-4832-A722-161911A22AB6@pincette.biz> <50415F0B.9020504@ringerc.id.au> In-Reply-To: <50415F0B.9020504@ringerc.id.au> Content-Type: multipart/alternative; boundary="------------020004050102090904020304" X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201209/4 X-Sequence-Number: 23240 This is a multi-part message in MIME format. --------------020004050102090904020304 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mbx.knossos.net.nz id q812Bi0c010357 On 01/09/12 13:04, Craig Ringer wrote: > On 09/01/2012 12:49 AM, Werner Donn=E9 wrote: >> Hello, >> >> I have modified version 9.1-902 of the driver in order for it to=20 >> stream bytea values when calling ResultSet.getBinaryStream(). The=20 >> implementation is here: >> >> http://www.pincette.biz/home/werner/postgresql-jdbc-9.1-902-patched.sr= c.zip=20 >> >> >> When a bytea value is larger than 1MB it is streamed to a temporary=20 >> file instead of being copied in the "answer" array. When the stream=20 >> is later accessed, either with "getBinaryInputStream" or "getBytes",=20 >> the bytes are fetched from the temporary file, which is subsequently=20 >> deleted. The "getBytes" method copies the bytes in the result array,=20 >> while "getBinaryInputStream" returns a FileInputStream with an=20 >> overridden "close" method that deletes the temporary file > > Sounds potentially good, but what happens if it's run inside the=20 > SecurityManager, or in an environment with no ability to create=20 > temporary files? > > What about out-of-disk causing failures that wouldn't occur with OOM? > > Do you propose to make this always-on, or configurable? > > How (if at all) does this interact with JDBC-standard BLOB support,=20 > and with large objects? > > > If you'd like this change considered, it'd be great if you could=20 > create a patch against the current PgJDBC sources, rather than just=20 > publishing patched sources. I'd recommend that you clone PgJDBC=20 > (https://github.com/pgjdbc/pgjdbc): > > git://github.com/pgjdbc/pgjdbc.git > > then copy your changes into that working tree and use `git diff`.=20 > Alternately, you can , `git add` them, `git commit`, then use `git=20 > format-patch` to get a diff; see > > http://www.kernel.org/pub/software/scm/git/docs/git-format-patch.html > > Make sure not to include any generated files, and please add some unit=20 > tests demonstrating the functionality if possible. > > --=20 > Craig Ringer > > Hi, BACKGROUND: I am working on a project at the University of Auckland,=20 that will involve serving images over the web from JBoss backed by=20 PostgreSQL (probably 9.2, though 9.1 is sufficient) running on a Linux=20 box. We are talking transactions per minute rather than per second, but=20 the SQL queries are likely to be quite complicated and involve many=20 images -- though detailed database design is yet to be done. We will=20 probably have a reasonable amount of RAM So in the future, I may have need of the functionality discussed. At this stage, I think I would prefer to avoid work files as much as=20 possible, so having the _threshold for deciding when to use a temporary=20 file being configurable_ would be appreciated. Currently the test image=20 files are under 1 MB, but I expect larger images will need to be dealt wi= th. Cheers, Gavin --------------020004050102090904020304 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
On 01/09/12 13:04, Craig Ringer wrote:
On 09/01/2012 12:49 AM, Werner Donné wrote:
Hello,

I have modified version 9.1-902 of the driver in order for it to stream bytea values when calling ResultSet.getBinaryStream(). The implementation is here:

http://www.pincette.biz/home/werner/postgresql-jdbc-9.1-902-patched.src.zip

When a bytea value is larger than 1MB it is streamed to a temporary file instead of being copied in the "answer" array. When the stream is later accessed, either with "getBinaryInputStream" or "getBytes", the bytes are fetched from the temporary file, which is subsequently deleted. The "getBytes" method copies the bytes in the result array, while "getBinaryInputStream" returns a FileInputStream with an overridden "close" method that deletes the temporary file

Sounds potentially good, but what happens if it's run inside the SecurityManager, or in an environment with no ability to create temporary files?

What about out-of-disk causing failures that wouldn't occur with OOM?

Do you propose to make this always-on, or configurable?

How (if at all) does this interact with JDBC-standard BLOB support, and with large objects?


If you'd like this change considered, it'd be great if you could create a patch against the current PgJDBC sources, rather than just publishing patched sources. I'd recommend that you clone PgJDBC (https://github.com/pgjdbc/pgjdbc):

    git://github.com/pgjdbc/pgjdbc.git

then copy your changes into that working tree and use `git diff`. Alternately, you can , `git add` them, `git commit`, then use `git format-patch` to get a diff; see

    http://www.kernel.org/pub/software/scm/git/docs/git-format-patch.html

Make sure not to include any generated files, and please add some unit tests demonstrating the functionality if possible.

--
Craig Ringer


Hi,

BACKGROUND: I am working on a project at the University of Auckland, that will involve serving images over the web from JBoss backed by PostgreSQL (probably 9.2, though 9.1 is sufficient) running on a Linux box.  We are talking transactions per minute rather than per second, but the SQL queries are likely to be quite complicated and involve many images – though detailed database design is yet to be done.  We will probably have a reasonable amount of RAM

So in the future, I may have need of the functionality discussed.

At this stage, I think I would prefer to avoid work files as much as possible, so having the threshold for deciding when to use a temporary file being configurable would be appreciated.  Currently the test image files are under 1 MB, but I expect larger images will need to be dealt with.

Cheers,
Gavin



--------------020004050102090904020304--