前几天遇到一家客户报错ora-20999的错误,现将处理方式分享一下:
1.表空间使用率查询,其中,最大使用使用率来判断是否增加数据文件:
select a.tablespace_name As 表空间,f.文件数,round(f.最大值 / 1024,2) || 'GB' as max,
round(to_number(total - free) / to_number(最大值) * 100, 2) as 最大使用率,
total || 'M' As 空间大小,free || 'M' As 剩余空间,total - free || 'M' 已使用,
round(to_number(total - free) / to_number(total) * 100, 2) As 实际使用率
from (select tablespace_name, round(sum(bytes) /(1024*1024),2) total
from dba_data_files
group by tablespace_name) a,
(select tablespace_name, round(sum(bytes) /(1024*1024),2) free
from dba_free_space
group by tablespace_name) b,
(select d.name, count(*) as 文件数, sum(decode(c.autoextensible,'YES',c.maxbytes,c.bytes))/1024/1024 as 最大值
from dba_data_files c, v$tablespace d
where c.tablespace_name = d.name
group by d.name) f
where a.tablespace_name = b.tablespace_name
and a.tablespace_name = f.name
order by 最大使用率 desc
-----可根据以上语句判断哪个表空间满了,需要扩展
2.查询表空间数据文件位置:(方法有二)
(1)select * from dba_data_files
(2)select tablespace_name, file_id, file_name, round(bytes / (1024 * 1024), 0) total_space from sys.dba_data_files order by tablespace_name
-----file_name就是表空间数据文件的路径及名称
3.扩展表空间数据文件:(方法有三)
(1)新增一个数据文件:
Alter tablespace 表空间名 add datafile ‘数据文件路径.dbf’ size 500M autoextend on next 100M maxsize unlimited;
举例:alter tablespace test add datafile 'E:\oradata\orcl\test01.dbf' size 3200m
test01.dbf为新增的数据文件的名称, test为扩展的表空间
(2)手动增加表空间数据文件的大小:
alter database datafile 'E:\oradata\orcl\test01.dbf' resize 4096m
-----test01.dbf为需要修改大小的数据文件
(3)将表空间的数据文件设置成自动扩展:
alter database datafile 'E:\oradata\orcl\test01.dbf' autoextend on next 5M maxsize unlimited;
-----test01.dbf为设置自动扩展的数据文件