Thread: BLOBs

BLOBs

From
Eugene Yin
Date:
<div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida
Grande,sans-serif;font-size:13px"><h2 class="" id="yui_3_16_0_1_1452227859253_99029" style="color: rgb(230, 86, 0);
font-weight:normal; margin-top: 0px; margin-bottom: 0.6em; padding-top: 0.5em; padding-bottom: 0.17em;
border-bottom-width:1px; border-bottom-style: solid; border-bottom-color: rgb(170, 170, 170); font-size:
19.0499992370605px;font-family: sans-serif; line-height: 19.0499992370605px; background-image: none;
background-attachment:initial; background-size: initial; background-origin: initial; background-clip: initial;
background-position:initial; background-repeat: initial;"><span class="" id="yui_3_16_0_1_1452227859253_99130">The
followingstatement is excerpted from the </span></h2><h1 class="" id="yui_3_16_0_1_1452227859253_99133" style="color:
rgb(230,86, 0); font-weight: normal; margin-top: 0px; margin-bottom: 0.1em; padding-top: 0.5em; padding-bottom: 0.17em;
border-bottom-width:1px; border-bottom-style: solid; border-bottom-color: rgb(170, 170, 170); font-size:
23.8759994506836px;font-family: sans-serif; line-height: 19.0499992370605px; background: none;">"Oracle to Postgres
Conversion"</h1><divid="yui_3_16_0_1_1452227859253_99134"><span class=""><br /></span></div><div dir="ltr"
id="yui_3_16_0_1_1452227859253_99078"><spanclass="" id="yui_3_16_0_1_1452227859253_99077"><a
href="https://wiki.postgresql.org/wiki/Oracle_to_Postgres_Conversion#Grammar_Differences"
id="yui_3_16_0_1_1452227859253_99074">https://wiki.postgresql.org/wiki/Oracle_to_Postgres_Conversion#Grammar_Differences</a><br
/></span></div><divid="yui_3_16_0_1_1452227859253_99078"><br /></div><div dir="ltr"
id="yui_3_16_0_1_1452227859253_99078">on <spanclass="" id="yui_3_16_0_1_1452227859253_99196" style="font-family:
sans-serif;font-size: 12.6999998092651px; line-height: 19.0499992370605px;">Postgres 8.4.</span></div><div dir="ltr"
id="yui_3_16_0_1_1452227859253_99078"><spanclass="" style="font-family: sans-serif; font-size: 12.6999998092651px;
line-height:19.0499992370605px;"><br /></span></div><div dir="ltr" id="yui_3_16_0_1_1452227859253_99078"><br
/></div><h2class="" id="yui_3_16_0_1_1452227859253_99029" style="color: rgb(230, 86, 0); font-weight: normal;
margin-top:0px; margin-bottom: 0.6em; padding-top: 0.5em; padding-bottom: 0.17em; border-bottom-width: 1px;
border-bottom-style:solid; border-bottom-color: rgb(170, 170, 170); font-size: 19.0499992370605px; font-family:
sans-serif;line-height: 19.0499992370605px; background-image: none; background-attachment: initial; background-size:
initial;background-origin: initial; background-clip: initial; background-position: initial; background-repeat:
initial;"><spanclass="" id="BLOBs">BLOBs</span></h2><div class="" id="yui_3_16_0_1_1452227859253_99032"
style="margin-top:0.4em; margin-bottom: 0.5em; line-height: 19.0499992370605px; font-family: sans-serif; font-size:
12.6999998092651px;"><bid="yui_3_16_0_1_1452227859253_99194">Binary large object support in Postgres is very poor and
unsuitablefor use in a 24/7 environment</b>, because you can't dump them with pg_dump. Backing up a database that makes
useof Postgres large objects requires one to knock down the RDBMS and dump the files in the database
directory.</div><divclass="" id="yui_3_16_0_1_1452227859253_99034" style="margin-top: 0.4em; margin-bottom: 0.5em;
line-height:19.0499992370605px; font-family: sans-serif; font-size: 12.6999998092651px;">Don Baccus put together a hack
thatextends AOLserver's postgres driver with BLOB-like support, by uuencoding/decoding binary files before stuffing
theminto or extracting them from the database. The resulting objects can be consistently dumped by "pg_dump" while the
RDBMSis up and running. There is no need to interrupt service while making your backup.</div><div class=""
id="yui_3_16_0_1_1452227859253_99036"style="margin-top: 0.4em; margin-bottom: 0.5em; line-height: 19.0499992370605px;
font-family:sans-serif; font-size: 12.6999998092651px;">To get around the one-block limit on the size of a tuple
imposedby Postgres, the driver segments the encoded data into 8K chunks.</div><div class=""
id="yui_3_16_0_1_1452227859253_99038"style="margin-top: 0.4em; margin-bottom: 0.5em; line-height: 19.0499992370605px;
font-family:sans-serif; font-size: 12.6999998092651px;"><b id="yui_3_16_0_1_1452227859253_99170">Postgres large objects
arescheduled for a major overhaul in summer 2000. Because of this, only the BLOB functionality used by the ACS was
implemented.</b></div><divclass="" dir="ltr" id="yui_3_16_0_1_1452227859253_99040"><br class=""
id="yui_3_16_0_1_1452227859253_99042"/></div><div class="" dir="ltr" id="yui_3_16_0_1_1452227859253_99040"><br
/></div><divclass="" dir="ltr" id="yui_3_16_0_1_1452227859253_99040">Now for Postgres 9.4.5,  is backup of the BLOB
stillan issue as described above, OR, it now works equivalent to that of Oracle?</div><div class="" dir="ltr"
id="yui_3_16_0_1_1452227859253_99040"><br/></div><div class="" dir="ltr" id="yui_3_16_0_1_1452227859253_99040"><br
/></div><divclass="" dir="ltr" id="yui_3_16_0_1_1452227859253_99040">Thanks</div><div class="" dir="ltr"
id="yui_3_16_0_1_1452227859253_99040"><br/></div><div class="" dir="ltr" id="yui_3_16_0_1_1452227859253_99040"><br
/></div><divclass="" dir="ltr" id="yui_3_16_0_1_1452227859253_99040">Eugene</div></div> 

