Postgresql:查看表、索引、表空间大小,top 10
在PostgreSQL中,您可以使用以下SQL查询来查看表、索引和表空间的大小,并按大小排序前10名。
查看表大小:
SELECT
relname AS table_name,
pg_size_pretty(pg_total_relation_size(relid)) AS size
FROM
pg_catalog.pg_statio_user_tables
ORDER BY
pg_total_relation_size(relid) DESC
LIMIT 10;
查看索引大小:
SELECT
relname AS index_name,
pg_size_pretty(pg_relation_size(relid)) AS size
FROM
pg_catalog.pg_statio_user_indexes
ORDER BY
pg_relation_size(relid) DESC
LIMIT 10;
查看表空间大小:
SELECT
spcname AS tablespace_name,
pg_size_pretty(pg_tablespace_size(spcname)) AS size
FROM
pg_tablespace
ORDER BY
pg_tablespace_size(spcname) DESC
LIMIT 10;
请注意,这些查询可能需要您具有足够的权限来执行。如果您没有权限,您可能需要联系数据库管理员。
评论已关闭