1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
-- 查看数据库大小
SELECT pg_size_pretty(pg_database_size('db1'));
-- 查询所有数据文件对象的大小
SELECT object_type, object_name, schema_name, size FROM
(SELECT
'Table' AS object_type,
relname AS object_name,
schemaname AS schema_name,
pg_total_relation_size(relid) as size_bytes,
pg_size_pretty(pg_total_relation_size(relid)) AS size
FROM
pg_catalog.pg_statio_user_tables
UNION
SELECT
'Index' AS object_type,
indexrelname AS object_name,
schemaname AS schema_name,
pg_total_relation_size(indexrelid) as size_bytes,
pg_size_pretty(pg_total_relation_size(indexrelid)) AS size
FROM
pg_catalog.pg_stat_all_indexes
) as data
ORDER BY
size_bytes DESC;
--- 只查看表大小
SELECT
'Table' AS object_type,
relname AS object_name,
schemaname AS schema_name,
pg_total_relation_size(relid) as size_bytes,
pg_size_pretty(pg_total_relation_size(relid)) AS size
FROM
pg_catalog.pg_statio_user_tables
ORDER BY
size_bytes DESC;
|