Re: BLOBs

From
Tom Lane
Date:
Eugene Yin <eugeneymail@ymail.com> writes:
> The following statement is excerpted from the 
> "Oracle to Postgres Conversion"
> https://wiki.postgresql.org/wiki/Oracle_to_Postgres_Conversion#Grammar_Differences

My goodness, that's out of date (as you should have guessed from the
reference to "scheduled for an overhaul in summer 2000").  pg_dump
has been able to dump large objects just fine since 8.1 or so.

I don't know what else an Oracle user might be expecting that we don't
have, though, so I'm hesitant to change the text.
        regards, tom lane



Re: BLOBs

From
Eugene Yin
Date:
<div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida
Grande,sans-serif;font-size:13px"><div dir="ltr" id="yui_3_16_0_1_1452227859253_128440"><span
id="yui_3_16_0_1_1452227859253_128623"style="line-height: 16.8999996185303px; white-space: pre-wrap; background-color:
rgb(238,238, 238);"><font color="#222426" face="Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans
Mono,Bitstream Vera Sans Mono, Courier New, monospace, sans-serif" id="yui_3_16_0_1_1452227859253_128622">I use the
BLOBin an Oracle table to store IMG and document files. Now for Postgres(9.4.5), I have two options, i.e., BYTEA or
OID.</font></span></div><divdir="ltr" id="yui_3_16_0_1_1452227859253_128440"><span style="line-height:
16.8999996185303px;white-space: pre-wrap; background-color: rgb(238, 238, 238);"><font color="#222426" face="Consolas,
Menlo,Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace,
sans-serif"><br/></font></span></div><div class="" dir="ltr" id="yui_3_16_0_1_1452227859253_128440"><span class=""
id="yui_3_16_0_1_1452227859253_128984"style="color: rgb(34, 36, 38); font-family: Consolas, Menlo, Monaco, 'Lucida
Console','Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif;
line-height:16.8999996185303px; white-space: pre-wrap; background-color: rgb(238, 238, 238);">With consideration of
passingthe params </span><span class="" id="yui_3_16_0_1_1452227859253_128993" style="color: rgb(34, 36, 38);
font-family:Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans
Mono','Courier New', monospace, sans-serif; line-height: 16.8999996185303px; white-space: pre-wrap; background-color:
rgb(238,238, 238);">(SAVING) </span><span class="" id="yui_3_16_0_1_1452227859253_128995" style="color: rgb(34, 36,
38);font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans
Mono','Courier New', monospace, sans-serif; line-height: 16.8999996185303px; white-space: pre-wrap; background-color:
rgb(238,238, 238);">from the Java side as follows:</span></div><div class="" dir="ltr"
id="yui_3_16_0_1_1452227859253_128440"><spanclass="" id="yui_3_16_0_1_1452227859253_129306" style="color: rgb(34, 36,
38);font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans
Mono','Courier New', monospace, sans-serif; line-height: 16.8999996185303px; white-space: pre-wrap; background-color:
rgb(238,238, 238);"><br class="" id="yui_3_16_0_1_1452227859253_129308" /></span></div><div class="" dir="ltr"
id="yui_3_16_0_1_1452227859253_128440"><spanclass="" id="yui_3_16_0_1_1452227859253_129034" style="background-color:
rgb(238,238, 238);"><font class="" color="#222426" face="Consolas, Menlo, Monaco, Lucida Console, Liberation Mono,
DejaVuSans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif"
id="yui_3_16_0_1_1452227859253_128988"><spanclass="" id="yui_3_16_0_1_1452227859253_128990" style="line-height:
16.8999996185303px;white-space: pre-wrap;">DiskFileItemDeepy file = myFile; InputStream is = null; long fileSize = 0;
if(file != null && file.getFileSize() > 0){      is = file.getInputStream();     fileSize =
file.getFileSize();    call.setBinaryStream(1, (InputStream)is, (long)fileSize);</span></font><br class=""
id="yui_3_16_0_1_1452227859253_129314"/></span></div><div class="" dir="ltr"
id="yui_3_16_0_1_1452227859253_128440"><spanclass="" id="yui_3_16_0_1_1452227859253_129317" style="color: rgb(34, 36,
38);font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans
Mono','Courier New', monospace, sans-serif; line-height: 16.8999996185303px; white-space: pre-wrap; background-color:
rgb(238,238, 238);">}</span></div><div class="" dir="ltr" id="yui_3_16_0_1_1452227859253_128440"><span class=""
id="yui_3_16_0_1_1452227859253_129320"style="color: rgb(34, 36, 38); font-family: Consolas, Menlo, Monaco, 'Lucida
Console','Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif;
line-height:16.8999996185303px; white-space: pre-wrap; background-color: rgb(238, 238, 238);">...</span></div><div
class=""dir="ltr" id="yui_3_16_0_1_1452227859253_128440"><span class="" id="yui_3_16_0_1_1452227859253_129213"
style="background-color:rgb(238, 238, 238);"><font class="" color="#222426" face="Consolas, Menlo, Monaco, Lucida
Console,Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif"
id="yui_3_16_0_1_1452227859253_129180"><spanclass="" id="yui_3_16_0_1_1452227859253_129182" style="line-height:
16.8999996185303px;white-space: pre-wrap;">call.execute(); </span></font></span></div><div class="" dir="ltr"
id="yui_3_16_0_1_1452227859253_128440"><spanclass="" style="background-color: rgb(238, 238, 238);"><font class=""
color="#222426"face="Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans
Mono,Courier New, monospace, sans-serif"><span class="" style="line-height: 16.8999996185303px; white-space:
pre-wrap;"><br/></span></font></span></div><div class="" dir="ltr" id="yui_3_16_0_1_1452227859253_128440"><span
class=""style="background-color: rgb(238, 238, 238);"><font class="" color="#222426" face="Consolas, Menlo, Monaco,
LucidaConsole, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif"><span
class=""style="line-height: 16.8999996185303px; white-space: pre-wrap;"><br /></span></font></span></div><div class=""
dir="ltr"id="yui_3_16_0_1_1452227859253_128440"><span class="" id="yui_3_16_0_1_1452227859253_129443"
style="background-color:rgb(238, 238, 238);"><font class="" color="#222426" face="Consolas, Menlo, Monaco, Lucida
Console,Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif"
id="yui_3_16_0_1_1452227859253_129442"><spanclass="" id="yui_3_16_0_1_1452227859253_129441" style="line-height:
16.8999996185303px;white-space: pre-wrap;">//When retrieve the data use:</span></font></span></div><div class=""
dir="ltr"id="yui_3_16_0_1_1452227859253_128440"><span class="" style="background-color: rgb(238, 238, 238);"><font
class=""color="#222426" face="Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream
VeraSans Mono, Courier New, monospace, sans-serif"><span class="" style="line-height: 16.8999996185303px; white-space:
pre-wrap;"><br/></span></font></span></div><div class="" dir="ltr" id="yui_3_16_0_1_1452227859253_128440"><span
class=""id="yui_3_16_0_1_1452227859253_129446" style="background-color: rgb(238, 238, 238);"><font class=""
color="#222426"face="Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans
Mono,Courier New, monospace, sans-serif" id="yui_3_16_0_1_1452227859253_129445"><span class=""
id="yui_3_16_0_1_1452227859253_129444"style="line-height: 16.8999996185303px; white-space: pre-wrap;"> java.sql.Blob
blob= (Blob) <span class="" id="yui_3_16_0_1_1452227859253_129515" style="line-height:
16.8999996185303px;">resultSet</span>.getBlob(tableColumnName); </span></font></span></div><div class="" dir="ltr"
id="yui_3_16_0_1_1452227859253_128440"><spanclass="" style="background-color: rgb(238, 238, 238);"><font class=""
color="#222426"face="Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans
Mono,Courier New, monospace, sans-serif"><span class="" style="line-height: 16.8999996185303px; white-space:
pre-wrap;"><br/></span></font></span></div><div class="" dir="ltr" id="yui_3_16_0_1_1452227859253_128440"><span
class=""style="background-color: rgb(238, 238, 238);"><font class="" color="#222426" face="Consolas, Menlo, Monaco,
LucidaConsole, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, sans-serif"><span
class=""style="line-height: 16.8999996185303px; white-space: pre-wrap;"><br /></span></font></span></div><div dir="ltr"
id="yui_3_16_0_1_1452227859253_128440"><spanid="yui_3_16_0_1_1452227859253_128718" style="line-height:
16.8999996185303px;white-space: pre-wrap; background-color: rgb(238, 238, 238);"><font color="#222426" face="Consolas,
Menlo,Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace,
sans-serif"id="yui_3_16_0_1_1452227859253_128719">For the purpose mentioned above, which Postgres data type is a better
candidatefor replacement the BLOB, </font></span><span class="" id="yui_3_16_0_1_1452227859253_128717" style="color:
rgb(34,36, 38); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono',
'BitstreamVera Sans Mono', 'Courier New', monospace, sans-serif; line-height: 16.8999996185303px; white-space:
pre-wrap;background-color: rgb(238, 238, 238);">BYTEA or OID?</span></div><div dir="ltr"
id="yui_3_16_0_1_1452227859253_128440"><spanclass="" style="color: rgb(34, 36, 38); font-family: Consolas, Menlo,
Monaco,'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
sans-serif;line-height: 16.8999996185303px; white-space: pre-wrap; background-color: rgb(238, 238, 238);"><br
/></span></div><divdir="ltr" id="yui_3_16_0_1_1452227859253_128440"><br /></div><div dir="ltr"
id="yui_3_16_0_1_1452227859253_128440"><spanclass="" style="color: rgb(34, 36, 38); font-family: Consolas, Menlo,
Monaco,'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace,
sans-serif;line-height: 16.8999996185303px; white-space: pre-wrap; background-color: rgb(238, 238, 238);"><br
/></span></div><divdir="ltr" id="yui_3_16_0_1_1452227859253_128440"><span class=""
id="yui_3_16_0_1_1452227859253_128919"style="color: rgb(34, 36, 38); font-family: Consolas, Menlo, Monaco, 'Lucida
Console','Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif;
line-height:16.8999996185303px; white-space: pre-wrap; background-color: rgb(238, 238, 238);">Thanks</span></div><div
dir="ltr"id="yui_3_16_0_1_1452227859253_128440"><span class="" style="color: rgb(34, 36, 38); font-family: Consolas,
Menlo,Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New',
monospace,sans-serif; line-height: 16.8999996185303px; white-space: pre-wrap; background-color: rgb(238, 238,
238);"><br/></span></div><div dir="ltr" id="yui_3_16_0_1_1452227859253_128440"><span class="" style="color: rgb(34, 36,
38);font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans
Mono','Courier New', monospace, sans-serif; line-height: 16.8999996185303px; white-space: pre-wrap; background-color:
rgb(238,238, 238);">Eugene</span></div><div dir="ltr" id="yui_3_16_0_1_1452227859253_128440"><br /></div><div
class="qtdSeparateBR"><br/><br /></div><div class="yahoo_quoted" style="display: block;"><div style="font-family:
HelveticaNeue,Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 13px;"><div style="font-family:
HelveticaNeue,Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"><div dir="ltr"><font
face="Arial"size="2"> On Saturday, January 9, 2016 11:13 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:<br
/></font></div><br/><br /><div class="y_msg_container">Eugene Yin <<a class="removed-link" href="" shape="rect"
ymailto="mailto:eugeneymail@ymail.com">eugeneymail@ymail.com</a>>writes:<div class="yqt5061021327"
id="yqtfd57926"><brclear="none" />> The following statement is excerpted from the <br clear="none" />> "Oracle to
PostgresConversion"<br clear="none" />> <a class="removed-link" href="" shape="rect"
target="_blank">https://wiki.postgresql.org/wiki/Oracle_to_Postgres_Conversion#Grammar_Differences</a></div><br
clear="none"/><br clear="none" />My goodness, that's out of date (as you should have guessed from the<br clear="none"
/>referenceto "scheduled for an overhaul in summer 2000").  pg_dump<br clear="none" />has been able to dump large
objectsjust fine since 8.1 or so.<br clear="none" /><br clear="none" />I don't know what else an Oracle user might be
expectingthat we don't<br clear="none" />have, though, so I'm hesitant to change the text.<br clear="none" /><br
clear="none"/>            regards, tom lane<br clear="none" /><br clear="none" /><br clear="none" />-- <br clear="none"
/>Sentvia pgsql-sql mailing list (<a class="removed-link" href="" shape="rect"
ymailto="mailto:pgsql-sql@postgresql.org">pgsql-sql@postgresql.org</a>)<brclear="none" />To make changes to your
subscription:<brclear="none" /><a class="removed-link" href="" shape="rect"
target="_blank">http://www.postgresql.org/mailpref/pgsql-sql</a><divclass="yqt5061021327" id="yqtfd99998"><br
clear="none"/></div><br /><br /></div></div></div></div></div> 

