lect relname, pg_size_pretty(pg_relation_size(relid)) from pg_stat_user_tables where schemaname='public' order by pg_relation_size(relid) desc;
relname | pg_size_pretty
-------------------------------+----------------
test | 91 MB
testtable | 1424 kB
city | 256 kB
countrylanguage | 56 kB
country | 40 kB
testcount | 8192 bytes
tbl_partition_201302 | 8192 bytes
tbl_partition_201303 | 8192 bytes
person | 8192 bytes
customer | 8192 bytes
american_state | 8192 bytes
tbl_david | 8192 bytes
emp | 8192 bytes
tbl_partition_201212 | 8192 bytes
tbl_partition_201304 | 8192 bytes
tbl_partition_error_join_date | 8192 bytes
tbl_partition_201211 | 8192 bytes
album | 8192 bytes
tbl_partition_201307 | 8192 bytes
tbl_xulie | 8192 bytes
tbl_partition_201301 | 8192 bytes
sale | 8192 bytes
item | 8192 bytes
track | 8192 bytes
tbl_partition_201306 | 0 bytes
tbl_partition | 0 bytes
tbl_partition_201305 | 0 bytes
person2 | 0 bytes
(28 rows)
david=#
3.10 查看表空间大小
david=# select spcname from pg_tablespace;
spcname
------------
pg_default
pg_global
(2 rows)
david=# select pg_tablespace_size('pg_default');
pg_tablespace_size
--------------------
28381579760
(1 row)
david=# select pg_size_pretty(pg_tablespace_size('pg_default'));
pg_size_pretty
----------------
26 GB
(1 row)
david=#
另一种查看方法:
david=# select pg_tablespace_size('pg_default')/1024/1024 as "SIZE M";
SIZE M
--------
27066
(1 row)
david=# select pg_tablespace_size('pg_default')/1024/1024/1024 as "SIZE G";
SIZE G
--------
26
(1 row)
david=#