数据库redo log日志太小,默认单个文件只有50M,3个日志文件循环写,容易导致日志频繁切换,因此建议调整。
1.查看当前日志组成员
SQL> select member from v$logfile;
MEMBER
--------------------------------------------------------------------------------
/opt/oracle/oradata/orcl/redo03.log
/opt/oracle/oradata/orcl/redo02.log
/opt/oracle/oradata/orcl/redo01.log
2.查看当前日志组状态
SQL> select group#,members,bytes/1024/1024,status from v$log;
GROUP# MEMBERS BYTES/1024/1024
---------- ---------- ---------------
STATUS
------------------------------------------------
1 1 50
CURRENT
2 1 50
INACTIVE
3 1 50
INACTIVE
SQL>
现在有三个日志成员,大小为50M,想要更改为1024M。
3.增加日志组
SQL> alter database add logfile group 4 ('/opt/oracle/oradata/orcl/redo04.log') size 1G;
SQL> alter database add logfile group 5 ('/opt/oracle/oradata/orcl/redo05.log') size 1G;
SQL> alter database add logfile group 6 ('/opt/oracle/oradata/orcl/redo06.log') size 1G;
4.切换到新增的日志组上
SQL> alter system switch logfile;
System altered.
SQL> select group#,members,bytes/1024/1024,status from v$log;
GROUP# MEMBERS BYTES/1024/1024
---------- ---------- ---------------
STATUS
------------------------------------------------
1 1 50
ACTIVE
2 1 50
INACTIVE
3 1 50
INACTIVE
GROUP# MEMBERS BYTES/1024/1024
---------- ---------- ---------------
STATUS
------------------------------------------------
4 1 1024
CURRENT
5 1 1024
UNUSED
6 1 1024
UNUSED
CURRENT: 指当前的日志文件,在进行实例恢复时是必须的。
ACTIVE: 是指活动的非当前日志,在进行实例恢复时会被用到。Active状态意味着Checkpoint尚未完成,因此该日志文件不能被覆盖。
INACTIVEL 是非活动日志,在实例恢复时不再需要,但在介质恢复时可能需要。
UNUSED: 表示该日志从未被写入,可能是刚添加的,或RESETLOGS后被重置。
注意:如果原来的log组无法切换,仍然ACTIVE状态,导致删除日志组报错:thread 1 cannot allocate new log, sequence Checkpoint not complete
则执行:alter system checkpoint;
checkpoint由ckpt进程触发oracle进行checkpoint动作,将data buffer中的脏块(已经写在redo里记录、但没有写到datafile)的内容写入到data file里并释放占用的空间。
一般手工执行是由于要删除某个日志但是该日志里还有没有同步到data file里的内容,此时就需要手工check point来同步数据,然后才可以成功 drop logfile group n。
5.删除旧的日志组
SQL> alter database drop logfile group 3;
SQL> alter database drop logfile group 2;
SQL> alter database drop logfile group 1;
SQL> alter database drop logfile group 3;
Database altered.
SQL> alter database drop logfile group 2;
Database altered.
SQL> alter database drop logfile group 1;
alter database drop logfile group 1
*
ERROR at line 1:
ORA-01624: log 1 needed for crash recovery of instance orcl (thread 1)
ORA-00312: online log 1 thread 1: '/opt/oracle/oradata/orcl/redo01.log'
SQL>
注意:日志成员处在active状态,不能drop掉的,再次执行 alter system switch logfile; 切换日志组,然后就可以删除GROUP 1了。
SQL> alter system switch logfile;
System altered.
SQL> select group#,members,bytes/1024/1024,status from v$log;
GROUP# MEMBERS BYTES/1024/1024
---------- ---------- ---------------
STATUS
------------------------------------------------
1 1 50
INACTIVE
4 1 1024
ACTIVE
5 1 1024
CURRENT
GROUP# MEMBERS BYTES/1024/1024
---------- ---------- ---------------
STATUS
------------------------------------------------
6 1 1024
UNUSED
SQL>
SQL> alter database drop logfile group 1;
Database altered.
SQL>
再查看日志组
SQL> select group#,members,bytes/1024/1024,status from v$log;
GROUP# MEMBERS BYTES/1024/1024
---------- ---------- ---------------
STATUS
------------------------------------------------
4 1 1024
ACTIVE
5 1 1024
CURRENT
6 1 1024
UNUSED
SQL>
6.在操作系统下删除掉redolog日志文件
# mv /opt/oracle/oradata/orcl/redo0[1-3].log /tmp