Re: BLOBs

From
Andreas Joseph Krogh
Date:
På mandag 11. januar 2016 kl. 01:37:52, skrev Eugene Yin <eugeneymail@ymail.com>:
I use the BLOB in an Oracle table to store IMG and document files. Now for Postgres(9.4.5), I have two options, i.e., BYTEA or OID.
 
With consideration of passing the params (SAVING) from the Java side as follows:
 
DiskFileItemDeepy file = myFile; InputStream is = null; long fileSize = 0; if (file != null && file.getFileSize() > 0){      is = file.getInputStream();     fileSize = file.getFileSize();     call.setBinaryStream(1, (InputStream)is, (long)fileSize);
}
...
call.execute();
 
 
//When retrieve the data use:
 
 java.sql.Blob blob = (Blob) resultSet.getBlob(tableColumnName); 
 
 
For the purpose mentioned above, which Postgres data type is a better candidate for replacement the BLOB, BYTEA or OID?
 
From my experience, always use OID for BLOBs, and use the pgjdbc-ng JDBC-driver here: https://github.com/impossibl/pgjdbc-ng
 
Maven-config:
<properties>    <version.pgjdbc-ng>0.6</version.pgjdbc-ng>
</properties>
<dependency>    <groupId>com.impossibl.pgjdbc-ng</groupId>    <artifactId>pgjdbc-ng</artifactId>    <version>${version.pgjdbc-ng}</version>    <classifier>complete</classifier>
</dependency>
 
