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;

返回结果

相关推荐
与衫26 分钟前
在 VS Code 里看清你的数据流向:Gudu SQL Omni 实测体验
数据库·sql
Element_南笙1 小时前
吴恩达新课程:Agentic AI(笔记2)
数据库·人工智能·笔记·python·深度学习·ui·自然语言处理
长安城没有风1 小时前
从入门到精通【Redis】Redis 典型应⽤ --- 分布式锁
数据库·redis·分布式
Ytadpole1 小时前
MySQL 数据库优化设计:优化原理和数据库表设计技巧
数据库·mysql·优化·索引·查询·检索·表设计
christine-rr2 小时前
数据库基础概念体系梳理
数据库·oracle
SirLancelot12 小时前
StarRocks-基本介绍(一)基本概念、特点、适用场景
大数据·数据库·数据仓库·sql·数据分析·database·数据库架构
Boop_wu2 小时前
[MySQL] 基础操作
数据库·mysql
6极地诈唬2 小时前
【sqlite】xxx.db-journal是什么?
数据库·sqlite
小糖学代码4 小时前
MySQL:14.mysql connect
android·数据库·mysql·adb