统计greenplum/postgresql数据占用存储情况

文章目录

1. 场景描述

因项目数据量略大,每天大概有几百g的存储需求,并且是多项目公用greenplum集群,需要定期检查一下磁盘情况。

2. 解决方案

2.1 按用户/项目统计

2.1.1 SQL语句
 SELECT d.datname AS Name,  pg_catalog.pg_get_userbyid(d.datdba) AS Owner,
    CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
        THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))
        ELSE 'No Access'
    END AS SIZE
FROM pg_catalog.pg_database d
    ORDER BY
    CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')
        THEN pg_catalog.pg_database_size(d.datname)
        ELSE NULL
    END DESC -- nulls first
    LIMIT 20;

2.1.2 效果图

统计greenplum/postgresql数据占用存储情况

2.2 按表统计

2.2.1 SQL语句
SELECT
    table_schema || '.' || table_name AS table_full_name,
    pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS size
FROM information_schema.tables
ORDER BY
    pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC;
2.2.2 效果图

统计greenplum/postgresql数据占用存储情况


如果觉得还可以的话,右上角点个赞呗!

如有不准确的地方或者疑问,可在讨论区/QQ/微信公共号沟通,谢谢!

上一篇:catalog和switch迁移数据文件目录


下一篇:php – Magento产品在前端不能始终如一地出现