Re: table names - Mailing list pgsql-general

From Brent Verner
Subject Re: table names
Date
Msg-id 20011117013156.A12103@rcfile.org
Whole thread Raw
In response to table names  ("K. Ari Krupnikov" <ari@cogsci.ed.ac.uk>)
List pgsql-general
On 16 Nov 2001 at 16:08 (+0000), K. Ari Krupnikov wrote:
| from 7.1 release notes:
|
| > Store tables as files named by OID (Vadim)
|
| until i upgraded to 7.1(.3), i used to track table sizes simply with ls
| -l. is there a simple way to see how much space a table takes on disk,
| short of
|
| select 'ln -s ' || oid || ' ' || relname from pg_class
| where relname not like 'pg%';

I've written some functions to enable:

brent=# SELECT oid, datname, pg_du_db(datname)
brent-# AS diskusage FROM pg_database;
  oid   |  datname  | diskusage
--------+-----------+-----------
 190550 | brent     |      1788
      1 | template1 |      1714
  16555 | template0 |      1714
(3 rows)

brent=# select relname,pg_du_rel(relname) as diskusage from pg_class
brent-# where (relkind='r' or relkind='i') and relname not like 'pg_%';
   relname   | diskusage
-------------+-----------
 test_id_key |        17
 test        |         9
(2 rows)

the 'diskusage' is only an approximate value in Kb.  The first query
returns diskusage by database name; the second returns diskusage by
relation name (on the current database connection).  This is/was
largely done out of needing to track database size (for billing
purposes) -- I know a small shell script could do it, but I felt
like cutting my teeth on a simple c module, so the implementation
is less than perfect...

Tested on 7.1 and 7.2b2 -- no (major) problems encountered.

Read the README.

cheers.
  brent

--
"Develop your talent, man, and leave the world something. Records are
really gifts from people. To think that an artist would love you enough
to share his music with anyone is a beautiful thing."  -- Duane Allman

pgsql-general by date:

Previous
From: Brent Verner
Date:
Subject: Re: table names
Next
From: Grant Table
Date:
Subject: Re: Triggers, functions and column names: a poser