In the connection-URL use blobtype=oid:
datasource.url=jdbc:pgsql://localhost:5432/andreak?blob.type=oid
 
This is the only (as I know of) combination which lets you work with true streams all the way down to PG. This way you can work with very large images/movies/documents without sacrificing memory.
The official JDBC-driver for PG doesn't support BLOBs proparly, no getBlob/createBlob (among other things, like custom type mappings).
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 
Attachment

Re: BLOBs

From
Eugene Yin
Date:

QUOTE:

Maven-config:
<properties>    <version.pgjdbc-ng>0.6</version.pgjdbc-ng>
</properties>
<dependency>    <groupId>com.impossibl.pgjdbc-ng</groupId>    <artifactId>pgjdbc-ng</artifactId>    <version>${version.pgjdbc-ng}</version>    <classifier>complete</classifier>
</dependency>


I do not use Maven.  

I use web.xml and standalone-ha.xml of JBoss AS 7.1.1 to configure the JDBC, such as


[web.xml]

<resource-ref>
     <description>Resource reference to my database</description>
    <res-ref-name>jdbc/web</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Application</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
 </resource-ref>

    
[standalone-ha.xml]

 <datasource jta="false" jndi-name="java:/jdbc/web" pool-name="OracleDS" enabled="true" use-ccm="false">
                    <connection-url>jdbc:oracle:thin:@192.168.1.20:1521:deepy</connection-url>
                    <driver-class>oracle.jdbc.OracleDriver</driver-class>
                    <driver>OracleJDBCDriver</driver>
                    <security>
                        <security-domain>mysecuritydomain</security-domain>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </datasource>



