資料表空間(下),資料表空間(
7.資料表空間的使用大小
-- 查看錶空間已使用方式
select a.tablespace_name,
round(a.bytes / 1024 / 1024) "Sum MB",
round((a.bytes - b.bytes) / 1024 / 1024) "used MB",
round(b.bytes / 1024 / 1024) "free MB",
round(((a.bytes - b.bytes) / a.bytes), 2) "percent_used"
from (select tablespace_name, sum(bytes) bytes
from dba_data_files
group by tablespace_name) a,
(select tablespace_name, sum(bytes) bytes, max(bytes) largest
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name
order by ((a.bytes - b.bytes) / a.bytes) desc;
NOTES:如果運行很久都沒得到結果,則查看各個使用者下的垃圾箱,
可能是垃圾箱堆積了太多資料導致的
(select * from recyclebin或select * from dba_recyclebin),
然後用下面的命令清理掉該使用者的垃圾箱。
(必須各個使用者都執行一遍,也可以直接用purge dba_recyclebin命令,
但如果和其他模組一起使用同一資料庫,不建議這麼操作,因為其他使用者的垃圾箱資料可能有用。)
SQL>purge recyclebin;
select file#,name,bytes/1024/1024 from v$tempfile; -- 暫存資料表空間總大小
select tablespace, (sum (blocks))*8/1000 "MB" from v$sort_usage group by tablespace; -- 暫存資料表空間已使用方式
-- 暫存資料表空間使用方式:
Select f.tablespace_name,
sum(f.bytes_free + f.bytes_used) / (1024 * 1024) "total MB",
sum((f.bytes_free + f.bytes_used) - nvl(p.bytes_used, 0)) / (1024 * 1024) "Free MB",
sum(nvl(p.bytes_used, 0)) / (1024 * 1024) "Used MB"
from sys.v_$temp_space_header f,
dba_temp_files d,
sys.v_$temp_extent_pool p
where f.tablespace_name(+) = d.tablespace_name
and f.file_id(+) = d.file_id
and p.file_id(+) = d.file_id
group by f.tablespace_name;
8.修改表的資料表空間
alter table a move tablespace TBS_DW_YM
9.查詢imuse01使用者所使用的預設資料表空間
select default_tablespace from dba_users where username=’imuse01’;
資料表空間下有什資料檔案
查看下面兩個資料字典視圖就知道了。
查看有哪些資料表空間:select * from dba_tablespaces;
查看有哪些資料檔案在哪個資料表空間中:select * from dba_data_files;
怎查看錶空間路徑及資料表空間下的使用者?
反了,應該實使用者所屬的資料表空間,DBA_USERS視圖就可以查
路徑去查DBA_DATA_FILES