Column storage (EXTERNAL/EXTENDED) settings for bytea/text column

From: Joel Stevenson <jstevenson(at)bepress(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Column storage (EXTERNAL/EXTENDED) settings for bytea/text column
Date: 2011-04-11 22:19:23
Message-ID: 469BA72B-2E6E-4E59-BAEE-2C9377ABB486@bepress.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

I'm trying to do some comparisons between the EXTERNAL and the EXTENDED storage methods on a bytea column and from the outside the setting doesn't appear to affect the value stored on initial insert, but perhaps I'm looking at the wrong numbers. If I create two new tables with a single bytea column and set one of them to external storage, then insert an existing bytea value from another table into each one, they appear to be of exactly the same size. This is using PG 9.0.3 on Debian Lenny, using the backports-sloppy deb package of PG 9.

(I've verified that the first table has "extended" storage via pg_attribute and that the second table has external.)

create table obj1 ( object bytea );
create table obj2 ( object bytea );
alter table obj2 alter column object set storage external;
insert into obj1 ( object ) select object from serialized_content where id = 12345;
insert into obj2 ( object ) select object from obj1;
select pg_total_relation_size('obj1') as o1, pg_total_relation_size( (select reltoastrelid from pg_class where relname = 'obj1' ) ) as otoast1, pg_total_relation_size('obj2') as o2, pg_total_relation_size( (select reltoastrelid from pg_class where relname = 'obj2' ) ) as otoast2;
o1 | otoast1 | o2 | otoast2
-------+---------+-------+---------
65536 | 57344 | 65536 | 57344
(1 row)

Now at this point if I perform a vacuum full on one or both, they'll both shrink down to a bit over half that size:

vacuum full obj1;
vacuum full obj2;
select pg_total_relation_size('obj1') as o1, pg_total_relation_size( (select reltoastrelid from pg_class where relname = 'obj1' ) ) as otoast1, pg_total_relation_size('obj2') as o2, pg_total_relation_size( (select reltoastrelid from pg_class where relname = 'obj2' ) ) as otoast2;
o1 | otoast1 | o2 | otoast2
-------+---------+-------+---------
40960 | 32768 | 40960 | 32768

This shrinkage doesn't occur with a normal vacuum, in fact the reported sizes increase if I do a normal vacuum at that point, but that's not germane to my question AFAICT.

Can I use the relation size like this to determine whether or not compression is happening for these toast columns? If not, is there a way that I can confirm that it is or isn't active? The results appear to be similar for text columns.

Thanks,
Joel

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Uwe Schroeder 2011-04-12 03:29:13 Why is 8.4 and 9.0 so much slower on some queries?
Previous Message Vibhor Kumar 2011-04-11 21:10:47 Re: CREATE RULE _copy AS ON COPY TO ...