1 系统表空间扩容
注:表空间监测或扩容方式很多,这里只提供一种方便使用的方法
1)查询SQL
注:需要输入百分比,如:90,就可查出使用率超过90%的表空间,
with t as
(select b.tablespace_name,
b.contents,
(b.currentbytes - nvl(a.free, 0)) / b.currentbytes * 100 ratio
from (select 'PERMANENT' contents,
tablespace_name,
sum(bytes) currentbytes,
sum(maxbytes) maxbyte
from dba_data_files
group by tablespace_name
union all
select 'TEMPORARY' contents,
tablespace_name,
sum(bytes) currentbytes,
sum(maxbytes) maxbyte
from dba_temp_files
group by tablespace_name) b,
(select tablespace_name, sum(bytes) free
from dba_free_space
group by tablespace_name
union all
select tablespace_name, sum(free_space) free
from dba_temp_free_space
group by tablespace_name) a
where a.tablespace_name(+) = b.tablespace_name
and (b.currentbytes - nvl(a.free, 0)) / b.currentbytes * 100 >
nvl(to_number('&百分比'), 80))
select case add_f.contents
when 'PERMANENT' then
'alter tablespace ' || add_f.tablespace_name || ' add datafile ''' ||
add_f.new_file || ''' size ' || nvl(to_number('&文件大小'), 4) || 'g;'
when 'TEMPORARY' then
'alter tablespace ' || add_f.tablespace_name || ' add tempfile ''' ||
add_f.new_file || ''' size ' || nvl(to_number('&文件大小'), 4) || 'g;'
end,
add_f.tablespace_name,
t.ratio
from (select t.tablespace_name,
t.contents,
substr(f.file_name, 1, instr(f.file_name, '/', -1)) ||
lower(t.tablespace_name) || (max(f.file_id) + 1) || '.dbf' new_file
from dba_data_files f, t
where f.tablespace_name = t.tablespace_name
group by t.tablespace_name,
t.contents,
substr(f.file_name, 1, instr(f.file_name, '/', -1))) add_f,
t
where add_f.tablespace_name = t.tablespace_name;
2)登录数据库服务器,执行扩容语句,如下
$ su - oraprod
$ sqlplus / as sysdba
SQL> alter tablespace APPS_TS_MEDIA add datafile '/oracle/PROD/ora/db/apps_st/data/apps_ts_media401.dbf' size 4g;
3)常见报错问题
a ORA-01654: 索引 GL.GL_BALANCES_N3 无法通过 16 (在表空间 APPS_TS_TX_IDX)
解决方法:增加 APPS_TS_TX_IDX空间大小
b ORA-01555: 快照过旧: 回退段号 18 (名称为 "_SYSSMU18_720684835$") 过小
解决方法:增加UNDO表空间大小
参考网址:
https://my.oschina.net/fuyong/blog/801767
http://blog.csdn.net/ghost241/article/details/50537063
2 临时表空间扩容
参考网址:http://www.cnblogs.com/vipsoft/archive/2012/11/28/2792431.html
备注:临时表空间的使用率跟正常的表空间使用率不一样,正常情况下,临时表空间的使用率也可能达到99%,没有参考意义。当某个报错的时候,就说明临时表空间真的不足了,需要进行扩容
1)查询临时表空间
SQL一:
select c.tablespace_name,
to_char(c.bytes / 1024 / 1024, '99,999.999') total_bytes,
to_char((c.bytes - d.bytes_used) / 1024 / 1024, '99,999.999') free_bytes,
to_char(d.bytes_used / 1024 / 1024, '99,999.999') use_bytes,
to_char(d.bytes_used * 100 / c.bytes, '99.99') || '%' use
from (select tablespace_name, sum(bytes) bytes
from dba_temp_files
group by tablespace_name) c,
(select tablespace_name, sum(bytes_cached) bytes_used
from v$temp_extent_pool
group by tablespace_name) d
where c.tablespace_name = d.tablespace_name
order by tablespace_name;
SQL二:
select tablespace_name,
file_name,
user_bytes/bytes,
bytes / 1024 / 1024 "file_size(M)",
autoextensible
from dba_temp_files t
where t.TABLESPACE_NAME = 'TEMP2';
注:查看临时表空间的数据文件命令及存放路径,便于下一步的表空间扩容
2)登录数据库服务器,执行扩容语句,如下
$ su - oraprod
$ sqlplus / as sysdba
SQL> alter tablespace temp add tempfile ‘/u01/app/oracle/oradata/orcl/temp02.dbf’ size 100m AUTOEXTEND ON NEXT 1G MAXSIZE 10g;