PostgreSQL查询表的live tuples和dead tuples

由于PostgreSQL的多版本特性,我们需要经常定期的去查看哪些表上的dead tuples过多,然后对其进行vacuum,提升数据库的性能,下面两个脚本可以进行查看:

–脚本1:

SELECT 
	relname AS ObjectName
	,pg_stat_get_live_tuples(c.oid) AS LiveTuples
	,pg_stat_get_dead_tuples(c.oid) AS DeadTuples
FROM pg_class c order by 3 desc;

–脚本2:

SELECT 
	relname AS TableName
	,n_live_tup AS LiveTuples
	,n_dead_tup AS DeadTuples
FROM pg_stat_user_tables order by 3 desc;

猜你喜欢

转载自blog.csdn.net/weixin_39540651/article/details/115357830