storing PDFs

Started by littlebuttyover 20 years ago8 messagesgeneral
Jump to latest
#1littlebutty
littlebutty@gmail.com

I have written software that will dynamically create PDF documents used
within my web application. Because each document is unique, I would
like to store the resultant PDF into a field of the DB. Currently I
just store the file to the server's hard drive and insert a path to the
file the database, but I would like to also store the actual file
itself in a field for redundancy purposes and other business reasons.
I am curious to know what everyone thinks would be the best way to
store PDF files in postgres??

#2Michael Glaesemann
grzm@seespotcode.net
In reply to: littlebutty (#1)
Re: storing PDFs

On Dec 29, 2005, at 16:45 , littlebutty wrote:

I am curious to know what everyone thinks would be the best way to
store PDF files in postgres??

The BYTEA data type should do the trick.

Michael Glaesemann
grzm myrealbox com

#3Larry Rosenman
ler@lerctr.org
In reply to: Michael Glaesemann (#2)
Re: storing PDFs

Michael Glaesemann wrote:

On Dec 29, 2005, at 16:45 , littlebutty wrote:

I am curious to know what everyone thinks would be the best way to
store PDF files in postgres??

The BYTEA data type should do the trick.

I did exactly this for a DB I did for a former employer of mine.

Works great.

--
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 512-248-2683 E-Mail: ler@lerctr.org
US Mail: 430 Valona Loop, Round Rock, TX 78681-3683 US

#4John DeSoi
desoi@pgedit.com
In reply to: littlebutty (#1)
Re: storing PDFs

On Dec 29, 2005, at 5:45 PM, littlebutty wrote:

I have written software that will dynamically create PDF documents
used
within my web application. Because each document is unique, I would
like to store the resultant PDF into a field of the DB. Currently I
just store the file to the server's hard drive and insert a path to
the
file the database, but I would like to also store the actual file
itself in a field for redundancy purposes and other business reasons.
I am curious to know what everyone thinks would be the best way to
store PDF files in postgres??

The BYTEA type works for this purpose. In cases where the content can
be easily regenerated, I have also found it useful to put these
columns in tables within a separate schema and reference them from
the primary table with the details about the document. This allows
the database to be dumped without the large bytea fields which makes
daily backups smaller and easier to manage.

John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL

#5Leonel Nunez
lnunez@enelserver.com
In reply to: littlebutty (#1)
Re: storing PDFs

littlebutty wrote:

I have written software that will dynamically create PDF documents used
within my web application. Because each document is unique, I would
like to store the resultant PDF into a field of the DB. Currently I
just store the file to the server's hard drive and insert a path to the
file the database, but I would like to also store the actual file
itself in a field for redundancy purposes and other business reasons.
I am curious to know what everyone thinks would be the best way to
store PDF files in postgres??

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

You can use ByteA but the size will be about 4 times bigger
You can use varchar and encode to Base64 and wil be abour 30% bigger

Leonel

#6Doug McNaught
doug@mcnaught.org
In reply to: Leonel Nunez (#5)
Re: storing PDFs

Leonel Nunez <lnunez@enelserver.com> writes:

You can use ByteA but the size will be about 4 times bigger

Are you sure? The intermediate form for bytea (escaped single-quoted
strings) is pretty inefficient, but once in the database the data is
stored as binary and can even be compressed.

Plus, I'm pretty sure the protocol supports transmitting bytea fields
as binary over the wire if your client software can handle it.

-Doug

#7Leonel Nunez
lnunez@enelserver.com
In reply to: Doug McNaught (#6)
Re: storing PDFs

Doug McNaught wrote:

Leonel Nunez <lnunez@enelserver.com> writes:

You can use ByteA but the size will be about 4 times bigger

Are you sure? The intermediate form for bytea (escaped single-quoted
strings) is pretty inefficient, but once in the database the data is
stored as binary and can even be compressed.

Plus, I'm pretty sure the protocol supports transmitting bytea fields
as binary over the wire if your client software can handle it.

-Doug

I've made 2 pg_dumps from 2 different databases , 1 from a ByteA
stored images and 1 from the same images but stored as Base64 on
varchar and the
sql file for byteA was 4 times bigger than the size of all the
images on the Filesystem
and the sql for varchar with base64 was about 30% bigger than the
size on the filesystem

but If the bytea is encoded only for dump and load and on the
database are same size as the original file
then that's great and my perception is wrong

I'll check that

Leonel

#8Scott Ribe
scott_ribe@killerbytes.com
In reply to: Leonel Nunez (#7)
Re: storing PDFs

but If the bytea is encoded only for dump and load

I think that's the case, as with all binary types dump (consider numbers for
instance) to an ASCII encoding.

--
Scott Ribe
scott_ribe@killerbytes.com
http://www.killerbytes.com/
(303) 665-7007 voice