Re: How much space do database objects take up in data files

Lists: pgsql-admin
From: "Peter Kovacs" <maxottovonstirlitz(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: How much space do database objects take up in data files
Date: 2008-02-13 18:43:36
Message-ID: b6e8f2e80802131043j70c15938ja094e45cd1559d5e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Hi,

How can I find out how much space is taken up by database objects in data files?

Thanks
Peter


From: paul socha <pawel(dot)socha(at)gmail(dot)com>
To: Peter Kovacs <maxottovonstirlitz(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: How much space do database objects take up in data files
Date: 2008-02-13 19:37:55
Message-ID: F57A5AF1-E873-42EF-BF5D-DC0ABC37D060@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Hi

Im not sure ;]
but ...

http://www.postgresql.org/docs/8.3/static/functions-admin.html
and table 9-54

merlin=# select tablename, pg_size_pretty(pg_relation_size
(tablename)) from pg_catalog.pg_tables where tableowner='merlin';;
tablename | pg_size_pretty
-----------+----------------
foo | 8192 bytes
ip | 8192 bytes
(2 rows)

On 2008-02-13, at 19:43, Peter Kovacs wrote:

> Hi,
>
> How can I find out how much space is taken up by database objects
> in data files?
>
> Thanks
> Peter

Pawel Socha
pawel(dot)socha(at)gmail(dot)com

