如何在 PostgreSQL 中列出 table 的所有索引及其相应的大小?
How to list all indexes of a table with their corresponding size in PostgreSQL?
我可以查看 table 和
中所有索引的总大小
SELECT pg_size_pretty (pg_indexes_size('table_name'));
以及特定索引的大小:
select pg_size_pretty(pg_relation_size('index_name'));
,
但我想分别检索 table 的每个索引的大小信息列表 (索引大小列表及其所属的相应索引名称).
select indexname, pg_size_pretty(pg_relation_size(indexname::regclass)) as size
from pg_indexes
where tablename = 'my_table';
您可以使用 \di+
psql 命令:
postgres=> \di+ schema.*
List of relations
Schema | Name | Type | Owner | Table | Persistence | Size | Description
--------+--------+-------+-------+----------------------+--------+-------------
schema | index1 | index | owner | table1 | permanent | 139 MB |
schema | index2 | index | owner | table1 | permanent | 77 MB |
schema | index3 | index | owner | table1 | permanent | 73 MB |
schema | index4 | index | owner | table1 | permanent | 38 MB |
(4 rows)
我可以查看 table 和
中所有索引的总大小SELECT pg_size_pretty (pg_indexes_size('table_name'));
以及特定索引的大小:
select pg_size_pretty(pg_relation_size('index_name'));
,
但我想分别检索 table 的每个索引的大小信息列表 (索引大小列表及其所属的相应索引名称).
select indexname, pg_size_pretty(pg_relation_size(indexname::regclass)) as size
from pg_indexes
where tablename = 'my_table';
您可以使用 \di+
psql 命令:
postgres=> \di+ schema.*
List of relations
Schema | Name | Type | Owner | Table | Persistence | Size | Description
--------+--------+-------+-------+----------------------+--------+-------------
schema | index1 | index | owner | table1 | permanent | 139 MB |
schema | index2 | index | owner | table1 | permanent | 77 MB |
schema | index3 | index | owner | table1 | permanent | 73 MB |
schema | index4 | index | owner | table1 | permanent | 38 MB |
(4 rows)