Re: Selecting Large Object and TOAST

Lists: pgsql-general
From: vishal saberwal <vishalsaberwal(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Selecting Large Object and TOAST
Date: 2005-12-05 00:55:47
Message-ID: 3e74dc250512041655u6a5742cew4429db7639715a41@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

hi,

We are storing the Icons/IMages in the database as Large Objects using
lo_import functions.

(1) what would be the return type if i want to return a large object (
XYZ.gif) to the remote client (GUI) using stored procedure.
Can anyone give an example please?
Are there any size limitations i need to consider when returning Large
Object using procedures?

(2) A statement from documentation:
"PostgreSQL 7.1 introduced a mechanism (nicknamed "TOAST") that allows data
values to be much larger than single pages. This makes the large object
facility partially obsolete."
How do i TOAST my data stored as Large Object?

thanks,
vish


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: vishal saberwal <vishalsaberwal(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting Large Object and TOAST
Date: 2005-12-05 02:05:51
Message-ID: 4393A07F.9020701@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 12/4/2005 7:55 PM, vishal saberwal wrote:

> hi,
>
> We are storing the Icons/IMages in the database as Large Objects using
> lo_import functions.
>
> (1) what would be the return type if i want to return a large object (
> XYZ.gif) to the remote client (GUI) using stored procedure.
> Can anyone give an example please?
> Are there any size limitations i need to consider when returning Large
> Object using procedures?
>
> (2) A statement from documentation:
> "PostgreSQL 7.1 introduced a mechanism (nicknamed "TOAST") that allows data
> values to be much larger than single pages. This makes the large object
> facility partially obsolete."
> How do i TOAST my data stored as Large Object?

You don't. You would change you schema and application to store the
images in bytea columns instead.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>
Cc: vishal saberwal <vishalsaberwal(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting Large Object and TOAST
Date: 2005-12-05 02:24:18
Message-ID: 4393A4D2.1040105@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


>>
>> (1) what would be the return type if i want to return a large object (
>> XYZ.gif) to the remote client (GUI) using stored procedure.
>> Can anyone give an example please?
>> Are there any size limitations i need to consider when returning Large
>> Object using procedures?
You have to use a lookup table that correlates the meta information
(filename, content-type)
with a particular loid. That way you can store any binary you want.

>>
>> How do i TOAST my data stored as Large Object?
This isn't a concern as it is all internal and automatic.

> You don't. You would change you schema and application to store the
> images in bytea columns instead.
>
Well I have to disagree with this. It entirely depends on the size of
the data you are storing. Bytea is remarkably
innefficient.

Joshua D. Drake

>
> Jan
>


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: vishal saberwal <vishalsaberwal(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting Large Object and TOAST
Date: 2005-12-05 03:54:14
Message-ID: 4393B9E6.5070500@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 12/4/2005 9:24 PM, Joshua D. Drake wrote:

>>>
>>> (1) what would be the return type if i want to return a large object (
>>> XYZ.gif) to the remote client (GUI) using stored procedure.
>>> Can anyone give an example please?
>>> Are there any size limitations i need to consider when returning Large
>>> Object using procedures?
> You have to use a lookup table that correlates the meta information
> (filename, content-type)
> with a particular loid. That way you can store any binary you want.

This doesn't answer the question.

Fact is that most procedural languages (including PL/pgSQL) don't have
any access to classic large objects in the first place. So all the
stored procedure can do is to return the identifier of the large object
to the client and the client must then use lo_open(), lo_read() etc. to
actually get the data of the object. Not all client interfaces support
these fastpath based libpq functions.

>
>>>
>>> How do i TOAST my data stored as Large Object?
> This isn't a concern as it is all internal and automatic.
>
>> You don't. You would change you schema and application to store the
>> images in bytea columns instead.
>>
> Well I have to disagree with this. It entirely depends on the size of
> the data you are storing. Bytea is remarkably
> innefficient.

Which would be the data type of your choice for images?

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>
Cc: vishal saberwal <vishalsaberwal(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting Large Object and TOAST
Date: 2005-12-05 04:45:53
Message-ID: 4393C601.8040900@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

>
> This doesn't answer the question.
>
> Fact is that most procedural languages (including PL/pgSQL) don't have
> any access to classic large objects in the first place. So all the
> stored procedure can do is to return the identifier of the large
> object to the client and the client must then use lo_open(), lo_read()
> etc. to actually get the data of the object. Not all client interfaces
> support these fastpath based libpq functions.
>

You are correct, I missed the part about wanting to return from a stored
procedure.

>> Well I have to disagree with this. It entirely depends on the size of
>> the data you are storing. Bytea is remarkably
>> innefficient.
>
> Which would be the data type of your choice for images?
Well as I said it depends on the size of the data. Are we talking 100
meg vector images? Then large objects. Are we talking thumbnails that
are 32k then bytea.

Joshua D. Drake

>
>
> Jan
>


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
Cc: vishal saberwal <vishalsaberwal(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting Large Object and TOAST
Date: 2005-12-05 05:51:46
Message-ID: 4393D572.9090509@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 12/4/2005 11:45 PM, Joshua D. Drake wrote:

> Well as I said it depends on the size of the data. Are we talking 100
> meg vector images? Then large objects. Are we talking thumbnails that
> are 32k then bytea.

I'd say that anything up to a megabyte or so can easily live in bytea.
Beyond that it depends on the access pattern.

That said, for certain situations I think some sql-callable functions
would be very handy:

lo_get(oid) returns bytea
lo_set(oid, bytea) returns void
lo_ins(bytea) returns oid
lo_del(oid) returns void

Those (and maybe some more) would allow access of traditional large
objects through client interfaces that don't support the regular large
object calls.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #


From: vishal saberwal <vishalsaberwal(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting Large Object and TOAST
Date: 2005-12-05 08:16:50
Message-ID: 3e74dc250512050016k53809438j47122c4ad6d56aa7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

thanks for all your responses,
really appreciate it,

I am sorry but I am not as familiar with this as much as you are.

So are you suggesting, I need to send the Large object ID to the client?
Since the application is time critical, is there a way to skip one of the
two steps (querying once for LOID and then again for its data) to a one step
by sending the Object data in the first call?

Are there any examples or pseudocode someone who's implemented using
largeobjects to retrieve images to be shown as icons/images in web pages
(using Stored procedures).

http://www.postgresql.org/docs/8.1/interactive/lo-examplesect.html
Is the above site's ExportFile() something that can help me (but it creates
a file, different from what i want)?

As far as the size is concerned, i am testing with image resource, but we
plan to store video clips too. Though we are planning to store thumbnails in
Large Objects too.

>> lo_get(oid) returns bytea
>> lo_set(oid, bytea) returns void
>> lo_ins(bytea) returns oid
>> lo_del(oid) returns void
How do you suggest i create lo_get(oid) function returning bytea data.

I have understood that TOAST is internal implementation, thanks for the
info.

thanks,
vish

On 12/4/05, Jan Wieck <JanWieck(at)yahoo(dot)com> wrote:
>
> On 12/4/2005 11:45 PM, Joshua D. Drake wrote:
>
> > Well as I said it depends on the size of the data. Are we talking 100
> > meg vector images? Then large objects. Are we talking thumbnails that
> > are 32k then bytea.
>
> I'd say that anything up to a megabyte or so can easily live in bytea.
> Beyond that it depends on the access pattern.
>
> That said, for certain situations I think some sql-callable functions
> would be very handy:
>
> lo_get(oid) returns bytea
> lo_set(oid, bytea) returns void
> lo_ins(bytea) returns oid
> lo_del(oid) returns void
>
> Those (and maybe some more) would allow access of traditional large
> objects through client interfaces that don't support the regular large
> object calls.
>
>
> Jan
>
> --
> #======================================================================#
> # It's easier to get forgiveness for being wrong than for being right. #
> # Let's break this rule - forgive me. #
> #================================================== JanWieck(at)Yahoo(dot)com #
>


From: vishal saberwal <vishalsaberwal(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting Large Object and TOAST
Date: 2005-12-05 20:16:19
Message-ID: 3e74dc250512051216w6ce5b379k5c24128f79da3b54@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

So are you suggesting, I need to send the Large object ID to the client?
Since the application is time critical, is there a way to skip one of the
two steps (querying once for LOID and then again for its data) to a one step
by sending the Object data in the first call?

Are there any examples or pseudocode someone who's implemented using
largeobjects to retrieve images to be shown as icons/images in web pages
(using Stored procedures).

http://www.postgresql.org/docs/8.1/interactive/lo-examplesect.html
Is the above site's ExportFile() something that can help me (but it creates
a file, different from what i want)?

As far as the size is concerned, i am testing with image resource, but we
plan to store video clips too. Though we are planning to store thumbnails in
Large Objects too.

>> lo_get(oid) returns bytea
>> lo_set(oid, bytea) returns void
>> lo_ins(bytea) returns oid
>> lo_del(oid) returns void
How do you suggest i create lo_get(oid) function returning bytea data.

thanks,
vish

On 12/5/05, vishal saberwal <vishalsaberwal(at)gmail(dot)com> wrote:
>
> thanks for all your responses,
> really appreciate it,
>
> I am sorry but I am not as familiar with this as much as you are.
>
> So are you suggesting, I need to send the Large object ID to the client?
> Since the application is time critical, is there a way to skip one of the
> two steps (querying once for LOID and then again for its data) to a one step
> by sending the Object data in the first call?
>
> Are there any examples or pseudocode someone who's implemented using
> largeobjects to retrieve images to be shown as icons/images in web pages
> (using Stored procedures).
>
> http://www.postgresql.org/docs/8.1/interactive/lo-examplesect.html
> Is the above site's ExportFile() something that can help me (but it
> creates a file, different from what i want)?
>
> As far as the size is concerned, i am testing with image resource, but we
> plan to store video clips too. Though we are planning to store thumbnails in
> Large Objects too.
>
> >> lo_get(oid) returns bytea
> >> lo_set(oid, bytea) returns void
> >> lo_ins(bytea) returns oid
> >> lo_del(oid) returns void
> How do you suggest i create lo_get(oid) function returning bytea data.
>
> I have understood that TOAST is internal implementation, thanks for the
> info.
>
> thanks,
> vish
>
> On 12/4/05, Jan Wieck <JanWieck(at)yahoo(dot)com> wrote:
> >
> > On 12/4/2005 11:45 PM, Joshua D. Drake wrote:
> >
> > > Well as I said it depends on the size of the data. Are we talking 100
> > > meg vector images? Then large objects. Are we talking thumbnails that
> > > are 32k then bytea.
> >
> > I'd say that anything up to a megabyte or so can easily live in bytea.
> > Beyond that it depends on the access pattern.
> >
> > That said, for certain situations I think some sql-callable functions
> > would be very handy:
> >
> > lo_get(oid) returns bytea
> > lo_set(oid, bytea) returns void
> > lo_ins(bytea) returns oid
> > lo_del(oid) returns void
> >
> > Those (and maybe some more) would allow access of traditional large
> > objects through client interfaces that don't support the regular large
> > object calls.
> >
> >
> > Jan
> >
> > --
> > #======================================================================#
> > # It's easier to get forgiveness for being wrong than for being right. #
> >
> > # Let's break this rule - forgive me. #
> > #================================================== JanWieck(at)Yahoo(dot)com #
> >
>
>


From: Greg Stark <gsstark(at)mit(dot)edu>
To: vishal saberwal <vishalsaberwal(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting Large Object and TOAST
Date: 2005-12-05 21:01:21
Message-ID: 87lkyzjm1q.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general


vishal saberwal <vishalsaberwal(at)gmail(dot)com> writes:

> So are you suggesting, I need to send the Large object ID to the client?
> Since the application is time critical, is there a way to skip one of the
> two steps (querying once for LOID and then again for its data) to a one step
> by sending the Object data in the first call?

The main reason to use large objects at all is if you have a need to read and
write *parts* of the data. For instance if your data is being served up by a
web server then you may want to be able to pipeline the data in chunks instead
of waiting until you can download the entire object from the database. So you
would use loread() to read out one chunk, stuff it into your network buffers,
then loop back and loread() the next chunk.

If all you want to do is store and read the entire object in a single query
then large objects don't really have any advantage for you. Postgres removes
many of the limitations that legacy databases imposed on regular data types
that made large objects necessary for such routine storage.

--
greg