pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedCompression of text fields
3+ messages / 3 participants
[nested] [flat]
* Compression of text fields
@ 2003-08-20 16:00 Brian McCane <bmccane@mccons.net>
2003-08-20 16:26 ` Re: Compression of text fields Stephan Szabo <sszabo@megazone.bigpanda.com>
0 siblings, 1 reply; 3+ messages in thread
From: Brian McCane @ 2003-08-20 16:00 UTC (permalink / raw)
To: pgsql-admin
I have read somewhere that text fields are "compressed". What I
am curious about is how the compression of text fields by PostgreSQL might
be affecting the performance of my software. I currently store entire
copies of documents in a table called "fulltext" as such:
CREATE TABLE fulltext (
uid serial8 PRIMARY KEY,
content text NOT NULL,
contentidx txtidx
) ;
As you can see, I am using contrib/tsearch to find documents for display,
and then I dump out 'content' to the user.
Anyway, when I first created this table, I was concerned about the size of
'content' so I linked my program to zlib and deflate the content field
before storing it into the table. This means that every time someone
views a document I have to inflate it, also if what I have read is correct
about the text fields, PostgreSQL is trying to deflate/compress/whatever
the field when it stores it so I am duplicating effort. This probably
slows down the performance of my software, and because compressed
documents are often larger when re-compressed (at least with older
algorithms like LZW) I might be using extra space to store my data.
So:
1) do text fields get compressed
2) what compression method is used
3) is there a way to view actual storage space used versus
the value I get from length()
4) Can I disable the compression to improve storage speed
if the compression algorithm is not as good as deflate
- brian
Wm. Brian McCane | Life is full of doors that won't open
Search http://recall.maxbaud.net/ | when you knock, equally spaced amid those
Usenet http://freenews.maxbaud.net/ | that open when you don't want them to.
Auction http://www.sellit-here.com/ | - Roger Zelazny "Blood of Amber"
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Compression of text fields
2003-08-20 16:00 Compression of text fields Brian McCane <bmccane@mccons.net>
@ 2003-08-20 16:26 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2003-08-20 17:11 ` Re: Compression of text fields Joe Conway <mail@joeconway.com>
0 siblings, 1 reply; 3+ messages in thread
From: Stephan Szabo @ 2003-08-20 16:26 UTC (permalink / raw)
To: Brian McCane <bmccane@mccons.net>; +Cc: pgsql-admin
On Wed, 20 Aug 2003, Brian McCane wrote:
> I have read somewhere that text fields are "compressed". What I
> am curious about is how the compression of text fields by PostgreSQL might
> be affecting the performance of my software. I currently store entire
> copies of documents in a table called "fulltext" as such:
>
> CREATE TABLE fulltext (
> uid serial8 PRIMARY KEY,
> content text NOT NULL,
> contentidx txtidx
> ) ;
>
> As you can see, I am using contrib/tsearch to find documents for display,
> and then I dump out 'content' to the user.
>
> Anyway, when I first created this table, I was concerned about the size of
> 'content' so I linked my program to zlib and deflate the content field
> before storing it into the table. This means that every time someone
> views a document I have to inflate it, also if what I have read is correct
> about the text fields, PostgreSQL is trying to deflate/compress/whatever
> the field when it stores it so I am duplicating effort. This probably
> slows down the performance of my software, and because compressed
> documents are often larger when re-compressed (at least with older
> algorithms like LZW) I might be using extra space to store my data.
>
> So:
> 1) do text fields get compressed
They can (if large enough and depending on their storage attributes).
If the value turns out bigger it won't store the larger compressed
one though (but it'll still attempt to compress it on insert).
> 2) what compression method is used
Looks like some LZ.
> 4) Can I disable the compression to improve storage speed
> if the compression algorithm is not as good as deflate
See ALTER TABLE ALTER COLUMN SET STORAGE (I would guess you would want
external, but I'm not 100% sure, check the docs :) )
Also, I'm not sure if storing a compressed version in a text field is a
good idea. I'd think that bytea would be a better match.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Compression of text fields
2003-08-20 16:00 Compression of text fields Brian McCane <bmccane@mccons.net>
2003-08-20 16:26 ` Re: Compression of text fields Stephan Szabo <sszabo@megazone.bigpanda.com>
@ 2003-08-20 17:11 ` Joe Conway <mail@joeconway.com>
0 siblings, 0 replies; 3+ messages in thread
From: Joe Conway @ 2003-08-20 17:11 UTC (permalink / raw)
To: Stephan Szabo <sszabo@megazone.bigpanda.com>; +Cc: Brian McCane <bmccane@mccons.net>; pgsql-admin
Stephan Szabo wrote:
> On Wed, 20 Aug 2003, Brian McCane wrote:
>> 4) Can I disable the compression to improve storage speed
>> if the compression algorithm is not as good as deflate
>
> See ALTER TABLE ALTER COLUMN SET STORAGE (I would guess you would want
> external, but I'm not 100% sure, check the docs :) )
Yes, EXTERNAL is correct. We had a good thread on this topic on PERFORM
a couple of weeks ago.
Starts here:
http://archives.postgresql.org/pgsql-performance/2003-08/msg00030.php
Ends here:
http://archives.postgresql.org/pgsql-performance/2003-08/msg00144.php
Note the issue with UPDATE in place of the data. You need to concatenate
an empty string to force the change of storage.
> Also, I'm not sure if storing a compressed version in a text field is a
> good idea. I'd think that bytea would be a better match.
>
You can pretty much guarantee problems if you store binary (i.e.
pre-compressed) data in a text field. If your uncompressed data is not
binary, you should probably do one of these options:
1) pre-compress and store in a bytea field with storage set to EXTERNAL
2) store as-is in a text field and let Postgres do the compression for
you
3) store as-is in a text field with storage set to EXTERNAL
Personally, I'd use #3 if you consider disk space cheap and performance
important, or #2 if you really need the data compressed. You might get
moderately better compression using an external program, but it is
probably at a big performance hit.
HTH,
Joe
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-08-20 17:11 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-20 16:00 Compression of text fields Brian McCane <bmccane@mccons.net>
2003-08-20 16:26 ` Stephan Szabo <sszabo@megazone.bigpanda.com>
2003-08-20 17:11 ` Joe Conway <mail@joeconway.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox