使用者生産系統運作一段時間後,表空間已經耗盡,隻有擴充表空間,才能繼續在表空間上添加表資料。
1.先去查詢表空間的使用情況及使用百分比
select a.tablespace_name "表空間名",
a.bytes / 1024 / 1024 "表空間大小(m)",
(a.bytes - b.bytes) / 1024 / 1024 "已使用空間(m)",
b.bytes / 1024 / 1024 "空閑空間(m)",
round(((a.bytes - b.bytes) / a.bytes) * 100, 2) "使用%比"
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;
2.查詢表空間名,檔案名,是否自動擴充,表空間大小及最大空間
select t.tablespace_name,
d.file_name,
d.autoextensible,
d.bytes,
d.maxbytes,
d.status
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
order by tablespace_name, file_name;
3.表空間擴容
注意:一個資料檔案最大隻能32G
3.1 方法一
--手工改變已存在資料檔案的大小
alter tablespace test_comm add datafile'd:\oracle\product\10.2.0\oradata\hisdb\test01.dbf' size 20480m;
3.2 方法二
--允許已存在的資料檔案自動增長
alter database datafile 'd:\oracle\product\10.2.0\oradata\hisdb\test01.dbf'autoextend on next 100m maxsize 20480m;
3.3 方法三
--增加資料檔案
/* 其中設定的每個檔案初始配置設定空間為7g, autoextend on為自動增長大小,oracle單個檔案大小最大不超過32g*/
/*說明1:sql腳本(增加兩個資料檔案,需要擴容的表空間是test_comm)*/
/*說明2:
/data/oracle/tablespace/msg21.dbf -檔案名及存放路徑
size -表空間的大小
utoextend -是否開啟自動擴充,on開啟
*/
alter tablespace test_comm add datafile '/data/oracle/tablespace/test02.dbf' size 7167m autoextend on ;
alter tablespace test_comm add datafile '/data/oracle/tablespace/test03.dbf' size 7167m autoextend on ;