1、查询所有数据库占用空间大小

SELECT datname, pg_size_pretty(pg_database_size(datname)) AS size FROM pg_database;

2、查询数据库所有表空间占用空间大小


SELECT spcname, pg_size_pretty(pg_tablespace_size(spcname)) AS size FROM pg_tablespace;

3、查询单个数据库表占用空间大小


SELECT pg_size_pretty(pg_total_relation_size('t_audit_log')) AS size;

4、查询所有数据库表占用空间大小


SELECT
    table_schema,
    table_name,
    pg_size_pretty(pg_total_relation_size('"'||table_schema||'"."'||table_name||'"')) as size
FROM information_schema.tables
WHERE table_schema NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_total_relation_size('"'||table_schema||'"."'||table_name||'"') DESC;


 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