What corresponding changes I need to make to use the Postgres?




Thanks

Eugene





 


On Monday, January 11, 2016 2:10 AM, Andreas Joseph Krogh <andreas@visena.com> wrote:


På mandag 11. januar 2016 kl. 01:37:52, skrev Eugene Yin <eugeneymail@ymail.com>:
I use the BLOB in an Oracle table to store IMG and document files. Now for Postgres(9.4.5), I have two options, i.e., BYTEA or OID.
 
With consideration of passing the params (SAVING) from the Java side as follows:
 
DiskFileItemDeepy file = myFile; InputStream is = null; long fileSize = 0; if (file != null && file.getFileSize() > 0){      is = file.getInputStream();     fileSize = file.getFileSize();     call.setBinaryStream(1, (InputStream)is, (long)fileSize);
}
...
call.execute();
 
 
//When retrieve the data use:
 
 java.sql.Blob blob = (Blob) resultSet.getBlob(tableColumnName); 
 
 
For the purpose mentioned above, which Postgres data type is a better candidate for replacement the BLOB, BYTEA or OID?
 
From my experience, always use OID for BLOBs, and use the pgjdbc-ng JDBC-driver here: https://github.com/impossibl/pgjdbc-ng
 
Maven-config:
<properties>    <version.pgjdbc-ng>0.6</version.pgjdbc-ng>
</properties>
<dependency>    <groupId>com.impossibl.pgjdbc-ng</groupId>    <artifactId>pgjdbc-ng</artifactId>    <version>${version.pgjdbc-ng}</version>    <classifier>complete</classifier>
</dependency>
 
