PostgeSQL 存储空间的查询

运维的同事要去检查数据库表的大小,分享一下:

单表:

SELECT 
	pg_size_pretty ( pg_relation_size ( [表名] ) );

所有表:

SELECT
	table_schema || '.' || TABLE_NAME AS table_full_name,
	pg_size_pretty ( pg_total_relation_size ( '"' || table_schema || '"."' || TABLE_NAME || '"' ) ) AS SIZE 
FROM
	information_schema.tables 
ORDER BY
	pg_total_relation_size ( '"' || table_schema || '"."' || TABLE_NAME || '"' ) DESC 

数据与索引占比:

SELECT 
	TABLE_NAME,
	pg_size_pretty ( table_size ) AS table_size,
	pg_size_pretty ( indexes_size ) AS indexes_size,
	pg_size_pretty ( total_size ) AS total_size 
FROM
	(
	SELECT 
		TABLE_NAME,
		pg_table_size ( TABLE_NAME ) AS table_size,
		pg_indexes_size ( TABLE_NAME ) AS indexes_size,
		pg_total_relation_size ( TABLE_NAME ) AS total_size 
	FROM
		( SELECT ( '"' || table_schema || '"."' || TABLE_NAME || '"' ) AS TABLE_NAME FROM information_schema.tables ) AS all_tables 
	ORDER BY
	total_size DESC 
	) AS pretty_sizes

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值