最近,項目上ORACLE資料庫越來越大,需要查看下資料庫資料量佔用大的原因。
1、查看ORACLE資料表空間及表資料大小
Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents group By Segment_Name order by Sum(bytes)/1024/1024 desc;
2、從返回的結果看,有一個segment名為"SYS_LOB0000053810C00004$$"的對象佔用了大量的空間;即LOB(BLOB和CLOB)對象佔用的大小對象
3、根據segment_name,就可以從 dba_lobs 表裡查到是哪個表,哪個欄位;
select * from dba_lobs where segment_name like 'your_segment_name';
裡面顯示的TABLE_NAME和COLUMN_NAME為表名和欄位名。
set pagesize 200
column "資料檔案名稱" format a25
column "資料表空間名稱" format a18
column "容量(M)" format a12
column "使用率%" format a12
column "最大容量(M)" format a15
column "可擴充容量(M)" format a15
column "空閑(M)" format a12
column "自動擴充" format a10
select a.FILE_NAME "資料檔案名稱",a.TABLESPACE_NAME"資料表空間名稱",
to_char(100-round((nvl(b.free_bytes,0)/a.BYTES)*100,2)) "使用率%",
to_char(round(a.BYTES/1024/1024,2)) "容量(M)",
to_char(round(nvl(b.free_bytes,0)/1024/1024,2)) "空閑(M)",
to_char(round(decode(a.autoextensible,'YES',a.maxbytes/1024/1024,'NO',a.bytes/1024/1024),2)) "最大容量(M)",
a.autoextensible "自動擴充",
to_char(round(decode(a.autoextensible,'YES',a.maxbytes/1024/1024,'NO',a.bytes/1024/1024)-a.BYTES/1024/1024,2)) "可擴充容量(M)"
from dba_data_files a,
(select FILE_ID,sum(bytes) free_bytes from dba_free_space group by FILE_ID) b
where a.FILE_ID=b.FILE_ID
order by to_number("可擴充容量(M)") asc;