In the connection-URL use blobtype=oid:
datasource.url=jdbc:pgsql://localhost:5432/andreak?blob.type=oid
 
This is the only (as I know of) combination which lets you work with true streams all the way down to PG. This way you can work with very large images/movies/documents without sacrificing memory.
The official JDBC-driver for PG doesn't support BLOBs proparly, no getBlob/createBlob (among other things, like custom type mappings).
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 


Attachment

Re: BLOBs

From
Andreas Joseph Krogh
Date:
På mandag 11. januar 2016 kl. 16:37:50, skrev Eugene Yin <eugeneymail@ymail.com>:
 
QUOTE:
 
Maven-config:
<properties>    <version.pgjdbc-ng>0.6</version.pgjdbc-ng>
</properties>
<dependency>    <groupId>com.impossibl.pgjdbc-ng</groupId>    <artifactId>pgjdbc-ng</artifactId>    <version>${version.pgjdbc-ng}</version>    <classifier>complete</classifier>
</dependency>
 
 
I do not use Maven.  
 
I use web.xml and standalone-ha.xml of JBoss AS 7.1.1 to configure the JDBC, such as
 
 
[web.xml]
 
<resource-ref>
     <description>Resource reference to my database</description>
    <res-ref-name>jdbc/web</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Application</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
 </resource-ref>
 
    
[standalone-ha.xml]
 
 <datasource jta="false" jndi-name="java:/jdbc/web" pool-name="OracleDS" enabled="true" use-ccm="false">
                    <connection-url>jdbc:oracle:thin:@192.168.1.20:1521:deepy</connection-url>
                    <driver-class>oracle.jdbc.OracleDriver</driver-class>
                    <driver>OracleJDBCDriver</driver>
                    <security>
                        <security-domain>mysecuritydomain</security-domain>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </datasource>
 
 
 
What corresponding changes I need to make to use the Postgres?
 
Using Maven is only for getting the right deps in place for your app, it has nothing to do with configuration.
 
The URL should be on the form:
jdbc:pgsql://<host>:<port>/<database_name>?blob.type=oid
Other parameters are available here: http://impossibl.github.io/pgjdbc-ng/
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 
Attachment

Re: BLOBs

From
Eugene Yin
Date:
I did some search on the OID data type.  Here is something I found regarding to the deletion of the OID data.

QUOTE:

