PostgreSQL 数据库统计信息查看

Table 9-73. Database Object Size Functions

NameReturn TypeDescription
pg_column_size(any)intNumber of bytes used to store a particular value (possibly compressed)
pg_database_size(oid)bigintDisk space used by the database with the specified OID
pg_database_size(name)bigintDisk space used by the database with the specified name
pg_indexes_size(regclass)bigintTotal disk space used by indexes attached to the specified table
pg_relation_size(relation regclass, fork text)bigintDisk space used by the specified fork (‘main’, ‘fsm’, ‘vm’, or ‘init’) of the specified table or index
pg_relation_size(relation regclass)bigintShorthand for pg_relation_size(..., 'main')
pg_size_pretty(bigint)textConverts a size in bytes expressed as a 64-bit integer into a human-readable format with size units
pg_size_pretty(numeric)textConverts a size in bytes expressed as a numeric value into a human-readable format with size units
pg_table_size(regclass)bigintDisk space used by the specified table, excluding indexes (but including TOAST, free space map, and visibility map)
pg_tablespace_size(oid)bigintDisk space used by the tablespace with the specified OID
pg_tablespace_size(name)bigintDisk space used by the tablespace with the specified name
pg_total_relation_size(regclass)bigintTotal disk space used by the specified table, including all indexes and TOAST data

所以,比如要查看 test 数据库的大小,则输入:

select pg_size_pretty(pg_database_size('test'));

POSTGRESQL 查看数据库 数据表大小

1、查看数据库大小:

select pg_database_size('log_analysis');
 pg_database_size 
------------------
         23799992
(1 row)

2、select pg_database.datname, pg_size_pretty (pg_database_size(pg_database.datname)) AS size from pg_database;

log_analysis=# select pg_database.datname, pg_size_pretty (pg_database_size(pg_database.datname)) AS size from pg_database; 

   datname    |  size   
--------------+---------
 template1    | 6594 kB
 template0    | 6457 kB
 postgres     | 6586 kB
 b2c_product  | 27 GB
 spider       | 11 MB
 crm          | 54 MB
 log_analysis | 23 MB
(7 rows)

log_analysis=# 

3、按顺序查看索引

select indexrelname, pg_size_pretty(pg_relation_size(relid)) from pg_stat_user_indexes where schemaname='public' order by pg_relation_size(relid) desc;
log_analysis=# select indexrelname, pg_size_pretty(pg_relation_size(relid)) from pg_stat_user_indexes where schemaname='public' order by pg_relation_size(relid) desc;

                        indexrelname                        | pg_size_pretty 
------------------------------------------------------------+----------------
 pk_dim_sight_area                                          | 184 kB
 idx_area_dim_sight_area                                    | 184 kB
 idx_city_dim_sight_area                                    | 184 kB
 idx_country_dim_sight_area                                 | 184 kB
 idx_region_dim_sight_area                                  | 184 kB
 pk_dim_page_type                                           | 8192 bytes
 cpc_supplier_sight_daily_pkey                              | 0 bytes

4、查看所有表的大小

select relname, pg_size_pretty(pg_relation_size(relid)) from pg_stat_user_tables where schemaname='public' order by pg_relation_size(relid) desc;
log_analysis=# select 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 
------------------------------------------------+----------------
 dim_sight_area                                 | 184 kB
 dim_page_type                                  | 8192 bytes
 wirelessapi_log_2014_08_08                     | 0 bytes
 trace_log_2014_08_04                           | 0 bytes
 dm_mobile                                      | 0 bytes
 trace_log_2014_07_14                           | 0 bytes
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值