perl -le 's**02).4^&-%2,).^9%4^!./4(%2^3,!#+7!2%^53%2&**y%& -;^[%"`-
{ a%%s%%$_%ee'


From: Carol Walter <walterc(at)indiana(dot)edu>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: How much space do database objects take up in data files
Date: 2008-02-13 20:13:41
Message-ID: 96FC91B8-A568-4781-80D5-0319AA27E8A3@indiana.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Hi,

I've struggled with this one too. You can get the size of databases
with SELECT pg_database_size('database name'); You can get the size
of tables with SELECT pg_relation_size('table name');

Carol
On Feb 13, 2008, at 1:43 PM, Peter Kovacs wrote:

> Hi,
>
> How can I find out how much space is taken up by database objects
> in data files?
>
> Thanks
> Peter
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq


From: Jeff Frost <jeff(at)frostconsultingllc(dot)com>
To: Carol Walter <walterc(at)indiana(dot)edu>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: How much space do database objects take up in data files
Date: 2008-02-13 20:46:23
Message-ID: Pine.LNX.4.64.0802131222500.5521@discord.home.frostconsultingllc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On Wed, 13 Feb 2008, Carol Walter wrote:

> I've struggled with this one too. You can get the size of databases with
> SELECT pg_database_size('database name'); You can get the size of tables
> with SELECT pg_relation_size('table name');
>
> Carol
> On Feb 13, 2008, at 1:43 PM, Peter Kovacs wrote:
>
>> Hi,
>>
>> How can I find out how much space is taken up by database objects in data
>> files?

Give this query a try. It's a variation of one posted on this list some time
ago. Unfortunately, I'm not sure who to credit for the original post. This
one takes into account index and toast size and sorts descending by totalsize.

SELECT nspname, relname,
pg_size_pretty(tablesize+indexsize+toastsize+toastindexsize) AS totalsize
FROM
(SELECT ns.nspname, cl.relname, pg_relation_size(cl.oid) AS tablesize,
COALESCE((SELECT SUM(pg_relation_size(indexrelid))::bigint
FROM pg_index WHERE cl.oid=indrelid), 0) AS indexsize,
CASE WHEN reltoastrelid=0 THEN 0
ELSE pg_relation_size(reltoastrelid)
END AS toastsize,
CASE WHEN reltoastrelid=0 THEN 0
ELSE pg_relation_size((SELECT reltoastidxid FROM pg_class ct
WHERE ct.oid = cl.reltoastrelid))
END AS toastindexsize
FROM pg_class cl, pg_namespace ns
WHERE cl.relnamespace = ns.oid
AND ns.nspname NOT IN ('pg_catalog', 'information_schema')
AND cl.relname IN
(SELECT table_name FROM information_schema.tables
WHERE table_type = 'BASE TABLE')) ss
ORDER BY tablesize+indexsize+toastsize+toastindexsize DESC;

--
Jeff Frost, Owner <jeff(at)frostconsultingllc(dot)com>
Frost Consulting, LLC http://www.frostconsultingllc.com/
Phone: 650-780-7908 FAX: 650-649-1954


From: "Peter Kovacs" <peter(dot)kovacs(dot)1(dot)0rc(at)gmail(dot)com>
To: "Jeff Frost" <jeff(at)frostconsultingllc(dot)com>
Cc: "Carol Walter" <walterc(at)indiana(dot)edu>, pgsql-admin(at)postgresql(dot)org
Subject: Re: How much space do database objects take up in data files
Date: 2008-02-13 21:05:55
Message-ID: b6e8f2e80802131305m76cb5fa5i6632f28533761bbe@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Howooow!!! Great!!!

Thanks a lot.
Peter

On Feb 13, 2008 9:46 PM, Jeff Frost <jeff(at)frostconsultingllc(dot)com> wrote:
> On Wed, 13 Feb 2008, Carol Walter wrote:
>
> > I've struggled with this one too. You can get the size of databases with
> > SELECT pg_database_size('database name'); You can get the size of tables
> > with SELECT pg_relation_size('table name');
> >
> > Carol
> > On Feb 13, 2008, at 1:43 PM, Peter Kovacs wrote:
> >
> >> Hi,
> >>
> >> How can I find out how much space is taken up by database objects in data
> >> files?
>
> Give this query a try. It's a variation of one posted on this list some time
> ago. Unfortunately, I'm not sure who to credit for the original post. This
> one takes into account index and toast size and sorts descending by totalsize.
>
> SELECT nspname, relname,
> pg_size_pretty(tablesize+indexsize+toastsize+toastindexsize) AS totalsize
> FROM
> (SELECT ns.nspname, cl.relname, pg_relation_size(cl.oid) AS tablesize,
> COALESCE((SELECT SUM(pg_relation_size(indexrelid))::bigint
> FROM pg_index WHERE cl.oid=indrelid), 0) AS indexsize,
> CASE WHEN reltoastrelid=0 THEN 0
> ELSE pg_relation_size(reltoastrelid)
> END AS toastsize,
> CASE WHEN reltoastrelid=0 THEN 0
> ELSE pg_relation_size((SELECT reltoastidxid FROM pg_class ct
> WHERE ct.oid = cl.reltoastrelid))
> END AS toastindexsize
> FROM pg_class cl, pg_namespace ns
> WHERE cl.relnamespace = ns.oid
> AND ns.nspname NOT IN ('pg_catalog', 'information_schema')
> AND cl.relname IN
> (SELECT table_name FROM information_schema.tables
> WHERE table_type = 'BASE TABLE')) ss
> ORDER BY tablesize+indexsize+toastsize+toastindexsize DESC;
>
>
>
> --
> Jeff Frost, Owner <jeff(at)frostconsultingllc(dot)com>
> Frost Consulting, LLC http://www.frostconsultingllc.com/
> Phone: 650-780-7908 FAX: 650-649-1954
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>


From: "Peter Kovacs" <maxottovonstirlitz(at)gmail(dot)com>
To: "Jeff Frost" <jeff(at)frostconsultingllc(dot)com>
Cc: "Carol Walter" <walterc(at)indiana(dot)edu>, pgsql-admin(at)postgresql(dot)org
Subject: Re: How much space do database objects take up in data files
Date: 2008-02-13 23:15:37
Message-ID: b6e8f2e80802131515v56bf38d1ybfd61b4e1afe5e99@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Thanks, appears to work great!!
Peter

On Feb 13, 2008 9:46 PM, Jeff Frost <jeff(at)frostconsultingllc(dot)com> wrote:
> On Wed, 13 Feb 2008, Carol Walter wrote:
>
> > I've struggled with this one too. You can get the size of databases with
> > SELECT pg_database_size('database name'); You can get the size of tables
> > with SELECT pg_relation_size('table name');
> >
> > Carol
> > On Feb 13, 2008, at 1:43 PM, Peter Kovacs wrote:
> >
> >> Hi,
> >>
> >> How can I find out how much space is taken up by database objects in data
> >> files?
>
> Give this query a try. It's a variation of one posted on this list some time
> ago. Unfortunately, I'm not sure who to credit for the original post. This
> one takes into account index and toast size and sorts descending by totalsize.
>
> SELECT nspname, relname,
> pg_size_pretty(tablesize+indexsize+toastsize+toastindexsize) AS totalsize
> FROM
> (SELECT ns.nspname, cl.relname, pg_relation_size(cl.oid) AS tablesize,
> COALESCE((SELECT SUM(pg_relation_size(indexrelid))::bigint
> FROM pg_index WHERE cl.oid=indrelid), 0) AS indexsize,
> CASE WHEN reltoastrelid=0 THEN 0
> ELSE pg_relation_size(reltoastrelid)
> END AS toastsize,
> CASE WHEN reltoastrelid=0 THEN 0
> ELSE pg_relation_size((SELECT reltoastidxid FROM pg_class ct
> WHERE ct.oid = cl.reltoastrelid))
> END AS toastindexsize
> FROM pg_class cl, pg_namespace ns
> WHERE cl.relnamespace = ns.oid
> AND ns.nspname NOT IN ('pg_catalog', 'information_schema')
> AND cl.relname IN
> (SELECT table_name FROM information_schema.tables
> WHERE table_type = 'BASE TABLE')) ss
> ORDER BY tablesize+indexsize+toastsize+toastindexsize DESC;
>
>
>
> --
> Jeff Frost, Owner <jeff(at)frostconsultingllc(dot)com>
> Frost Consulting, LLC http://www.frostconsultingllc.com/
> Phone: 650-780-7908 FAX: 650-649-1954
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>