"The Large Object method for storing binary data is better suited to storing very large values, but it has its own limitations. Specifically deleting a row that contains a Large Object reference does not delete the Large Object. 

Deleting the Large Object is a separate operation that needs to be performed. 

Large Objects also have some security issues since anyone connected to the database can view and/or modify any Large Object, even if they don't have permissions to view/update the row containing the Large Object reference."



So I have two questions:

1)  If it is true that "Deleting the Large Object is a separate operation that needs to be performed.", after the deletion, what operation I need to perform, in order to delete the OID data in the table?  Possiblely put into an after trigger

2) "Large Objects also have some security issues since anyone connected to the database can view and/or modify any Large Object".  Will this pose a real risk to the security?  or just a forethought?






On Monday, January 11, 2016 9:49 AM, Andreas Joseph Krogh <andreas@visena.com> wrote:


På mandag 11. januar 2016 kl. 16:37:50, skrev Eugene Yin <eugeneymail@ymail.com>:
 
QUOTE:
 
Maven-config:
<properties>    <version.pgjdbc-ng>0.6</version.pgjdbc-ng>
</properties>
<dependency>    <groupId>com.impossibl.pgjdbc-ng</groupId>    <artifactId>pgjdbc-ng</artifactId>    <version>${version.pgjdbc-ng}</version>    <classifier>complete</classifier>
</dependency>
 
 
I do not use Maven.  
 
I use web.xml and standalone-ha.xml of JBoss AS 7.1.1 to configure the JDBC, such as
 
 
[web.xml]
 
<resource-ref>
     <description>Resource reference to my database</description>
    <res-ref-name>jdbc/web</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Application</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
 </resource-ref>
 
    
[standalone-ha.xml]
 
 <datasource jta="false" jndi-name="java:/jdbc/web" pool-name="OracleDS" enabled="true" use-ccm="false">
                    <connection-url>jdbc:oracle:thin:@192.168.1.20:1521:deepy</connection-url>
                    <driver-class>oracle.jdbc.OracleDriver</driver-class>
                    <driver>OracleJDBCDriver</driver>
                    <security>
                        <security-domain>mysecuritydomain</security-domain>
                    </security>
                    <validation>
                        <validate-on-match>false</validate-on-match>
                        <background-validation>false</background-validation>
                    </validation>
                    <statement>
                        <share-prepared-statements>false</share-prepared-statements>
                    </statement>
                </datasource>
 
 
 
What corresponding changes I need to make to use the Postgres?
 
Using Maven is only for getting the right deps in place for your app, it has nothing to do with configuration.
 
The URL should be on the form:
jdbc:pgsql://<host>:<port>/<database_name>?blob.type=oid
Other parameters are available here: http://impossibl.github.io/pgjdbc-ng/
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 


Attachment

Re: BLOBs

From
Andreas Joseph Krogh
Date:
På tirsdag 12. januar 2016 kl. 02:32:46, skrev Eugene Yin <eugeneymail@ymail.com>:
I did some search on the OID data type.  Here is something I found regarding to the deletion of the OID data.
 
QUOTE:
 
"The Large Object method for storing binary data is better suited to storing very large values, but it has its own limitations. Specifically deleting a row that contains a Large Object reference does not delete the Large Object. 
 
Deleting the Large Object is a separate operation that needs to be performed. 
 
Large Objects also have some security issues since anyone connected to the database can view and/or modify any Large Object, even if they don't have permissions to view/update the row containing the Large Object reference."
 
 
 
So I have two questions:
 
1)  If it is true that "Deleting the Large Object is a separate operation that needs to be performed.", after the deletion, what operation I need to perform, in order to delete the OID data in the table?  Possiblely put into an after trigger
 
2) "Large Objects also have some security issues since anyone connected to the database can view and/or modify any Large Object".  Will this pose a real risk to the security?  or just a forethought?
 
1) You don't need to perform any "after delete"-operation as a developer. But the DBA (or someone else) has to execute vacuumlo (see "man vacuumlo" for more info) using cron or some other periodic scheduling tool.
 
2) Your mileage may vary, but for our app this isn't an issue.
 
PS: 8.4 is EOL, use a more current version, preferably 9.5.
I also recommend the -ng driver as it's the only one with proper BLOB-support, as mentioned earlier in this thread.
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 
Attachment

Re: BLOBs

From
Eugene Yin
Date:

