查看各表空間的使用情況 select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB", round(((a.bytes-b.bytes)/a.bytes)*100,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
select * from dba_data_files
order by tablespace_name, file_name;
select tablespace_name,dba_tablespaces.* from dba_tablespaces
表真實占用的空間
select OWNER, t.segment_name, t.segment_type, sum(t.bytes / 1024 / 1024/1024) USED_G from dba_segments t where t.owner LIKE '%ODS%' AND SEGMENT_NAME NOT LIKE 'BIN$%' group by OWNER, t.segment_name, t.segment_type order by OWNER, USED_G desc;
--1、查看表空間的名稱及大小 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size from dba_tablespaces t, dba_data_files d where t.tablespace_name = d.tablespace_name group by t.tablespace_name; --2、查看表空間物理文件的名稱及大小 select tablespace_name, file_id, file_name, round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name;
alter tablespace {表空間名字} add datafile '物理數據文件路徑' SIZE 『初始大小M』 AUTOEXTEND ON NEXT 『自動擴展大小M』 alter tablespace SDK_TB add datafile '/oradata/ORA11G/sdk_tb2.dbf' size 1000m autoextend on next 200m
如果datafile加錯到表空間,執行刪除
Alter tablespace SDK_TB drop datafile '/oradata/ORA11G/a_tb04.dbf'; 或者 alter database datafile '/oradata/ORA11G/a_tb04.dbf' offline drop;
查看臨時表空間
select * from dba_temp_files where tablespace_name = 'DEV_TEMP2' order by tablespace_name, file_name;
添加臨時表空間文件
alter tablespace DEV_TEMP2 add tempfile '/data/phonedb/datafile/dev_temp3.dbf' size 1000m autoextend on next 200m
修改用戶默認表空間
alter user user_name default tablespace dev_tb; alter user user_name temporary tablespace dev_temp;
查看數據文件是否有數據:
只需查看數據文件中是否包含extent段。如果有extent(索引段,數據段)段,則說明數據文件中有數據。
使用dba_extents視圖和dba_data_files視圖進行連接查詢。
select t.file_name,t1.owner,t1.segment_name,t1.segment_type,t1.tablespace_name from dba_data_files t,dba_extents t1 where t.file_id=t1.file_id and file_name='你要查詢的數據文件路徑';