Oracle Redo Log配置:
大致修改步骤:
1.安装logminer
2.开启日志的归档模式
3.开启补充日志(primary key,unique,foreign key,all)
4.日志优化(调整在线日志文件大小和个数)
5.创建redolog同步账号
step1:安装logminer
--安装logminer
SQL> conn / as sysdba
SQL> @$ORACLE_HOME/rdbms/admin/dbmslms.sql
SQL> @$ORACLE_HOME/rdbms/admin/dbmslm.sql
SQL> @$ORACLE_HOME/rdbms/admin/dbmslmd.sql
--以mount方式重启数据库
SQL> shutdown immediate
SQL> startup mount
--题外话:Oracle的几种启动方式说明
1.startup nomount
非安装启动,该方式启动下可执行:重建控制文件和重建数据库,读取init.ora文件,启动instance(SGA和后台进程),这种启动只需要init.ora文件。
2.startup mount [dbname]
安装启动,该方式启动下可执行:数据库日志归档,数据库介质恢复,使数据文件联机或脱机,重新定位数据文件,重做日志文件。
先执行“nomount”,然后打开控制文件,确认数据文件和联机日志文件的位置,但此时不对数据文件和日志文件进行校验检查。
3、startup open [dbname]
先执行“nomount”,然后执行“mount”,再打开包括Redo Log文件在内的所有数据库文件,这种方式下可访问数据库中的数据。
4、startup
startup等同于下面3条命令:
startup nomount;
alter database mount;
alter database open;
查看Oracle数据库的启动状态
SQL> select status from v$instance;
STATUS
------------
OPEN
状态:showdown | nomount | mount | open
step2:开启日志的归档模式
--查看归档日志是否开启(ARCHIVELOG/NOARCHIVELOG,前者表示开启)
--也可以用命令:archive log list;
SQL> select log_mode from v$database;
--开启归档日志
SQL> alter database archivelog;
SQL> alter database force logging;
SQL> alter database add supplemental log data;
SQL> alter database open;
step3:开启补充日志(primary key,unique,foreign key,all)
--查看补充日志是否开启
SQL> select SUPPLEMENTAL_LOG_DATA_MIN min,
SUPPLEMENTAL_LOG_DATA_PK pk,
SUPPLEMENTAL_LOG_DATA_UI ui,
SUPPLEMENTAL_LOG_DATA_FK fk,
SUPPLEMENTAL_LOG_DATA_ALL "all"
from v$database;
--开启补充日志
SQL> alter database add supplemental log data ;
SQL> alter database add supplemental log data (primary key,unique,foreign key,all) columns ;
step4:修改在线日志文件大小和个数(建议不满足时修改:日志文件单个大小>=2G,在线日志个数>=4个)
--查看当前日志组成员(日志个数和位置)
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
--查看当前日志组状态(日志个数和大小)
SQL> select group#,members,bytes/1024/1024,status from v$log;
GROUP# MEMBERS BYTES/1024/1024 STATUS
---------- ---------- --------------- ----------------
1 1 50 INACTIVE
2 1 50 CURRENT
3 1 50 INACTIVE
SQL>
--修改日志:增加日志文件和单个文件大小
1.创建3个新的临时日志组10,11,12(原来有几个日志组,就创建几个临时组)
alter database add logfile group 10 ('/opt/oracle/oradata/orcl/redo10.log') size 2G;
alter database add logfile group 11 ('/opt/oracle/oradata/orcl/redo11.log') size 2G;
alter database add logfile group 12 ('/opt/oracle/oradata/orcl/redo12.log') size 2G;
2.切换当前日志到新的日志组(确认状态切换为:INACTIVE,只有INACTIVE才能删除,如果不是多次执行)
alter system switch logfile;
alter system switch logfile;
alter system switch logfile;
alter system checkpoint;
3.删除旧的日志组(注意:ACTIVE状态的无法删除,需要先切换状态)
--删除前确认一下状态
select group#,members,bytes/1024/1024,status from v$log;
--删除日志组
alter database drop logfile group 1;
alter database drop logfile group 2;
alter database drop logfile group 3;
4.操作系统下删除原日志组1、2、3中的文件
rm -rf /opt/oracle/oradata/orcl/redo01.log
rm -rf /opt/oracle/oradata/orcl/redo02.log
rm -rf /opt/oracle/oradata/orcl/redo03.log
5.重建4个新的日志组1、2、3、4
alter database add logfile group 1 ('/opt/oracle/oradata/orcl/redo01.log') size 2G;
alter database add logfile group 2 ('/opt/oracle/oradata/orcl/redo02.log') size 2G;
alter database add logfile group 3 ('/opt/oracle/oradata/orcl/redo03.log') size 2G;
alter database add logfile group 4 ('/opt/oracle/oradata/orcl/redo04.log') size 2G;
6.切换日志组
alter system switch logfile;
alter system switch logfile;
alter system switch logfile;
alter system switch logfile;
alter system checkpoint;
7.删除中间过渡用的日志组10,11,12
alter database drop logfile group 10;
alter database drop logfile group 11;
alter database drop logfile group 12;
8.删除原日志组10,11,12的文件
rm -rf /opt/oracle/oradata/orcl/redo10.log
rm -rf /opt/oracle/oradata/orcl/redo11.log
rm -rf /opt/oracle/oradata/orcl/redo12.log
9.备份当前的最新的控制文件
SQL> connect / as sysdba
SQL> alter database backup controlfile to trace resetlogs;
step5:创建redolog同步账号
DROP USER JACKREDO cascade;
CREATE USER JACKREDO IDENTIFIED BY 123456;
GRANT connect, resource, create session to JACKREDO;
GRANT select on sys.v_$database to JACKREDO;
GRANT select any table to JACKREDO;
GRANT select any transaction to JACKREDO;
GRANT select on sys.v_$logmnr_session to JACKREDO;
GRANT select on sys.v_$logmnr_transaction to JACKREDO;
GRANT select on sys.v_$logmnr_logs to JACKREDO;
GRANT select on sys.v_$logmnr_logfile to JACKREDO;
GRANT select on sys.v_$logmnr_contents to JACKREDO;
GRANT select on sys.v_$logmnr_dictionary to JACKREDO;
GRANT select on sys.v_$logmnr_parameters to JACKREDO;
GRANT select on sys.v_$log to JACKREDO;
GRANT select on sys.v_$logfile to JACKREDO;
GRANT select on sys.v_$archived_log to JACKREDO;
GRANT execute_catalog_role to JACKREDO;
GRANT execute on sys.dbms_logmnr to JACKREDO;
GRANT execute on sys.dbms_logmnr_d to JACKREDO;
注意:
1.如果是Oracle12c还需要执行下面授权
GRANT logmining to DXTREDOLOGSYNC;
2.如果是创建CDB用户,需要用C##打头的账号,因此需要把JACKREDO整体替换成C##JACKREDO