BLOB binary large object see Large Object Support


  •  Minuses
    • must use different interface from what is normally used to access BLOBs.
    • Need to track OID. Normally a separate table with additional meta data is used to describe what each OID is.
    • (8.4 and <8.4) No access controls in database.
    • Sometimes advised against (basically you only need them if your entry is so large you need/want to seek and read bits and pieces of it at a time). 


    Do one really: 
    • Need to track OID. Normally a separate table with additional meta data is used to describe what each OID is.



    Thanks

    Eugene



    On Monday, January 11, 2016 11:10 PM, Andreas Joseph Krogh <andreas@visena.com> wrote:


    På tirsdag 12. januar 2016 kl. 02:32:46, skrev Eugene Yin <eugeneymail@ymail.com>:
    I did some search on the OID data type.  Here is something I found regarding to the deletion of the OID data.
     
    QUOTE:
     
    "The Large Object method for storing binary data is better suited to storing very large values, but it has its own limitations. Specifically deleting a row that contains a Large Object reference does not delete the Large Object. 
     
    Deleting the Large Object is a separate operation that needs to be performed. 
     
    Large Objects also have some security issues since anyone connected to the database can view and/or modify any Large Object, even if they don't have permissions to view/update the row containing the Large Object reference."
     
     
     
    So I have two questions:
     
    1)  If it is true that "Deleting the Large Object is a separate operation that needs to be performed.", after the deletion, what operation I need to perform, in order to delete the OID data in the table?  Possiblely put into an after trigger
     
    2) "Large Objects also have some security issues since anyone connected to the database can view and/or modify any Large Object".  Will this pose a real risk to the security?  or just a forethought?
     
    1) You don't need to perform any "after delete"-operation as a developer. But the DBA (or someone else) has to execute vacuumlo (see "man vacuumlo" for more info) using cron or some other periodic scheduling tool.
     
    2) Your mileage may vary, but for our app this isn't an issue.
     
    PS: 8.4 is EOL, use a more current version, preferably 9.5.
    I also recommend the -ng driver as it's the only one with proper BLOB-support, as mentioned earlier in this thread.
     
    --
    Andreas Joseph Krogh
    CTO / Partner - Visena AS
    Mobile: +47 909 56 963
     


Attachment

Re: BLOBs

From
Andreas Joseph Krogh
Date:
På søndag 17. januar 2016 kl. 20:26:34, skrev Eugene Yin <eugeneymail@ymail.com>:
 
BLOB binary large object see Large Object Support
 
 
  •  Minuses
  • must use different interface from what is normally used to access BLOBs.
  • Need to track OID. Normally a separate table with additional meta data is used to describe what each OID is.
  • (8.4 and <8.4) No access controls in database.
  • Sometimes advised against (basically you only need them if your entry is so large you need/want to seek and read bits and pieces of it at a time). 
 
 
Do one really: 
  • Need to track OID. Normally a separate table with additional meta data is used to describe what each OID is.
 
Using BLOBs and PG's OIDs is really simple if you use the pgjdbc-ng driver.
 
You column has to be defined as type=OID, like this
 
CREATE TABLE my_stuff(
id SERIAL PRIMARY KEY,
data OID
);
 
Then use the JDBC BLOB-interface as defined.
 
You don't need to do anything else except running the 'vacuumlo' system-command (not SQL-command) once in a while, preferably using 'cron' or some other scheduling-tool.
 
Note that "everything" you read about PG and JDBC and BLOB will describe the official JDBC-driver, which doesn't even support BLOBs. So if you just get by that and use the pgjdbc-ng driver your life will be much simpler.
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 
Attachment

Re: BLOBs

From
Thomas Kellerer
Date:
Andreas Joseph Krogh schrieb am 17.01.2016 um 23:08:
> will describe the official JDBC-driver which doesn't even support BLOBs.

This is not true.

using set/getBinaryStream() or set/getBytes() works just fine






Re: BLOBs

From
Andreas Joseph Krogh
Date:
På søndag 17. januar 2016 kl. 23:17:29, skrev Thomas Kellerer <spam_eater@gmx.net>:
Andreas Joseph Krogh schrieb am 17.01.2016 um 23:08:
> will describe the official JDBC-driver which doesn't even support BLOBs.

This is not true.

using set/getBinaryStream() or set/getBytes() works just fine
 
Just fine for you maybe, but it doesn't work for people working with large data (think GB) and who want streams. Se my previous reply.
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
 
Attachment