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;
查找數據文件指標及路徑sql
select b.file_id 文件ID, b.tablespace_name 表空間, b.file_name 物理文件名, b.bytes 總字節數, (b.bytes-sum(nvl(a.bytes,0))) 已使用, sum(nvl(a.bytes,0)) 剩餘, sum(nvl(a.bytes,0))/(b.bytes)*100 剩餘百分比 from dba_free_space a,dba_data_files b where a.file_id=b.file_id group by b.tablespace_name,b.file_name,b.file_id,b.bytes order by b.tablespace_name
一個數據文件最大隻能32G;oracle
ALTER TABLESPACE app_data ADD DATAFILE 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP03.DBF' SIZE 20480M;
ALTER DATABASE DATAFILE 'D:\ORACLE\PRODUCT\10.2.0\ORADATA\EDWTEST\APP03.DBF' AUTOEXTEND ON NEXT 100M MAXSIZE 20480M;
其中設置的每一個文件初始分配空間爲7g, autoextend on爲自動增加大小,oracle單個文件大小最大不超過32g.app
sql腳本以下:(我這裏增長兩個數據文件,須要擴容的表空間是system)spa
ALTER TABLESPACE SYSTEM ADD DATAFILE 'C:\APP\ORACLE\ORADATA\DFYYCDB\DATAFILE\O2_MF_SYSTEM_CWMNZ9XV_.DBF' size 7167M autoextend on ; ALTER TABLESPACE SYSTEM ADD DATAFILE 'C:\APP\ORACLE\ORADATA\DFYYCDB\DATAFILE\O3_MF_SYSTEM_CWMNZ9XV_.DBF' size 7167M autoextend on ;