PostgreSQL 查询库中所有表占用磁盘大小、表大小

sql 复制代码
SELECT
  n.nspname AS schema_name,
  c.relname AS table_name,

  -- 1️⃣ 总大小(表 + toast + 索引)
  pg_size_pretty(pg_total_relation_size(c.oid)) AS total_size,

  -- 2️⃣ 表不包含索引(含 TOAST)
  pg_size_pretty(pg_total_relation_size(c.oid) - pg_indexes_size(c.oid)) AS without_index_size,

  -- 3️⃣ 仅表本体(不含 TOAST、不含索引)
  pg_size_pretty(pg_relation_size(c.oid)) AS table_only_size,

  -- 4️⃣ 索引大小(不含 TOAST)
  pg_size_pretty(pg_indexes_size(c.oid)) AS index_size

FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE c.relkind = 'r'  -- 普通表
  AND n.nspname NOT IN ('pg_catalog', 'information_schema')
--	AND  c.relname  = 'appraisal_history_sales'
ORDER BY pg_total_relation_size(c.oid) DESC;

返回结果

相关推荐
笃行3505 小时前
国产化落地避坑 · 干货向|Oracle 迁金仓 KES,我把外连接消除排在隐性陷阱第一位
数据库
老纪的技术唠嗑局5 小时前
花一年时间整理出的:AI 数据库混合搜索入门实践
数据库
川石课堂软件测试6 小时前
安全测试|常见SQL注入攻击方式、实例及预防
服务器·数据库·sql·功能测试·测试工具·安全·单元测试
笃行3506 小时前
国产化落地避坑 · 干货向|迁移后那条「测试能过、一上生产就查空」的 SQL,多半栽在 WHERE 函数顺序上
数据库
蓝田~7 小时前
MySQL慢查询怎么优化?B+Tree索引原理+MVCC读不阻塞写+EXPLAIN执行计划,从5秒到0.05秒
数据库·mysql
sunxunyong8 小时前
doris用户资源组配置
数据库
Cloud云卷云舒8 小时前
云卷云舒:HaishanDB的AI原生能力主要应用场景
数据库·人工智能·ai-native·haishandb·移动云长期记忆
时间的拾荒人8 小时前
MySQL 视图详解
android·数据库·mysql
qq_366086228 小时前
sql 查询中关于 null 值判断的问题
数据库·sql
测试修炼手册8 小时前
[测试技术] JUnit 6 入门与实战:断言、参数化与 Mockito
数据库·junit·sqlserver