author:skate
time:2009/08/27
在线更改undo和redo的路径,以便减少io的争用
为了降低系统的io,在线最好,最直接,最简单就是把一部分io分担到其他的磁盘,由于是在线操作,所以能在线移动
也就只能是undo文件和redo日志文件
在线切换undo文件
可以切换使用一个undo表空间到另一个undo表空间。这样可以分担io,因为UNDO_TABLESPACE初始化参数是一个动态参数,
可以使用ALTER SYSTEM SET语句分配一个新的undo表空间。下列语句有效地切换至一个新的undo表空间
确认当前undo表空间的基本信息:
SQL> show parameter undo
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
undo_management string AUTO
undo_retention integer 900
undo_tablespace string UNDOTBS1
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/home/oracle/oracle/oradata/orcl/system01.dbf
/u01/oradata/orcl/undotbs01.dbf
/home/oracle/oracle/oradata/orcl/sysaux01.dbf
/home/oracle/oracle/oradata/orcl/users01.dbf
/home/oracle/oracle/oradata/orcl/example01.dbf
SQL> select sum(bytes) from dba_undo_extents where tablespace_name='UNDOTBS1' and status='ACTIVE';
SUM(BYTES)
--------
步骤:(假如现在使用undotbs1表空间)
1.新创建一个undo空间undotbs2
2.把系统的undo表空间切换到新创建的undo表空间undotbs2
3.把原来的undo表空间undotbs1离线(offline)
4.删除原来的undo表空间undotbs1
1. 首先确认当前正在使用回滚段的大小
select sum(bytes) from dba_undo_extents where tablespace_name='UNDOTBS1' and status='ACTIVE';
此语句得出要回滚的数据量,如果不为NULL,则undotbs1表空间不能被删除。而且如果有大量数据的话,系统会比较慢,
且使用shutdown immediate将不能关闭数据库,且重新启动数据库后smon仍要继续回滚undotbs1中的数据。因为smon管理
回滚及段的分配,此时集中处理回滚,将很少进行段的分配,那么会造成数据库慢。
2.新创建一个undo空间undotbs2
SQL> create undo tablespace undotbs2
2 datafile '/u01/oradata/orcl/undotbs02.dbf' size 500m reuse
3 autoextend on next 10m maxsize unlimited;
3. 把系统的undo表空间切换到新创建的undo表空间undotbs2
SQL> alter system set undo_tablespace = undotbs2;
4.把原来的undo表空间undotbs1离线(offline)
SQL> alter tablespace undotbs1 offline;
5。删除原来的undo表空间undotbs1
SQL> drop tablespace undotbs1 including contents and datafiles cascade constraints;
如果报如下的错误,说明还有事务在使用原来的undo空间,没有处理完毕
ORA-00959: tablespace 'UNDOTB1' does not exist
查询确认是否还事务在使用原来的undo空间
SQL> select segment_name,owner,tablespace_name,status from dba_rollback_segs
where tablespace_name='UNDOTBS1' and status = 'ONLINE';
如果有记录返回,说明还有未处理完的事务,这个时候,可以等待系统自动处理,知直到没有记录返回为止,才可以
删除原来的undo表空间;当然如果你不想等,可能查到相关进程,然后kill掉
查看有多少回滚事务:
select count(*) from v$transaction;
确认os的pid:
SELECT P.SPID
FROM V$SESSION S, V$PROCESS P
WHERE S.PADDR = P.ADDR
AND S.SID IN (SELECT S.SID
FROM V$TRANSACTION T, V$SESSION S
WHERE T.ADDR = S.TADDR);
然后直接kill掉
eg:
kill -9 29987
undo空间满的问题讨论:
解决方法:
1.增加undo空间的大小
2.减少undo_retention
alter system set undo_retention= 3600;
undo表空间不清除,是反复的覆盖利用。
这个undo_retention表示数据在undo里保存的时间(持续时间),
若在这一时间范围内产生的UNDO数据超过了undo表空间的大小,将报undo表空间不够的错误,可以试着把undo_retention值设小。
redo日志管理
1.当前日志相关信息
sys@ora11g> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- --------- ------------- ---------
1 1 10 209715200 1 YES INACTIVE 461938 09-MAR-09
2 1 11 209715200 1 NO CURRENT 485885 09-MAR-09
3 1 9 209715200 1 YES INACTIVE 432636 04-MAR-09
sys@ora11g> select * from v$logfile;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- -------------------- ---------------------------------------- ---
1 ONLINE /oracle/u02/oradata/ora11g/redo01.log NO
2 ONLINE /oracle/u02/oradata/ora11g/redo02.log NO
3 ONLINE /oracle/u02/oradata/ora11g/redo03.log NO
2.添加重做日志组
sys@ora11g>alter database add logfile group 4
('/oracle/u02/oradata/ora11g/redo04_01.log','/oracle/u02/oradata/ora11g/redo04_02.log') size 50m;
Database altered.
sys@ora11g> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- --------- ------------- ---------
1 1 10 209715200 1 YES INACTIVE 461938 09-MAR-09
2 1 11 209715200 1 NO CURRENT 485885 09-MAR-09
3 1 9 209715200 1 YES INACTIVE 432636 04-MAR-09
4 1 0 52428800 2 YES UNUSED 0
sys@ora11g> select * from v$logfile;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- -------------------- ---------------------------------------- ---
1 ONLINE /oracle/u02/oradata/ora11g/redo01.log NO
2 ONLINE /oracle/u02/oradata/ora11g/redo02.log NO
3 ONLINE /oracle/u02/oradata/ora11g/redo03.log NO
4 ONLINE /oracle/u02/oradata/ora11g/redo04_01.log NO
4 ONLINE /oracle/u02/oradata/ora11g/redo04_02.log NO
3.添加日志文件
sys@ora11g>alter database add logfile member
'/oracle/u02/oradata/ora11g/redo01_02.log' to group 1,
'/oracle/u02/oradata/ora11g/redo02_02.log' to group 2,
'/oracle/u02/oradata/ora11g/redo03_02.log' to group 3;
Database altered.
sys@ora11g> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- --------- ------------- ---------
1 1 10 209715200 2 YES INACTIVE 461938 09-MAR-09
2 1 11 209715200 2 NO CURRENT 485885 09-MAR-09
3 1 9 209715200 2 YES INACTIVE 432636 04-MAR-09
4 1 0 52428800 2 YES UNUSED 0
sys@ora11g> select * from v$logfile order by 1;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- -------------------- ---------------------------------------- ---
1 ONLINE /oracle/u02/oradata/ora11g/redo01.log NO
1 INVALID ONLINE /oracle/u02/oradata/ora11g/redo01_02.log NO
2 INVALID ONLINE /oracle/u02/oradata/ora11g/redo02_02.log NO
2 ONLINE /oracle/u02/oradata/ora11g/redo02.log NO
3 ONLINE /oracle/u02/oradata/ora11g/redo03.log NO
3 INVALID ONLINE /oracle/u02/oradata/ora11g/redo03_02.log NO
4 ONLINE /oracle/u02/oradata/ora11g/redo04_02.log NO
4 ONLINE /oracle/u02/oradata/ora11g/redo04_01.log NO
8 rows selected.
4.重命名日志成员
在重命名日志组成员之前新的目标必须已经存在。Oracle的sql命令只是把控制文件中的内部指针指向新的日志文件。
最好在关闭数据库后,在os层面重命名,我测试在不关闭数据库也可以在os层面重命名log文件
1).关闭数据库
sys@ora11g> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
2).使用操作系统命令重命名或移动日志文件
ora11g@RHEL53 /oracle/u02/oradata/ora11g$mv redo01.log redo01_01.log
ora11g@RHEL53 /oracle/u02/oradata/ora11g$mv redo02.log redo02_01.log
ora11g@RHEL53 /oracle/u02/oradata/ora11g$mv redo03.log redo03_01.log
3).启动数据库实例到mount状态,重命名控制文件中的日志文件成员。
NotConnected@> select * from v$logfile order by 1,4;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- -------------------- ------------------------------------------ ---
1 ONLINE /oracle/u02/oradata/ora11g/redo01.log NO
2 ONLINE /oracle/u02/oradata/ora11g/redo02.log NO
3 ONLINE /oracle/u02/oradata/ora11g/redo03.log NO
4 ONLINE /oracle/u02/oradata/ora11g/redo04_01.log NO
4 ONLINE /oracle/u02/oradata/ora11g/redo04_02.log NO
1 ONLINE /oracle/u02/oradata/ora11g/redo01_02.log NO
2 ONLINE /oracle/u02/oradata/ora11g/redo02_02.log NO
3 ONLINE /oracle/u02/oradata/ora11g/redo03_02.log NO
8 rows selected.
NotConnected@>alter database rename file '/oracle/u02/oradata/ora11g/redo01.log' to '/oracle/u02/oradata/ora11g/redo01_01.log';
Database altered.
NotConnected@>alter database rename file '/oracle/u02/oradata/ora11g/redo02.log' to '/oracle/u02/oradata/ora11g/redo02_01.log';
Database altered.
NotConnected@>alter database rename file '/oracle/u02/oradata/ora11g/redo03.log' to '/oracle/u02/oradata/ora11g/redo03_01.log';
Database altered.
4).open数据库,验证结果
NotConnected@>alter database open;
Database altered.
sys@ora11g> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- -------- ------------- ---------
1 1 18 209715200 2 YES INACTIVE 486960 09-MAR-09
2 1 19 209715200 2 YES INACTIVE 486964 09-MAR-09
3 1 21 209715200 2 NO CURRENT 486973 09-MAR-09
4 1 20 52428800 2 YES INACTIVE 486968 09-MAR-09
sys@ora11g> select * from v$logfile order by 1,4;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- -------------------- ------------------------------------------ ---
1 ONLINE /oracle/u02/oradata/ora11g/redo01_01.log NO
1 ONLINE /oracle/u02/oradata/ora11g/redo01_02.log NO
2 ONLINE /oracle/u02/oradata/ora11g/redo02_01.log NO
2 ONLINE /oracle/u02/oradata/ora11g/redo02_02.log NO
3 ONLINE /oracle/u02/oradata/ora11g/redo03_01.log NO
3 ONLINE /oracle/u02/oradata/ora11g/redo03_02.log NO
4 ONLINE /oracle/u02/oradata/ora11g/redo04_01.log NO
4 ONLINE /oracle/u02/oradata/ora11g/redo04_02.log NO
8 rows selected.
5).最后,不要忘记备份控制文件
sys@ora11g>alter database backup controlfile to trace;
Database altered.
5.删除一个非活动的重做日志组的成员
sys@ora11g> select * from v$log;
GROUP# THREAD# SEQUENCE# BYTES MEMBERS ARC STATUS FIRST_CHANGE# FIRST_TIM
---------- ---------- ---------- ---------- ---------- --- -------- ------------- ---------
1 1 18 209715200 2 YES INACTIVE 486960 09-MAR-09
2 1 19 209715200 2 YES INACTIVE 486964 09-MAR-09
3 1 21 209715200 2 NO CURRENT 486973 09-MAR-09
4 1 20 52428800 2 YES INACTIVE 486968 09-MAR-09
sys@ora11g>alter database drop logfile member '/oracle/u02/oradata/ora11g/redo04_02.log';
Database altered.
sys@ora11g> !ls -l /oracle/u02/oradata/ora11g/redo04_02.log
-rw-r----- 1 oracle oinstall 52429312 Mar 9 16:28 /oracle/u02/oradata/ora11g/redo04_02.log
sys@ora11g>!rm -f /oracle/u02/oradata/ora11g/redo04_02.log
sys@ora11g> select * from v$logfile order by 1,4;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- -------------------- ------------------------------------------ ---
1 ONLINE /oracle/u02/oradata/ora11g/redo01_01.log NO
1 ONLINE /oracle/u02/oradata/ora11g/redo01_02.log NO
2 ONLINE /oracle/u02/oradata/ora11g/redo02_01.log NO
2 ONLINE /oracle/u02/oradata/ora11g/redo02_02.log NO
3 ONLINE /oracle/u02/oradata/ora11g/redo03_01.log NO
3 ONLINE /oracle/u02/oradata/ora11g/redo03_02.log NO
4 ONLINE /oracle/u02/oradata/ora11g/redo04_01.log NO
7 rows selected.
6.删除一个非活动的重做日志组
sys@ora11g>alter database drop logfile group 4;
Database altered.
sys@ora11g>!rm -f /oracle/u02/oradata/ora11g/redo04_01.log
sys@ora11g> select * from v$logfile;
GROUP# STATUS TYPE MEMBER IS_
---------- ------- -------------------- ------------------------------------------ ---
1 ONLINE /oracle/u02/oradata/ora11g/redo01_01.log NO
2 ONLINE /oracle/u02/oradata/ora11g/redo02_01.log NO
3 ONLINE /oracle/u02/oradata/ora11g/redo03_01.log NO
1 ONLINE /oracle/u02/oradata/ora11g/redo01_02.log NO
2 ONLINE /oracle/u02/oradata/ora11g/redo02_02.log NO
3 ONLINE /oracle/u02/oradata/ora11g/redo03_02.log NO
6 rows selected.
7.强制切换日志
sys@ora11g>alter system switch logfile;
System altered.
sys@ora11g>alter system archive log current;
System altered.
-----end-----