From 3be0580f8cc1faa8eccdd40c6b432aeb27c39b20 Mon Sep 17 00:00:00 2001 From: iProbe Date: Tue, 31 Jan 2023 15:30:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20'=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93/oracle/=E6=9F=A5=E8=AF=A2=E5=85=B7=E4=BD=93=E8=A1=A8?= =?UTF-8?q?=E5=8D=A0=E7=94=A8=E7=9A=84=E7=A9=BA=E9=97=B4.md'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 数据库/oracle/查询具体表占用的空间.md | 85 +++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 数据库/oracle/查询具体表占用的空间.md diff --git a/数据库/oracle/查询具体表占用的空间.md b/数据库/oracle/查询具体表占用的空间.md new file mode 100644 index 0000000..1bb260c --- /dev/null +++ b/数据库/oracle/查询具体表占用的空间.md @@ -0,0 +1,85 @@ +## 当前用户表占用空间 +```sql +select SEGMENT_NAME as TABLE_NAME,BYTES/1024/1024 as 大小MB +from USER_SEGMENTS +where SEGMENT_TYPE='TABLE' +order by BYTES desc; +``` +## 所有用户表占用空间 +```sql +select OWNER,SEGMENT_NAME as TABLE_NAME,BYTES/1024/1024 as 大小MB +from DBA_SEGMENTS +where SEGMENT_TYPE='TABLE' +order by OWNER,BYTES desc; +``` +## 查询表空间及表空间所占空间大小 +```sql +SELECT + tablespace_name, + sum( bytes ) / 1024 / 1024 +FROM + dba_data_files +GROUP BY + tablespace_name; +``` +## 查询表空间物理文件的名称及大小 +```sql +SELECT + a.tablespace_name, + total, + free, + total - free AS used, + substr( free / total * 100, 1, 5 ) AS "FREE%", + substr( ( total - free ) / total * 100, 1, 5 ) AS "USED%" +FROM + (SELECT tablespace_name, sum( bytes ) / 1024 / 1024 AS total FROM dba_data_files GROUP BY tablespace_name) a, + (SELECT tablespace_name, sum( bytes ) / 1024 / 1024 AS free FROM dba_free_space GROUP BY tablespace_name) b +WHERE + a.tablespace_name = b.tablespace_name +ORDER BY + a.tablespace_name; +``` +## 查询所有表空间以及每个表空间的大小,已用空间,剩余空间,使用率和空闲率 +```sql +SELECT + a.tablespace_name, + total, + free, + total - free AS used, + substr( free / total * 100, 1, 5 ) AS "FREE%", + substr( ( total - free ) / total * 100, 1, 5 ) AS "USED%" +FROM + (SELECT tablespace_name, sum( bytes ) / 1024 / 1024 AS total FROM dba_data_files GROUP BY tablespace_name) a, + (SELECT tablespace_name, sum( bytes ) / 1024 / 1024 AS free FROM dba_free_space GROUP BY tablespace_name) b +WHERE + a.tablespace_name = b.tablespace_name +ORDER BY + a.tablespace_name; +``` +## 查询某个具体的表所占空间的大小 +```sql +SELECT + t.segment_name, + t.segment_type, + sum( t.bytes / 1024 / 1024 ) "占用空间(M)" +FROM + dba_segments t +WHERE + t.segment_type = 'TABLE' + AND t.segment_name = 'TABLE_NAME' +GROUP BY + OWNER, + t.segment_name, + t.segment_type; +``` +## 查看每个表所占空间大小 +```sql +select * from ( + select t.tablespace_name,t.owner, t.segment_name, t.segment_type, sum(t.bytes / 1024 / 1024) mb + from dba_segments t + where t.segment_type='TABLE' + group by t.tablespace_name,t.OWNER, t.segment_name, t.segment_type +) t +order by t.mb desc +; +``` \ No newline at end of file