PG物件檢視

wongchaofan發表於2024-07-20

檢視錶物件大小

SELECT pg_size_pretty(pg_relation_size('mhrordhu_shk.mut_kharedi_audit'));
 pg_size_pretty
----------------
 238 MB
(1 row)
SELECT pg_size_pretty(pg_total_relation_size('mhrordhu_shk.mut_kharedi_audit'));
 pg_size_pretty
----------------
 268 MB
(1 row)

獲取 Postgres 中所有資料庫的列表及其大小(以 GB 為單位),按最大大小排序

SELECT pg_database.datname as "database_name", pg_database_size(pg_database.datname)/1024/1024/1024 AS size_in_GB FROM pg_database ORDER by size_in_GB DESC;
 database_name | size_in_gb
---------------+------------
 mumbai        |        422
 template1     |          0
 template0     |          0
(3 rows)

使用元命令獲取 Postgres 中所有資料庫及其大小的列表

nellore=# \l+

查詢當前資料庫中所有表大小的指令碼。

SELECT
    table_schema || '.' || table_name AS TableName,
    pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS TableSize
FROM information_schema.tables
ORDER BY
    pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC

相關文章