2002-06-13 05:09:09 +08:00
|
|
|
This utility allows administrators to view the file structure used by
|
|
|
|
PostgreSQL. Databases are placed in directories based on their OIDs in
|
|
|
|
pg_database, and the tables in that directory are named by their OIDs,
|
|
|
|
stored in pg_class.relfilenode. Oid2name connects to the database and
|
|
|
|
extracts the OID and table name information.
|
2001-01-24 08:41:25 +08:00
|
|
|
|
2002-06-13 05:09:09 +08:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
It can be used in four ways:
|
|
|
|
|
|
|
|
|
|
|
|
oid2name
|
2001-01-24 08:41:25 +08:00
|
|
|
|
|
|
|
This will connect to the template1 database and display all databases
|
2002-06-13 05:09:09 +08:00
|
|
|
in the system:
|
2001-01-24 08:41:25 +08:00
|
|
|
|
2002-06-13 05:09:09 +08:00
|
|
|
$ oid2name
|
2001-01-24 08:41:25 +08:00
|
|
|
All databases:
|
|
|
|
---------------------------------
|
|
|
|
18720 = test1
|
|
|
|
1 = template1
|
|
|
|
18719 = template0
|
|
|
|
18721 = test
|
|
|
|
18735 = postgres
|
|
|
|
18736 = cssi
|
|
|
|
|
|
|
|
|
2002-06-13 05:09:09 +08:00
|
|
|
oid2name -d test [-x]
|
2001-01-24 08:41:25 +08:00
|
|
|
|
2002-06-13 05:09:09 +08:00
|
|
|
This connects to the database test and shows all tables and their OIDs:
|
|
|
|
|
|
|
|
$ oid2name -d test
|
2001-01-24 08:41:25 +08:00
|
|
|
All tables from database "test":
|
|
|
|
---------------------------------
|
|
|
|
18766 = dns
|
|
|
|
18737 = ips
|
|
|
|
18722 = testdate
|
|
|
|
|
2002-06-13 05:09:09 +08:00
|
|
|
|
|
|
|
oid2name -d test -o 18737
|
|
|
|
oid2name -d test -t testdate
|
2001-01-24 08:41:25 +08:00
|
|
|
|
|
|
|
This will connect to the database test and display the table name for oid
|
2002-06-13 05:09:09 +08:00
|
|
|
18737 and the oid for table name testdate respectively:
|
2001-01-24 08:41:25 +08:00
|
|
|
|
2002-06-13 05:09:09 +08:00
|
|
|
$ oid2name -d test -o 18737
|
2001-01-24 08:41:25 +08:00
|
|
|
Tablename of oid 18737 from database "test":
|
|
|
|
---------------------------------
|
|
|
|
18737 = ips
|
|
|
|
|
|
|
|
|
2002-06-13 05:09:09 +08:00
|
|
|
$ oid2name -d test -t testdate
|
2001-01-24 08:41:25 +08:00
|
|
|
Oid of table testdate from database "test":
|
2002-06-13 05:09:09 +08:00
|
|
|
---------------------------------
|
2001-01-24 08:41:25 +08:00
|
|
|
18722 = testdate
|
|
|
|
|
2002-06-13 05:09:09 +08:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Sample session:
|
|
|
|
|
|
|
|
$ cd /u/pg/data/base
|
|
|
|
$ oid2name
|
|
|
|
All databases:
|
|
|
|
---------------------------------
|
|
|
|
16817 = test2
|
|
|
|
16578 = x
|
|
|
|
16756 = test
|
|
|
|
1 = template1
|
|
|
|
16569 = template0
|
|
|
|
16818 = test3
|
|
|
|
16811 = floattest
|
|
|
|
|
|
|
|
$ cd 16756
|
|
|
|
$ ls 1873*
|
|
|
|
18730 18731 18732 18735 18736 18737 18738 18739
|
|
|
|
|
|
|
|
$ oid2name -d test -o 18737
|
|
|
|
Tablename of oid 18737 from database "test":
|
|
|
|
---------------------------------
|
|
|
|
18737 = ips
|
|
|
|
|
|
|
|
$ oid2name -d test -t ips
|
|
|
|
Oid of table ips from database "test":
|
|
|
|
---------------------------------
|
|
|
|
18737 = ips
|
|
|
|
|
2002-06-13 08:21:52 +08:00
|
|
|
$ # show disk space for every db object
|
2002-06-13 05:09:09 +08:00
|
|
|
$ du * | while read SIZE OID
|
|
|
|
> do
|
|
|
|
> echo "$SIZE `oid2name -q -d test -o $OID`"
|
|
|
|
> done
|
|
|
|
24 18737 = ips
|
|
|
|
36 18722 = cities
|
|
|
|
...
|
|
|
|
|
2002-06-13 08:21:52 +08:00
|
|
|
$ # same as above, but sort by largest first
|
2002-06-13 05:09:09 +08:00
|
|
|
$ du * | while read SIZE OID
|
|
|
|
> do
|
|
|
|
> echo "$SIZE `oid2name -q -d test -o $OID`"
|
|
|
|
> done |
|
|
|
|
> sort -rn
|
|
|
|
2048 19324 = bigtable
|
|
|
|
1950 23903 = customers
|
|
|
|
...
|
|
|
|
|
2002-06-13 08:21:52 +08:00
|
|
|
$ # show disk usage per database
|
|
|
|
$ cd /u/pg/data/base
|
|
|
|
$ du -s * |
|
|
|
|
> while read SIZE OID
|
|
|
|
> do
|
|
|
|
> echo "$SIZE `aspg oid2name -q | grep ^$OID' '`"
|
|
|
|
> done |
|
|
|
|
> sort -rn
|
|
|
|
2256 18721 = test
|
|
|
|
2135 18735 = postgres
|
|
|
|
..
|
|
|
|
|
2002-06-13 08:54:05 +08:00
|
|
|
This can be done in psql with:
|
2002-06-13 07:41:50 +08:00
|
|
|
|
2002-06-13 07:42:48 +08:00
|
|
|
test=> SELECT relpages, relfilenode, relname FROM pg_class ORDER BY relpages DESC;
|
2002-06-13 07:41:50 +08:00
|
|
|
|
2002-06-13 08:54:05 +08:00
|
|
|
Each page is typically 8k. Relpages is updated by VACUUM.
|
2002-06-13 05:09:09 +08:00
|
|
|
|
|
|
|
---------------------------------------------------------------------------
|
2001-01-24 08:41:25 +08:00
|
|
|
|
|
|
|
Mail me with any problems or additions you would like to see. Clearing
|
2002-06-13 05:09:09 +08:00
|
|
|
house for the code will be at: http://www.crimelabs.net
|
2001-01-24 08:41:25 +08:00
|
|
|
|
|
|
|
b. palmer, bpalmer@crimelabs.net
|