Oracle表空間大小查詢和清理

2021-10-06 01:47:29 字數 1824 閱讀 3858

-- 統計表空間

select tablespace_name 表空間,

to_char(round(bytes / 1024, 2), '99990.00') || '' 實有,

to_char(round(free / 1024, 2), '99990.00') || 'g' 現有,

to_char(round((bytes - free) / 1024, 2), '99990.00') || 'g' 使用,

to_char(round(10000 * used / bytes) / 100, '99990.00') || '%' 比例

from (select a.tablespace_name tablespace_name,

floor(a.bytes / (1024 * 1024)) bytes,

floor(b.free / (1024 * 1024)) free,

floor((a.bytes - b.free) / (1024 * 1024)) used

from (select tablespace_name tablespace_name, sum(bytes) bytes

from dba_data_files

group by tablespace_name) a,

(select tablespace_name tablespace_name, sum(bytes) free

from dba_free_space

group by tablespace_name) b

where a.tablespace_name = b.tablespace_name)

--where tablespace_name like 'cdr%'

order by floor(10000 * used / bytes) desc; 

--3 檢視oracle使用者佔了哪幾個表空間及大小

select *

from (select owner || '.' || tablespace_name name, sum(b) g

from (select owner,

t.segment_name,

t.partition_name,

round(bytes / 1024 / 1024 / 1024, 2) b,

tablespace_name

from dba_segments t)

where owner not in

('sys', 'outln', 'system', 'tsmsys', 'dbsnmp', 'wmsys')

group by owner || '.' || tablespace_name)

order by name;

--4. 檢視表、索引占用空間大小

select owner,segment_name,bytes/1024/1024 from dba_segments where owner='某使用者' order by 3 desc;

--5.清空**站

purge user_recyclebin;

purge dba_recyclebin;

--6.收縮表

alter table hkta.tsharedetail enable row movement; 

alter table hkta.tsharedetail shrink space cascade;

alter table hkta.tsharedetail disable row movement; 

--7收縮索引

alter index itrequest_his shrink space;

Oracle查詢表空間與表大小

資料表的大小由段和區組成 當前使用者下的可以使用下面sql分別顯示段和區資訊 select us.segment name,us.bytes from user segments us order by us.bytes desc select from user extents ue order ...

ORACLE查詢每個表占用空間大小

select select sum bytes from dba segments where owner testbar and segment type table and segment name table name from user tables 錯誤的,對於oracle而言,雙引號 要...

oracle查詢表空間大小以及每個表所佔空間的大小

最近維護的專案遇到了oracle的效能的問題,需要查詢一下oracle資料庫表空間的大小以及每個表所佔空間的大小,在網上搜尋了一些查詢語句,在此記錄一下 1 查詢資料庫中所有的表空間以及表空間所佔空間的大小,直接執行語句就可以了 select tablespace name,sum bytes 10...