Oracle变更Redo日志文件大小的操作方法
原创
Oracle 作者:
yhdmy 时间:2015-08-25 14:19:47 6464 0
一、说明与分析:
由于默认安装的数据库redo日志文件大小为50M,后期测试与生产都会产生切换日志频繁,同时会出现等待事件: log file switch completion 。这时你只需要将 redo日志文件调整大些,就可以轻松的解决该问题。
二、实验,更改redo文件大小:
1. 首先检查日志文件大小及使用状态
SYS@TESTDB >select bytes/1024/1024 from v$log;
BYTES/1024/1024
---------------
50
50
50
SYS@TESTDB >select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/TESTDB/redo03.log
/u01/app/oracle/oradata/TESTDB/redo02.log
/u01/app/oracle/oradata/TESTDB/redo01.log
2. 增加3组新的500M的日志组
SYS@TESTDB >alter database add logfile group 4 ('/u01/app/oracle/oradata/TESTDB/redo04.log') size 500m;
Database altered.
SYS@TESTDB >alter database add logfile group 5 ('/u01/app/oracle/oradata/TESTDB/redo05.log') size 500m;
Database altered.
SYS@TESTDB >alter database add logfile group 6 ('/u01/app/oracle/oradata/TESTDB/redo06.log') size 500m;
Database altered.
3. 删除3组旧的50M的日志组,第二组报错,原因是他目前是current 的日志组,不能被删除。
SYS@TESTDB >alter database drop logfile group 1;
Database altered.
SYS@TESTDB >alter database drop logfile group 2;
alter database drop logfile group 2
*
ERROR at line 1:
ORA-01623: log 2 is current log for instance TESTDB (thread 1) - cannot drop
ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/TESTDB/redo02.log'
SYS@TESTDB >alter database drop logfile group 3;
Database altered.
4. 切换当前日志组,再删除第2组日志。报错原因是第2组日志仍为活动日志组,不能被删除。
SYS@TESTDB >alter system switch logfile;
System altered.
SYS@TESTDB >alter database drop logfile group 2;
alter database drop logfile group 2
*
ERROR at line 1:
ORA-01624: log 2 needed for crash recovery of instance TESTDB (thread 1)
ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/TESTDB/redo02.log'
SYS@TESTDB >select group#,status from v$log;
GROUP# STATUS
---------- ----------------
2 ACTIVE
4 CURRENT
5 UNUSED
6 UNUSED
5. 做全局检查点,使redo日志文件改变为非活动
SYS@TESTDB >alter system checkpoint;
System altered.
SYS@TESTDB >select group#,status from v$log;
GROUP# STATUS
---------- ----------------
2 INACTIVE
4 CURRENT
5 UNUSED
6 UNUSED
6. 再次删除第2组redo日志组
SYS@TESTDB >alter database drop logfile group 2;
Database altered.
SYS@TESTDB >select group#,status from v$log;
GROUP# STATUS
---------- ----------------
4 CURRENT
5 UNUSED
6 UNUSED
7. 验证日志组文件及大小
SYS@TESTDB >select group#,bytes/1024/1024 from v$log;
GROUP# BYTES/1024/1024
---------- ---------------
4 500
5 500
6 500
三、总结:以上操作是实验环境,如果在生产环境,还是要更加细心,要打开Oracle日志进行实时跟踪。如果希望继续使用日志组号1,2,3的话,可以再次使用该方法,建立1,2,3组后,删除4,5,6组。当然保留4,5,6也是可以的。往往业务比较繁忙的系统都不只3组日志,请各自DBA朋友们自己按照业务需求来调整。