今天需要对一个24*7的生产库创建一个DG的物理备库,要求主库不能停机,一开始以为不可能,后来查了下文档,原来通过rman的duplicate命令可以实现在线创建物理备库。
主备库的信息如下:
角色 db_name db_unique_name 主机 网络连接字符串
主库 jkka jkka lx32 jkkapri
备库 jkka jkka2 lx201 jkkasta
SYS@JKKA>select log_mode,force_logging from v$database; LOG_MODE FOR ------------ --- ARCHIVELOG NO从上面我们发现主库已经开启了归档,但没有开启force logging,可以通过以下语句开启:
SYS@JKKA>alter database force logging; Database altered.
$ orapwd file=$ORACLE_HOME/dbs/orapwjkka确认参数remote_login_passwordfile为EXCLUSIVE(默认值):
SYS@JKKA>show parameter remote_login_passwordfile NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ remote_login_passwordfile string EXCLUSIVE通过v$pwfile_users再次确认sys用户在密码文件中:
SYS@JKKA>select * from v$pwfile_users; USERNAME SYSDB SYSOP SYSAS ------------------------------ ----- ----- ----- SYS TRUE TRUE FALSE
SYS@JKKA>show parameter db_name NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_name string jkka SYS@JKKA>show parameter db_unique_name NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ db_unique_name string jkka接着,修改log_acchive_config参数,在dg_config属性分别写上主备库的db_unique_name:
SYS@JKKA>alter system set log_archive_config='DG_CONFIG=(jkka,jkka2)'; System altered.配置log_archive_dest_1写入本地目录:
SYS@JKKA>alter system set log_archive_dest_1='location=/data/oradata/jkka/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=jkka'; System altered. SYS@JKKA>alter system set log_archive_dest_state_1=enable; System altered.
SYS@JKKA>alter system set log_archive_dest_state_2=defer; System altered. SYS@JKKA>alter system set log_archive_dest_2='service=jkkasta ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=jkka2'; System altered.下面这些参数是可选的,只有当主库切换成备库时有效,但强烈建议配置,否则以后主备库切换会失败。
SYS@JKKA>alter system set fal_server=jkka2; System altered. SYS@JKKA>alter system set fal_client=jkka; System altered. SYS@JKKA>alter system set standby_file_management=auto; System altered.最后创建pfile
SYS@JKKA>create pfile from spfile; File created.
db_unique_name='jkka2' fal_client='JKKA2' fal_server='JKKA' log_archive_dest_1='location=/data/oradata/jkka/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=jkka2' log_archive_dest_2='service=jkkapri ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) db_unique_name=jkka'
$ export ORACLE_SID=jkka $ sqlplus / as sysdba SQL>startup nomount
LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = lx32)(PORT = 1521)) ) )2)备库的监听器设置
LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = lx201)(PORT = 1521)) ) )3)主备库tnsnames.ora的设置
jkkasta = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =lx201)(PORT = 1521)) ) (CONNECT_DATA = (sid = jkka) ) ) jkkapri = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST =lx32)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (sid =jkka) ) )4)测试主备库是否互通
主库: $ sqlplus sys@jkkasta as sysdba 备库: $ sqlplus sys@jkkapri as sysdba
$ rman target / RMAN> backup full format='/home/oracle/backup/ora_bak/data/db_jkka_%U' database include current controlfile for standby plus archivelog format='/home/oracle/backup/ora_bak/data/arc_jkka_%U';
$ rman target sys/***@jkkapri AUXILIARY / RMAN> duplicate target database for standby dorecover nofilenamecheck;
ORACLE error from auxiliary database: ORA-19527: physical standby redo log must be renamed ORA-00312: online log 1 thread 1: '/data/oradata/jkka/data/redoa1.log' RMAN-05535: WARNING: All redo log files were not defined properly.这是因为oracle为了加快备库与主库switchover的速度,从10.2开始增加了一个增强的功能,就是当MRP启动时会去清理备库上online redo log。如果不考虑switchover(备库上不创建online reod log),那么可以忽略这个错误,因为这个错只是一个提示性的信息,不会影响备库的MRP的工作。如果考虑switchover,就要在备库上创建online reod log,需要数据库在打开的情况下,具体见第5)步。
SYS@JKKA>ALTER DATABASE ADD STANDBY LOGFILE GROUP 10 ('/data/oradata/jkka/data/standby_redo10.log') size 100M; Database altered. SYS@JKKA>ALTER DATABASE ADD STANDBY LOGFILE GROUP 11 ('/data/oradata/jkka/data/standby_redo11.log') size 100M; Database altered. SYS@JKKA>ALTER DATABASE ADD STANDBY LOGFILE GROUP 12 ('/data/oradata/jkka/data/standby_redo12.log') size 100M; Database altered. SYS@JKKA>ALTER DATABASE ADD STANDBY LOGFILE GROUP 13 ('/data/oradata/jkka/data/standby_redo13.log') size 100M; Database altered.
SQL>create spfile from pfile; File created. SQL>shutdown immediate SQL>startup
SYS@jkka> alter system set standby_file_management=manual; System altered. SYS@jkka> alter system set LOG_FILE_NAME_CONVERT='/data/oradata/jkka/data/','/data/oradata/jkka/data/' scope=spfile; System altered. shutdown immediate; startup; SYS@jkka> alter database clear logfile group 1; Database altered. SYS@jkka> alter database clear logfile group 2; Database altered. SYS@jkka> alter database clear logfile group 3; Database altered. SYS@jkka> alter system reset LOG_FILE_NAME_CONVERT; System altered. shutdown immediate; startup; SYS@jkka> alter system set standby_file_management=auto; System altered.
SYS@JKKA>alter system set log_archive_dest_state_2=enable; System altered.
SQL>ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION; Database altered.
SQL>SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; SEQUENCE# FIRST_TIME NEXT_TIME ---------- ------------------- ------------------- 504 2013-08-22 14:41:54 2013-08-22 20:32:39
SYS@JKKA>select max(sequence#) from v$archived_log; MAX(SEQUENCE#) -------------- 504
SYS@JKKA>ALTER SYSTEM SWITCH LOGFILE; System altered.这时再看备库的归档日志,如果505已经从主库成功拷贝至备库,说明主备库同步正常。
SQL>SELECT SEQUENCE#, FIRST_TIME, NEXT_TIME FROM V$ARCHIVED_LOG ORDER BY SEQUENCE#; SEQUENCE# FIRST_TIME NEXT_TIME ---------- ------------------- ------------------- 504 2013-08-22 14:41:54 2013-08-22 20:32:39 505 2013-08-22 20:32:39 2013-08-22 20:35:41
《[Oracle] Data Guard 系列(1) - 三种保护模式》
《[Oracle] Data Guard 系列(2) - 日志传输》
《[Oracle] Data Guard 系列(3) - 日志应用》
《[Oracle] Data Guard 系列(4) - 在不停主库的情况下创建物理备库》
《[Oracle] Data Guard 系列(5) - 创建逻辑备库》
《[Oracle] Data Guard 系列(6) - 角色转换》