过程和类似,只是不需要重启数据库。
目的:创建standby,不重启源数据库
1设定环境如下:
Primary数据库
IP | 172.17.22.16 |
SID | orcl |
Standby数据库
IP | 172.17.22.17 |
SID | orcl_standby |
设置提示,以区分操作的位置
primary数据库
set SQLPROMPT Primary>
standby数据库
set SQLPROMPT StandBy>
1、Primary端设置 归档模式
确保primary数据库运行在归档模式
Primary>archive log listDatabase log mode No Archive ModeAutomatic archival DisabledArchive destination USE_DB_RECOVERY_FILE_DESTOldest online log sequence 5Current log sequence 7Primary>shutdown immediate;Database closed.Database dismounted.ORACLE instance shut down.Primary>startup mountORACLE instance started.Total System Global Area 3290345472 bytesFixed Size 2217832 bytesVariable Size 1795164312 bytesDatabase Buffers 1476395008 bytesRedo Buffers 16568320 bytesDatabase mounted.Primary>alter database archivelog;Database altered.Primary>alter database open;Database altered.Primary>archive log listDatabase log mode Archive ModeAutomatic archival EnabledArchive destination USE_DB_RECOVERY_FILE_DESTOldest online log sequence 5Next log sequence to archive 7Current log sequence 7Primary>
2、Primary端开启强制日志
Primary>select force_logging from v$database;FOR---NOPrimary>alter database force logging;Database altered.
关于FORCE LOGGING
想必大家知道有一些DDL语句可以通过指定NOLOGGING子句的方式避免写redo log(目的是提高速度,某些时候确实有效),指定数据库为FORCE LOGGING模式后,数据库将会记录除临时表空间或临时回滚段外所有的操作而忽略类似NOLOGGING之类的指定参数。如果在执行force logging时有nologging之类的语句在执行,则force logging会等待直到这类语句全部执行。FORCE LOGGING是做为固定参数保存在控制文件中,因此其不受重启之类操作的影响(只执行一次即可),如果想取消,可以通过alter database no force logging语句关闭强制记录。
3、standby端创建相关目录
为了和Primary库保存相同的结构,我们需要在Standby数据库建立相同的目录,首先查询现有Primary数据库的相关目录
Primary>col name for a30Primary>col value for a100Primary>select name ,value from v$parameter where name in ('audit_file_dest','background_dump_dest','control_files','core_dump_dest','user_dump_dest') ORDER BY name ASC;NAME VALUE------------------------------ ---------------------------------------------------------------------------------------------audit_file_dest /usr/oracle/app/admin/orcl/adumpbackground_dump_dest /usr/oracle/app/diag/rdbms/orcl/orcl/tracecontrol_files /usr/oracle/app/oradata/orcl/control01.ctl, /usr/oracle/app/flash_recovery_area/orcl/control02.ctlcore_dump_dest /usr/oracle/app/diag/rdbms/orcl/orcl/cdumpuser_dump_dest /usr/oracle/app/diag/rdbms/orcl/orcl/trace
在standby数据库服务器创建如下的目录:
[oracle@oracledb ~]$ mkdir -p /usr/oracle/standby/app/admin/orcl_standby/adump[oracle@oracledb ~]$ mkdir -p /usr/oracle/standby/app/diag/rdbms/orcl_standby/orcl_standby/trace[oracle@oracledb ~]$ mkdir -p /usr/oracle/standby/app/oradata/orcl_standby[oracle@oracledb ~]$ mkdir -p /usr/oracle/standby/app/flash_recovery_area/orcl_standby[oracle@oracledb ~]$ mkdir -p /usr/oracle/standby/app/diag/rdbms/orcl_standby/orcl_standby/
3、创建辅助实例密钥文件
方法一: 直接从Primary数据库复制密钥文件过来 (如果ORACLE_SID不同 需要改名)
[oracle@oracledb dbs]$ scp orapworcl 172.17.22.17:/usr/oracle/standby/app/product/11.2.0/dbhome_1/dbsoracle@172.17.22.17's password: orapworcl 100% 1536 1.5KB/s 00:00 [oracle@oracledb dbs]$
改名
[oracle@oracledb dbs]$ mv orapworcl orapworcl_standby
方法二: orapwd生成
orapwd FILE=/usr/oracle/standby/app/product/11.2.0/dbhome_1/dbs/orapworcl password=wangshengzhuang entries=30;
4、修改primary端初始化参数,
需要配置如下的参数,参数说明如下
1、与主库角色相关的初始化参数说明:DB_NAME 注意保持同一个DataGuard环境中所有数据库DB_NAME相同 DB_UNIQUE_NAME 为每一个数据库指定一个唯一的名称,以标示同一个dataguard环境中不同的数据库。 LOG_ARCHIVE_CONFIG 该参数通过DG_CONFIG属性罗列同一个Data Guard中所有DB_UNIQUE_NAME(含主库db及备库db),以逗号分隔。 例如:LOG_ARCHIVE_CONFIG='DB_CONFIG=(orcl,orcl2)' LOG_ARCHIVE_DEST_n 归档文件的生成路径。该参数非常重要,dataguard就是通过这里的设置传输日志的。 LOG_ARCHIVE_DEST_STATE_n 指定参数值为ENABLE,标示对应的LOG_ARCHIVE_DEST_n参数是否有效。 REMOTE_LOGIN_PASSWORDFILE 推荐设置参数值为EXCLUSIVE或者SHARED,注意保证相同Data Guard配置中所有db服务器sys密码相同。如果不同日志传输会失败。数据库默认是EXCLUSIVE,一般不用修改。 LOG_ARCHIVE_FORMAT 指定归档文件格式。一般也不用修改,保持默认即可 2、以下参数为备库角色相关的参数,建议在主库的初始化参数中也进行设置,这样在主备库角色相互转换后不需要做修改dataguard也能正常运行。 FAL_SERVER 指定备库到主数据库的连接服务名,FAL_SERVER = orcl2日志所在服务器。 FAL_CLIENT 指定主库到备库的连接服务名,FAL_CLIENT = orcl日志接收客户端。 STANDBY_FILE_MANAGEMENT 如果主库的数据文件发生修改(如新建,重命名等)则按照本参数的设置在备库中做相应修改。设为AUTO表示自动管理。设为MANUAL表示需要手工管理。 例如:STANDBY_FILE_MANAGEMENT=AUTO |
在Primary端根据spfile生成pfile,并备份
Primary>create pfile from spfile;File created.
查询Primary库的db_unique_name,(默认和db_name相同)
Primary>show parameter db_unique_name;NAME TYPE VALUE------------------------------------ ---------------------- ------------------------------db_unique_name string orcl
修改spfile参数值
-------为了不重启,沿用上面的db_unique_name --alter system set DB_UNIQUE_NAME=orcl scope=spfile----这里的orcl和orcl_standby为别为主库和备库的db_unique_namealter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,orcl_standby)' scope=spfile -----这里的service为主库连接到备库的服务名,后面会在tnsnames.ora文件中配置 valid_for参数说明这个归档日志目的地在本数据库为主库的角色下才需要把online_logfile传输到备库去。arch async NOAFFIRM说明的是同步的方式,这个同步的方式有三种方式,最大保护,最大性能,最大可用。每个方式有不同的设置,具体见后面说明alter system set LOG_ARCHIVE_DEST_2='SERVICE=tns_standby ARCH ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl_standby'----- 暂时不启用日志传送alter system set LOG_ARCHIVE_DEST_STATE_2=DEFER------以下修改的是作为备库角色需要的参数,为了方便以后主备库切换,建议在主库中也配置作为备库角色的相关参数。alter system set FAL_SERVER=tns_standbyalter system set FAL_CLIENT=tns_primaryalter system set STANDBY_FILE_MANAGEMENT=AUTO
alter system set DB_FILE_NAME_CONVERT='/usr/oracle/standby/app/oradata/orcl_standby/','/usr/oracle/app/oradata/orcl/' scope=spfile;
alter system set LOG_FILE_NAME_CONVERT='/usr/oracle/standby/app/oradata/orcl_standby/','/usr/oracle/app/oradata/orcl/' scope=spfile;
生成standby端的pfile
在Primary端根据spfile重新生成pfile,用以启动standby数据库
Primary>create pfile from spfile;File created.
复制生成的initorcl.ora到standby的$ORACLE_HOME/dbs目录下,并改名(因为实例名不同)
[oracle@oracledb dbs]$ pwd/usr/oracle/app/product/11.2.0/dbhome_1/dbs[oracle@oracledb dbs]$ scp initorcl.ora 172.17.22.17:/usr/oracle/standby/app/product/11.2.0/dbhome_1/dbsThe authenticity of host '172.17.22.17 (172.17.22.17)' can't be established.RSA key fingerprint is 72:28:f5:f9:9c:f8:49:23:48:6d:9d:d4:0e:0c:89:71.Are you sure you want to continue connecting (yes/no)? yesWarning: Permanently added '172.17.22.17' (RSA) to the list of known hosts.oracle@172.17.22.17's password: initorcl.ora 100% 1291 1.3KB/s 00:00 [oracle@oracledb dbs]$
改名
[oracle@oracledb dbs]$ mv initorcl.ora initorcl_standby.ora
修改standbyd端的initorcl_standby.ora文件,内容如下
------这里的实例名要由orcl改为orcl_standby
orcl_standby.__db_cache_size=1476395008orcl_standby.__java_pool_size=16777216orcl_standby.__large_pool_size=16777216orcl_standby.__oracle_base='/usr/oracle/app'#ORACLE_BASE set from environmentorcl_standby.__pga_aggregate_target=1325400064orcl_standby.__sga_target=1979711488orcl_standby.__shared_io_pool_size=0orcl_standby.__shared_pool_size=436207616orcl_standby.__streams_pool_size=0
*.audit_file_dest='/usr/oracle/standby/app/admin/orcl_standby/adump'*.audit_trail='db'*.compatible='11.2.0.0.0'*.control_files='/usr/oracle/standby/app/oradata/orcl_standby/control01.ctl','/usr/oracle/standby/app/flash_recovery_area/orcl_standby/control02.ctl'*.db_block_size=8192*.db_domain=''*.db_name='orcl'*.db_recovery_file_dest='/usr/oracle/standby/app/flash_recovery_area'*.db_recovery_file_dest_size=4070572032*.diagnostic_dest='/usr/oracle/standby/app'*.dispatchers='(PROTOCOL=TCP) (SERVICE=orclXDB)'*.memory_target=3299868672*.nls_language='SIMPLIFIED CHINESE'*.nls_territory='CHINA'*.open_cursors=300*.processes=150*.remote_login_passwordfile='EXCLUSIVE'*.undo_tablespace='UNDOTBS1'*.DB_UNIQUE_NAME=orcl_standby*.LOG_ARCHIVE_CONFIG='DG_CONFIG=(orcl,orcl_standby)'*.LOG_ARCHIVE_DEST_2='SERVICE=tns_primary ARCH ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl'*.LOG_ARCHIVE_DEST_STATE_2=ENABLE
------路径转换
*.DB_FILE_NAME_CONVERT= '/usr/oracle/app/oradata/orcl/','/usr/oracle/standby/app/oradata/orcl_standby/' *.LOG_FILE_NAME_CONVERT='/usr/oracle/app/oradata/orcl/','/usr/oracle/standby/app/oradata/orcl_standby/'
*.FAL_SERVER=tns_primary
*.FAL_CLIENT=tns_standby
*.STANDBY_FILE_MANAGEMENT=AUTO
通过复制的pfile创建Standby数据库的spfile
StandBy> create spfile from pfile;File created.
启动到nomount环境
SQL> startup nomountORACLE instance started.Total System Global Area 3290345472 bytesFixed Size 2217832 bytesVariable Size 1795164312 bytesDatabase Buffers 1476395008 bytesRedo Buffers 16568320 bytes
5、配置监听服务
Primary端监听(应该已经存在,大多数情况下不用重新配置)
# listener.ora Network Configuration File: /usr/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.ora# Generated by Oracle configuration tools.LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.22.16)(PORT = 1521)) ) )ADR_BASE_LISTENER = /usr/oracle/app
StandBy端监听(配置了静态监听 服务名GLOBAL_DBNAME = StandBy)
# listener.ora Network Configuration File: /usr/oracle/app/product/11.2.0/dbhome_1/network/admin/listener.ora# Generated by Oracle configuration tools.SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = StandBy) (ORACLE_HOME =/usr/oracle/standby/app/product/11.2.0/dbhome_1) (SID_NAME = orcl_standby) ) )LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.22.17)(PORT = 1521)) ) )ADR_BASE_LISTENER = /usr/oracle/app
启动standby端监听
[oracle@oracledb admin]$ lsnrctl startLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 23-DEC-2015 15:48:15Copyright (c) 1991, 2009, Oracle. All rights reserved.Starting /usr/oracle/standby/app/product/11.2.0/dbhome_1/bin/tnslsnr: please wait...TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionSystem parameter file is /usr/oracle/standby/app/product/11.2.0/dbhome_1/network/admin/listener.oraLog messages written to /usr/oracle/standby/app/diag/tnslsnr/oracledb/listener/alert/log.xmlListening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.17.22.17)(PORT=1521)))Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))STATUS of the LISTENER------------------------Alias LISTENERVersion TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionStart Date 23-DEC-2015 15:48:16Uptime 0 days 0 hr. 0 min. 0 secTrace Level offSecurity ON: Local OS AuthenticationSNMP OFFListener Parameter File /usr/oracle/standby/app/product/11.2.0/dbhome_1/network/admin/listener.oraListener Log File /usr/oracle/standby/app/diag/tnslsnr/oracledb/listener/alert/log.xmlListening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.17.22.17)(PORT=1521)))Services Summary...Service "StandBy" has 1 instance(s). Instance "orcl", status UNKNOWN, has 1 handler(s) for this service...The command completed successfully
6、配置网络服务名,并测试互通性
Primary端和StandBy端都要进行如下配置:
tns_primary = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.22.16)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ) ) )tns_standby = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 172.17.22.17)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = ) ) )
***********************************************************************************************
SERVICE_NAME 的值参考lsnrctl的输出,确保用sqlplus工具或者navicact工具能够连接SERVICE_NAME
因为fal_server 会使用服务名,如果配置不正确,这归档日志无法正常发送
***********************************************************************************************
在primary端和standby端都进行测试(为了角色切换)
[oracle@oracledb admin]$ tnsping tns_primary[oracle@oracledb admin]$ tnsping tns_standby
7、duplicate standby
rman连接两个数据库
[oracle@oracledb admin]$ rman target sys/wangshengzhuang@tns_primary auxiliary sys/wangshengzhuang@tns_standbyRecovery Manager: Release 11.2.0.1.0 - Production on Wed Dec 23 16:11:51 2015Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: ORCL (DBID=1426832466)connected to auxiliary database: ORCL (not mounted)
开始复制
RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;Starting Duplicate Db at 23-DEC-15using target database control file instead of recovery catalogallocated channel: ORA_AUX_DISK_1channel ORA_AUX_DISK_1: SID=20 device type=DISKRMAN-00571: ===========================================================RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============RMAN-00571: ===========================================================RMAN-03002: failure of Duplicate Db command at 12/23/2015 16:13:38RMAN-05541: no archived logs found in target database
primary端切换下日志,quit重新执行rman duplicate即可
[oracle@oracledb ~]$ rman target sys/wangshengzhuang@tns_primary auxiliary sys/wangshengzhuang@tns_standby Recovery Manager: Release 11.2.0.1.0 - Production on Wed Dec 30 16:56:13 2015Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.connected to target database: ORCL (DBID=1426832466)connected to auxiliary database: ORCL (not mounted)RMAN> DUPLICATE TARGET DATABASE FOR STANDBY FROM ACTIVE DATABASE DORECOVER NOFILENAMECHECK;Starting Duplicate Db at 30-DEC-15using target database control file instead of recovery catalogallocated channel: ORA_AUX_DISK_1channel ORA_AUX_DISK_1: SID=20 device type=DISKcontents of Memory Script:{ backup as copy reuse targetfile '/usr/oracle/app/product/11.2.0/dbhome_1/dbs/orapworcl' auxiliary format '/usr/oracle/standby/app/product/11.2.0/dbhome_1/dbs/orapworcl_standby' ;}executing Memory ScriptStarting backup at 30-DEC-15allocated channel: ORA_DISK_1channel ORA_DISK_1: SID=35 device type=DISKFinished backup at 30-DEC-15contents of Memory Script:{ backup as copy current controlfile for standby auxiliary format '/usr/oracle/standby/app/oradata/orcl_standby/control01.ctl'; restore clone controlfile to '/usr/oracle/standby/app/flash_recovery_area/orcl_standby/control02.ctl' from '/usr/oracle/standby/app/oradata/orcl_standby/control01.ctl';}executing Memory ScriptStarting backup at 30-DEC-15using channel ORA_DISK_1channel ORA_DISK_1: starting datafile copycopying standby control fileoutput file name=/usr/oracle/app/product/11.2.0/dbhome_1/dbs/snapcf_orcl.f tag=TAG20151230T165618 RECID=4 STAMP=899830578channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01Finished backup at 30-DEC-15Starting restore at 30-DEC-15using channel ORA_AUX_DISK_1channel ORA_AUX_DISK_1: copied control file copyFinished restore at 30-DEC-15contents of Memory Script:{ sql clone 'alter database mount standby database';}executing Memory Scriptsql statement: alter database mount standby databasecontents of Memory Script:{ set newname for tempfile 1 to "/usr/oracle/standby/app/oradata/orcl_standby/temp01.dbf"; switch clone tempfile all; set newname for datafile 1 to "/usr/oracle/standby/app/oradata/orcl_standby/system01.dbf"; set newname for datafile 2 to "/usr/oracle/standby/app/oradata/orcl_standby/sysaux01.dbf"; set newname for datafile 3 to "/usr/oracle/standby/app/oradata/orcl_standby/undotbs01.dbf"; set newname for datafile 4 to "/usr/oracle/standby/app/oradata/orcl_standby/users01.dbf"; backup as copy reuse datafile 1 auxiliary format "/usr/oracle/standby/app/oradata/orcl_standby/system01.dbf" datafile 2 auxiliary format "/usr/oracle/standby/app/oradata/orcl_standby/sysaux01.dbf" datafile 3 auxiliary format "/usr/oracle/standby/app/oradata/orcl_standby/undotbs01.dbf" datafile 4 auxiliary format "/usr/oracle/standby/app/oradata/orcl_standby/users01.dbf" ; sql 'alter system archive log current';}executing Memory Scriptexecuting command: SET NEWNAMErenamed tempfile 1 to /usr/oracle/standby/app/oradata/orcl_standby/temp01.dbf in control fileexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEexecuting command: SET NEWNAMEStarting backup at 30-DEC-15using channel ORA_DISK_1channel ORA_DISK_1: starting datafile copyinput datafile file number=00001 name=/usr/oracle/app/oradata/orcl/system01.dbfoutput file name=/usr/oracle/standby/app/oradata/orcl_standby/system01.dbf tag=TAG20151230T165625channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:15channel ORA_DISK_1: starting datafile copyinput datafile file number=00002 name=/usr/oracle/app/oradata/orcl/sysaux01.dbfoutput file name=/usr/oracle/standby/app/oradata/orcl_standby/sysaux01.dbf tag=TAG20151230T165625channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:16channel ORA_DISK_1: starting datafile copyinput datafile file number=00003 name=/usr/oracle/app/oradata/orcl/undotbs01.dbfoutput file name=/usr/oracle/standby/app/oradata/orcl_standby/undotbs01.dbf tag=TAG20151230T165625channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:03channel ORA_DISK_1: starting datafile copyinput datafile file number=00004 name=/usr/oracle/app/oradata/orcl/users01.dbfoutput file name=/usr/oracle/standby/app/oradata/orcl_standby/users01.dbf tag=TAG20151230T165625channel ORA_DISK_1: datafile copy complete, elapsed time: 00:00:01Finished backup at 30-DEC-15sql statement: alter system archive log currentcontents of Memory Script:{ backup as copy reuse archivelog like "/usr/oracle/app/flash_recovery_area/ORCL/archivelog/2015_12_30/o1_mf_1_8_c8772wkh_.arc" auxiliary format "/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_%u_.arc" ; catalog clone recovery area; switch clone datafile all;}executing Memory ScriptStarting backup at 30-DEC-15using channel ORA_DISK_1channel ORA_DISK_1: starting archived log copyinput archived log thread=1 sequence=8 RECID=2 STAMP=899830620output file name=/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arc RECID=0 STAMP=0channel ORA_DISK_1: archived log copy complete, elapsed time: 00:00:01Finished backup at 30-DEC-15searching for all files in the recovery areaList of Files Unknown to the Database=====================================File Name: /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arccataloging files...cataloging doneList of Cataloged Files=======================File Name: /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arcdatafile 1 switched to datafile copyinput datafile copy RECID=4 STAMP=899830621 file name=/usr/oracle/standby/app/oradata/orcl_standby/system01.dbfdatafile 2 switched to datafile copyinput datafile copy RECID=5 STAMP=899830621 file name=/usr/oracle/standby/app/oradata/orcl_standby/sysaux01.dbfdatafile 3 switched to datafile copyinput datafile copy RECID=6 STAMP=899830621 file name=/usr/oracle/standby/app/oradata/orcl_standby/undotbs01.dbfdatafile 4 switched to datafile copyinput datafile copy RECID=7 STAMP=899830621 file name=/usr/oracle/standby/app/oradata/orcl_standby/users01.dbfcontents of Memory Script:{ set until scn 1027736; recover standby clone database delete archivelog ;}executing Memory Scriptexecuting command: SET until clauseStarting recover at 30-DEC-15using channel ORA_AUX_DISK_1starting media recoveryarchived log for thread 1 with sequence 8 is already on disk as file /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arcarchived log file name=/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arc thread=1 sequence=8media recovery complete, elapsed time: 00:00:00Finished recover at 30-DEC-15Finished Duplicate Db at 30-DEC-15
8、启用日志传送
Primary>show parameter LOG_ARCHIVE_DEST_STATE_2NAME TYPE VALUE------------------------------------ ---------------------- ------------------------------log_archive_dest_state_2 string DEFERlog_archive_dest_state_20 string enablelog_archive_dest_state_21 string enablelog_archive_dest_state_22 string enablelog_archive_dest_state_23 string enablelog_archive_dest_state_24 string enablelog_archive_dest_state_25 string enablelog_archive_dest_state_26 string enablelog_archive_dest_state_27 string enablelog_archive_dest_state_28 string enablelog_archive_dest_state_29 string enablePrimary>alter system set LOG_ARCHIVE_DEST_STATE_2=ENABLE;System altered.
8、验证结果
查询primary数据库角色
Primary>select database_role from v$database;DATABASE_ROLE--------------------------------PRIMARY
查询standby数据库角色
StandBy>select database_role from v$database;DATABASE_ROLE--------------------------------PHYSICAL STANDBYStandBy>
primary端插入一条数据
Primary> INSERT INTO "SCOTT"."DEPT" ("DEPTNO", "DNAME", "LOC") VALUES ('12', 'OPERATIONS', 'OPERATIONS');1 row created.Primary>commit;Commit complete.Primary>alter system switch logfile;System altered.
standby端:启动redo应用、暂停redo应用 打开数据库,查询数据是否被同步过来了
StandBy>alter database recover managed standby database disconnect from session;Database altered.StandBy>alter database recover managed standby database cancel;Database altered.StandBy>alter database open;Database altered.StandBy>select open_mode from v$database;OPEN_MODE----------------------------------------READ ONLYStandBy>
见证奇迹的时刻:
StandBy>select * from scott.dept; DEPTNO DNAME LOC---------- ---------------------------- -------------------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 12 OPERATIONS OPERATIONS
9、启用实时应用redo
添加redo log
首先查询当前redo log的大小、位置
Primary>col group# for 9Primary>col status for a10Primary>col type for a10Primary>col member for a50;Primary>col is_rec for a10Primary>select * from v$logfile;GROUP# STATUS TYPE MEMBER IS_REC------ ---------- ---------- -------------------------------------------------- ------ 3 ONLINE /usr/oracle/app/oradata/orcl/redo03.log NO 2 ONLINE /usr/oracle/app/oradata/orcl/redo02.log NO 1 ONLINE /usr/oracle/app/oradata/orcl/redo01.log NOPrimary>select * from v$log;GROUP# THREAD# SEQUENCE# BYTES BLOCKSIZE MEMBERS ARCHIV STATUS FIRST_CHANGE# FIRST_TIME NEXT_CHANGE# NEXT_TIME------ ---------- ---------- ---------- ---------- ---------- ------ ---------- ------------- ------------ ------------ ------------ 1 1 10 52428800 512 1 NO CURRENT 1029234 23-DEC-15 2.8147E+14 2 1 8 52428800 512 1 YES INACTIVE 1028340 23-DEC-15 1028421 23-DEC-15 3 1 9 52428800 512 1 YES INACTIVE 1028421 23-DEC-15 1029234 23-DEC-15
standby redo log的文件大小与primary数据库online redo log文件大小相同。
standby redo log的组数最好比主库online redo log多。
当前主库有三组、每组1个member、大小为50M, 我们在备库增加四组,每组1个member,大小为50M
StandBy>ALTER DATABASE ADD STANDBY LOGFILE GROUP 4('/usr/oracle/standby/app/oradata/orcl_standby/stbyredolog4a.log') SIZE 50 M;Database altered.StandBy>ALTER DATABASE ADD STANDBY LOGFILE GROUP 5('/usr/oracle/standby/app/oradata/orcl_standby/stbyredolog5a.log') SIZE 50 M;Database altered.StandBy>ALTER DATABASE ADD STANDBY LOGFILE GROUP 6('/usr/oracle/standby/app/oradata/orcl_standby/stbyredolog6a.log') SIZE 50 M;Database altered.StandBy>ALTER DATABASE ADD STANDBY LOGFILE GROUP 7('/usr/oracle/standby/app/oradata/orcl_standby/stbyredolog7a.log') SIZE 50 M;Database altered.
查询备库当前的日志
Standby>select group#, type, member from v$logfile;GROUP# TYPE MEMBER----------------------------------------------------------------------------------------------------------------------------- 3 ONLINE /usr/oracle/standby/app/oradata/orcl_standby/redo03.log 2 ONLINE /usr/oracle/standby/app/oradata/orcl_standby/redo02.log 1 ONLINE /usr/oracle/standby/app/oradata/orcl_standby/redo01.log 4 STANDBY /usr/oracle/standby/app/oradata/orcl_standby/stbyredolog4a.log 5 STANDBY /usr/oracle/standby/app/oradata/orcl_standby/stbyredolog5a.log 6 STANDBY /usr/oracle/standby/app/oradata/orcl_standby/stbyredolog6a.log 7 STANDBY /usr/oracle/standby/app/oradata/orcl_standby/stbyredolog7a.log
为了switchover,我们在主库也增加4组standby redo log
Primary>ALTER DATABASE ADD STANDBY LOGFILE GROUP 4('/usr/oracle/app/oradata/orcl/stbyredolog4a.log') SIZE 50 M;Database altered.Primary>ALTER DATABASE ADD STANDBY LOGFILE GROUP 5('/usr/oracle/app/oradata/orcl/stbyredolog5a.log') SIZE 50 M;Database altered.Primary>ALTER DATABASE ADD STANDBY LOGFILE GROUP 6('/usr/oracle/app/oradata/orcl/stbyredolog6a.log') SIZE 50 M;Database altered.Primary>ALTER DATABASE ADD STANDBY LOGFILE GROUP 7('/usr/oracle/app/oradata/orcl/stbyredolog7a.log') SIZE 50 M;Database altered.
查看结果:
Primary>select * from v$logfile;GROUP# STATUS TYPE MEMBER IS_REC------ ---------- ---------- -------------------------------------------------- ------ 3 ONLINE /usr/oracle/app/oradata/orcl/redo03.log NO 2 ONLINE /usr/oracle/app/oradata/orcl/redo02.log NO 1 ONLINE /usr/oracle/app/oradata/orcl/redo01.log NO 4 STANDBY /usr/oracle/app/oradata/orcl/stbyredolog4a.log NO 5 STANDBY /usr/oracle/app/oradata/orcl/stbyredolog5a.log NO 6 STANDBY /usr/oracle/app/oradata/orcl/stbyredolog6a.log NO 7 STANDBY /usr/oracle/app/oradata/orcl/stbyredolog7a.log NO7 rows selected.
更改primary和standby端的log_archive_dest_2、
更改Primary端的log_archive_dest_2
Primary>alter system set log_archive_dest_2='SERVICE=tns_standby LGWR ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl_standby';System altered.
更改standby端的log_archive_dest_2
>alter system set log_archive_dest_2='SERVICE=tns_primary LGWR ASYNC NOAFFIRM VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=orcl';System altered.
启用实时StandBy端redo应用
StandBy>alter database recover managed standby database using current logfile disconnect from session;
验证:
首先在Primay端插入一条数据:
Primary>select * from scott.dept; DEPTNO DNAME LOC---------- ---------------------------- -------------------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 12 OPERATIONS OPERATIONSPrimary>INSERT INTO "SCOTT"."DEPT" ("DEPTNO", "DNAME", "LOC") VALUES ('13', 'OPERATIONS', 'OPERATIONS');1 row created.Primary>commit;Commit complete.
standby端查看
StandBy>select * from scott.dept; DEPTNO DNAME LOC---------- ---------------------------- -------------------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 12 OPERATIONS OPERATIONS 6 rows selected.
10、switchover
备库暂停 redo应用
StandBy>alter database recover managed standby database cancel;Database altered.
查询主库是否支持switchover操作
Primary> select switchover_status from v$database;SWITCHOVER_STATUS----------------------------------------TO STANDBY
查询备库是否支持switchover操作
StandBy> select switchover_status from v$database;SWITCHOVER_STATUS----------------------------------------NOT ALLOWED
not allowed是因为主库还未变切换为standby
switchover,primary切换为物理standby,切换后查看数据库角色、打开模式、
Primary>alter database commit to switchover to physical standby;Database altered.Primary>shutdown immediate;ORA-01507: database not mountedORACLE instance shut down.Primary>startupORACLE instance started.Total System Global Area 3290345472 bytesFixed Size 2217832 bytesVariable Size 1795164312 bytesDatabase Buffers 1476395008 bytesRedo Buffers 16568320 bytesDatabase mounted.Database opened.Primary>select open_mode from v$database;OPEN_MODE----------------------------------------READ ONLYPrimary>select database_role from v$database;DATABASE_ROLE--------------------------------PHYSICAL STANDBYPrimary>
如果报错ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected,关闭活动的连接即可
Primary>alter database commit to switchover to physical standby;alter database commit to switchover to physical standby*ERROR at line 1:ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected
物理standby切换为primary
SQL> select switchover_status from v$database;SWITCHOVER_STATUS----------------------------------------SWITCHOVER PENDING
如果是SWITCHOVER PENDING,说明当前standby数据库没有启动redo应用,重新执行下面的命令即可
alter database recover managed standby database using current logfile disconnect from session;
如果是session active 说明当前有用户连接到StandBy数据库,建议先断开这些连接,或者先关闭数据库,启动到mount状态(出现上面那个状态是你用sqlplus连接着主库,启动到mount状态就正常啦 )
SQL> shutdown immediate;Database closed.Database dismounted.ORACLE instance shut down.SQL> startup mount;ORACLE instance started.Total System Global Area 3290345472 bytesFixed Size 2217832 bytesVariable Size 1795164312 bytesDatabase Buffers 1476395008 bytesRedo Buffers 16568320 bytesDatabase mounted.SQL> select switchover_status from v$database;SWITCHOVER_STATUS----------------------------------------TO PRIMARY
切换
StandBy>select switchover_status from v$database;SWITCHOVER_STATUS----------------------------------------TO PRIMARYStandBy> alter database commit to switchover to primary;Database altered.StandBy>alter database open;Database altered.StandBy>select open_mode from v$database;OPEN_MODE----------------------------------------READ WRITEStandBy>select database_role from v$database;DATABASE_ROLE--------------------------------PRIMARYStandBy>
测试同上(插入删除),这里只进行简单测试
现在的Primay切换日志
> select max(sequence#) from v$archived_log;MAX(SEQUENCE#)-------------- 14SQL> alter system switch logfile;System altered.
在现在的standby查询
SYS@orcl>select max(sequence#) from v$archived_log;MAX(SEQUENCE#)-------------- 15
常用查询
1、查询进程的活动状态
select process,client_process,sequence#,status from v$managed_standby;
2、查询redo应用进度
select dest_name,archived_thread#,archived_seq#,applied_thread#,applied_seq#,db_unique_name from v$archive_dest_status where status ='VALID';
3、查询归档文件路径及创建信息
select name,creator,sequence#,applied,completion_time from v$archived_log;
4、查询归档历史
select first_time,first_change#,next_change#,sequence# from v$log_history;select thread#,sequence#,applied from v$archived_log;
5、参看数据库的基本信息
select database_role,db_unique_name,open_mode,protection_mode,protection_level,switchover_status from v$database;
6、查询redo应用及redo传输服务的活动状态
select database_role,db_unique_name,open_mode,protection_mode,protection_level,switchover_status from v$database;
7、检查应用模式
StandBy>select recovery_mode from v$archive_dest_status where dest_id=2;RECOVERY_MODE----------------------------------------------IDLE
取值
idle
managed:
managed real_time_apply:
8、在主库上执行只主要是查看日志归档目的地是否可用,如果远程归档目录不可用则error会显示错误信息
Primary>select dest_name,status,error from v$archive_dest;DEST_NAME STATUS ERROR------------------------- ---------- ----------------------------------------------------------------------------------------------------LOG_ARCHIVE_DEST_1 VALIDLOG_ARCHIVE_DEST_2 VALIDLOG_ARCHIVE_DEST_3 INACTIVELOG_ARCHIVE_DEST_4 INACTIVELOG_ARCHIVE_DEST_5 INACTIVELOG_ARCHIVE_DEST_6 INACTIVELOG_ARCHIVE_DEST_7 INACTIVELOG_ARCHIVE_DEST_8 INACTIVELOG_ARCHIVE_DEST_9 INACTIVELOG_ARCHIVE_DEST_10 INACTIVELOG_ARCHIVE_DEST_11 INACTIVELOG_ARCHIVE_DEST_12 INACTIVELOG_ARCHIVE_DEST_13 INACTIVELOG_ARCHIVE_DEST_14 INACTIVELOG_ARCHIVE_DEST_15 INACTIVELOG_ARCHIVE_DEST_16 INACTIVELOG_ARCHIVE_DEST_17 INACTIVELOG_ARCHIVE_DEST_18 INACTIVELOG_ARCHIVE_DEST_19 INACTIVELOG_ARCHIVE_DEST_20 INACTIVELOG_ARCHIVE_DEST_21 INACTIVELOG_ARCHIVE_DEST_22 INACTIVELOG_ARCHIVE_DEST_23 INACTIVELOG_ARCHIVE_DEST_24 INACTIVELOG_ARCHIVE_DEST_25 INACTIVELOG_ARCHIVE_DEST_26 INACTIVELOG_ARCHIVE_DEST_27 INACTIVELOG_ARCHIVE_DEST_28 INACTIVELOG_ARCHIVE_DEST_29 INACTIVELOG_ARCHIVE_DEST_30 INACTIVELOG_ARCHIVE_DEST_31 INACTIVESTANDBY_ARCHIVE_DEST VALID32 rows selected.
9、查询归档日志的应用情况。主备库上查询结果不同,在主库上对于每个归档文件会有两条记录。
Standby>select name,SEQUENCE#,APPLIED from v$archived_log order by sequence#;NAME SEQUENCE# APPLIED---------------------------------------------------------------------------------------------------------------------------------- ---------- ------------------/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_8_0lqq4kqs_.arc 8 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_9_c878jl2c_.arc 9 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_10_c878jl5h_.arc 10 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_11_c878jl92_.arc 11 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_12_c878zoqm_.arc 12 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_13_c87902oc_.arc 13 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_14_c879bdmq_.arc 14 YEStns_primary 14 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_15_c879ty73_.arc 15 YEStns_primary 15 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_16_c879yfv8_.arc 16 YEStns_primary 16 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_17_c87bj8s9_.arc 17 YEStns_primary 17 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_18_c87bmfnc_.arc 18 YEStns_primary 18 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_19_c87kfnfc_.arc 19 YEStns_primary 19 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_20_c87kozrv_.arc 20 YEStns_primary 20 NO/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_21_c87kq3v1_.arc 21 YEStns_primary 21 NO/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_22_c87kqj88_.arc 22 YEStns_primary 22 NO/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_23_c87m0kpm_.arc 23 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_24_c87mch18_.arc 24 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_25_c87mn8sw_.arc 25 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_26_c87po9r6_.arc 26 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_27_c87pwj5t_.arc 27 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_28_c87px4hz_.arc 28 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_29_c87pzfbv_.arc 29 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_30_c87pzr9s_.arc 30 YES/usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_31_c87pzsk7_.arc 31 YES33 rows selected.Standby>
10、查询dataguard状态信息
Standby>select message_num,message from v$dataguard_status;MESSAGE_NUM MESSAGE----------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 ARC0: Archival started 2 ARC1: Archival started 3 ARC2: Archival started 4 ARC1: Becoming the 'no FAL' ARCH 5 ARC2: Becoming the heartbeat ARCH 6 ARC3: Archival started 7 RFS[1]: Assigned to RFS process 5881 8 RFS[1]: Identified database type as 'physical standby': Client is ARCH pid 9099 9 RFS[2]: Assigned to RFS process 5892 10 RFS[2]: Identified database type as 'physical standby': Client is ARCH pid 9099 11 RFS[3]: Assigned to RFS process 5897 12 RFS[3]: Identified database type as 'physical standby': Client is ARCH pid 9101 13 Attempt to start background Managed Standby Recovery process 14 MRP0: Background Managed Standby Recovery process started 15 Managed Standby Recovery not using Real Time Apply 16 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_25_c87mn8sw_.arc 17 Media Recovery Waiting for thread 1 sequence 26 18 RFS[4]: Assigned to RFS process 5906 19 RFS[4]: Identified database type as 'physical standby': Client is ARCH pid 9099 20 RFS[5]: Assigned to RFS process 5911 21 RFS[5]: Identified database type as 'physical standby': Client is ARCH pid 9099 22 RFS[6]: Assigned to RFS process 5918 23 RFS[6]: Identified database type as 'physical standby': Client is ARCH pid 9099 24 RFS[7]: Assigned to RFS process 5925 25 RFS[7]: Identified database type as 'physical standby': Client is ARCH pid 9099 26 RFS[8]: Assigned to RFS process 5932 27 RFS[8]: Identified database type as 'physical standby': Client is ARCH pid 9099 28 RFS[9]: Assigned to RFS process 5938 29 RFS[9]: Identified database type as 'physical standby': Client is ARCH pid 9099 30 RFS[10]: Assigned to RFS process 5945 31 RFS[10]: Identified database type as 'physical standby': Client is ARCH pid 9099 32 RFS[11]: Assigned to RFS process 5952 33 RFS[11]: Identified database type as 'physical standby': Client is ARCH pid 9099 34 RFS[12]: Assigned to RFS process 5959 35 RFS[12]: Identified database type as 'physical standby': Client is ARCH pid 9099 36 RFS[13]: Assigned to RFS process 5970 37 RFS[13]: Identified database type as 'physical standby': Client is ARCH pid 9099 38 RFS[14]: Assigned to RFS process 5976 39 RFS[14]: Identified database type as 'physical standby': Client is ARCH pid 9099 40 RFS[15]: Assigned to RFS process 5984 41 RFS[15]: Identified database type as 'physical standby': Client is ARCH pid 9099 42 RFS[16]: Assigned to RFS process 5991 43 RFS[16]: Identified database type as 'physical standby': Client is ARCH pid 9099 44 RFS[17]: Assigned to RFS process 6006 45 RFS[17]: Identified database type as 'physical standby': Client is ARCH pid 9099 46 RFS[18]: Assigned to RFS process 6018 47 RFS[18]: Identified database type as 'physical standby': Client is ARCH pid 9099 48 RFS[19]: Assigned to RFS process 6024 49 RFS[19]: Identified database type as 'physical standby': Client is ARCH pid 9099 50 RFS[20]: Assigned to RFS process 6035 51 RFS[20]: Identified database type as 'physical standby': Client is ARCH pid 9099 52 RFS[21]: Assigned to RFS process 6047 53 RFS[21]: Identified database type as 'physical standby': Client is ARCH pid 9099 54 RFS[22]: Assigned to RFS process 6059 55 RFS[22]: Identified database type as 'physical standby': Client is ARCH pid 9099 56 RFS[23]: Assigned to RFS process 6070 57 RFS[23]: Identified database type as 'physical standby': Client is ARCH pid 9099 58 RFS[24]: Assigned to RFS process 6076 59 RFS[24]: Identified database type as 'physical standby': Client is ARCH pid 9099 60 RFS[25]: Assigned to RFS process 6082 61 RFS[25]: Identified database type as 'physical standby': Client is ARCH pid 9099 62 RFS[26]: Assigned to RFS process 6090 63 RFS[26]: Identified database type as 'physical standby': Client is ARCH pid 9099 64 RFS[27]: Assigned to RFS process 6097 65 RFS[27]: Identified database type as 'physical standby': Client is ARCH pid 9099 66 RFS[28]: Assigned to RFS process 6104 67 RFS[28]: Identified database type as 'physical standby': Client is ARCH pid 9099 68 RFS[29]: Assigned to RFS process 6110 69 RFS[29]: Identified database type as 'physical standby': Client is ARCH pid 9099 70 RFS[30]: Assigned to RFS process 6116 71 RFS[30]: Identified database type as 'physical standby': Client is ARCH pid 9099 72 RFS[31]: Assigned to RFS process 6123 73 RFS[31]: Identified database type as 'physical standby': Client is ARCH pid 9099 74 RFS[32]: Assigned to RFS process 6133 75 RFS[32]: Identified database type as 'physical standby': Client is ARCH pid 9099 76 RFS[33]: Assigned to RFS process 6144 77 RFS[33]: Identified database type as 'physical standby': Client is ARCH pid 9099 78 RFS[34]: Assigned to RFS process 6161 79 RFS[34]: Identified database type as 'physical standby': Client is ARCH pid 9099 80 RFS[35]: Assigned to RFS process 6167 81 RFS[35]: Identified database type as 'physical standby': Client is ARCH pid 9099 82 RFS[36]: Assigned to RFS process 6174 83 RFS[36]: Identified database type as 'physical standby': Client is ARCH pid 9099 84 RFS[37]: Assigned to RFS process 6181 85 RFS[37]: Identified database type as 'physical standby': Client is ARCH pid 9099 86 RFS[38]: Assigned to RFS process 6188 87 RFS[38]: Identified database type as 'physical standby': Client is ARCH pid 9099 88 RFS[39]: Assigned to RFS process 6201 89 RFS[39]: Identified database type as 'physical standby': Client is ARCH pid 9099 90 RFS[40]: Assigned to RFS process 6207 91 RFS[40]: Identified database type as 'physical standby': Client is ARCH pid 9099 92 RFS[41]: Assigned to RFS process 6214 93 RFS[41]: Identified database type as 'physical standby': Client is ARCH pid 9099 94 RFS[42]: Assigned to RFS process 6221 95 RFS[42]: Identified database type as 'physical standby': Client is ARCH pid 9099 96 RFS[43]: Assigned to RFS process 6232 97 RFS[43]: Identified database type as 'physical standby': Client is ARCH pid 9099 98 RFS[44]: Assigned to RFS process 6238 99 RFS[44]: Identified database type as 'physical standby': Client is ARCH pid 9099 100 RFS[45]: Assigned to RFS process 6244 101 RFS[45]: Identified database type as 'physical standby': Client is ARCH pid 9099 102 MRP0: Background Media Recovery cancelled with status 16037 103 MRP0: Background Media Recovery process shutdown 104 Managed Standby Recovery Canceled 105 RFS[46]: Assigned to RFS process 6253 106 RFS[46]: Identified database type as 'physical standby': Client is ARCH pid 9099 107 RFS[47]: Assigned to RFS process 6263 108 RFS[47]: Identified database type as 'physical standby': Client is ARCH pid 9099 109 RFS[48]: Assigned to RFS process 6270 110 RFS[48]: Identified database type as 'physical standby': Client is ARCH pid 9099 111 RFS[49]: Assigned to RFS process 6276 112 RFS[49]: Identified database type as 'physical standby': Client is ARCH pid 9099 113 RFS[50]: Assigned to RFS process 6284 114 RFS[50]: Identified database type as 'physical standby': Client is ARCH pid 9099 115 RFS[51]: Assigned to RFS process 6295 116 RFS[51]: Identified database type as 'physical standby': Client is ARCH pid 9099 117 RFS[52]: Assigned to RFS process 6301 118 RFS[52]: Identified database type as 'physical standby': Client is ARCH pid 9099 119 RFS[53]: Assigned to RFS process 6312 120 RFS[53]: Identified database type as 'physical standby': Client is ARCH pid 9099 121 RFS[54]: Assigned to RFS process 6320 122 RFS[54]: Identified database type as 'physical standby': Client is ARCH pid 9099 123 RFS[55]: Assigned to RFS process 6325 124 RFS[55]: Identified database type as 'physical standby': Client is ARCH pid 9099 125 RFS[56]: Assigned to RFS process 6332 126 RFS[56]: Identified database type as 'physical standby': Client is LGWR ASYNC pid 10167 127 Primary database is in MAXIMUM PERFORMANCE mode 128 ARC0: Beginning to archive thread 1 sequence 26 (1039145-1040585) 129 RFS[57]: Assigned to RFS process 6334 130 RFS[57]: Identified database type as 'physical standby': Client is LGWR ASYNC pid 10167 131 ARC0: Completed archiving thread 1 sequence 26 (0-0) 132 Primary database is in MAXIMUM PERFORMANCE mode 133 RFS[58]: Assigned to RFS process 6339 134 RFS[58]: Identified database type as 'physical standby': Client is ARCH pid 9099 135 RFS[59]: Assigned to RFS process 6356 136 RFS[59]: Identified database type as 'physical standby': Client is ARCH pid 9099 137 Attempt to start background Managed Standby Recovery process 138 MRP0: Background Managed Standby Recovery process started 139 Managed Standby Recovery starting Real Time Apply 140 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_26_c87po9r6_.arc 141 Media Recovery Waiting for thread 1 sequence 27 (in transit) 142 RFS[60]: Assigned to RFS process 6364 143 RFS[60]: Identified database type as 'physical standby': Client is ARCH pid 9099 144 MRP0: Background Media Recovery cancelled with status 16037 145 Managed Standby Recovery not using Real Time Apply 146 MRP0: Background Media Recovery process shutdown 147 Managed Standby Recovery Canceled 148 RFS[61]: Assigned to RFS process 6373 149 RFS[61]: Identified database type as 'physical standby': Client is ARCH pid 9099 150 ARC1: Beginning to archive thread 1 sequence 27 (1040585-1040839) 151 ARC1: Completed archiving thread 1 sequence 27 (0-0) 152 RFS[62]: Assigned to RFS process 6378 153 RFS[62]: Identified database type as 'physical standby': Client is ARCH pid 9099 154 RFS[63]: Assigned to RFS process 6382 155 RFS[63]: Identified database type as 'physical standby': Client is Foreground pid 9102 156 ARC3: Beginning to archive thread 1 sequence 28 (1040839-1040863) 157 ARC3: Completed archiving thread 1 sequence 28 (0-0) 158 RFS[64]: Assigned to RFS process 6386 159 RFS[64]: Identified database type as 'physical standby': Client is ARCH pid 9099 160 RFS[65]: Assigned to RFS process 6393 161 RFS[65]: Identified database type as 'physical standby': Client is ARCH pid 9095 162 ARC0: Beginning to archive thread 1 sequence 29 (1040863-1040945) 163 ARC0: Completed archiving thread 1 sequence 29 (0-0) 164 RFS[66]: Assigned to RFS process 6395 165 RFS[66]: Identified database type as 'physical standby': Client is ARCH pid 9099 166 RFS[67]: Assigned to RFS process 6400 167 RFS[67]: Identified database type as 'physical standby': Client is Foreground pid 9102 168 ARC1: Beginning to archive thread 1 sequence 30 (1040945-1040959) 169 ARC1: Completed archiving thread 1 sequence 30 (0-0) 170 RFS[68]: Assigned to RFS process 6404 171 RFS[68]: Identified database type as 'physical standby': Client is Foreground pid 9102 172 RFS[69]: Assigned to RFS process 6406 173 RFS[69]: Identified database type as 'physical standby': Client is Foreground pid 9102 174 Attempt to start background Managed Standby Recovery process 175 MRP0: Background Managed Standby Recovery process started 176 Managed Standby Recovery starting Real Time Apply 177 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_27_c87pwj5t_.arc 178 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_28_c87px4hz_.arc 179 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_29_c87pzfbv_.arc 180 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_30_c87pzr9s_.arc 181 Media Recovery Log /usr/oracle/standby/app/flash_recovery_area/ORCL_STANDBY/archivelog/2015_12_30/o1_mf_1_31_c87pzsk7_.arc 182 Resetting standby activation ID 1427590416 (0x55174d10) 183 MRP0: Media Recovery Complete: End-Of-REDO 184 MRP0: Background Media Recovery process shutdown 185 ALTER DATABASE SWITCHOVER TO PRIMARY 186 ARC0: Becoming the 'no SRL' ARCH 187 ARC0: Becoming the 'no SRL' ARCH 188 ARC1: Becoming the 'no SRL' ARCH188 rows selected.
11、查看是否有日志缺失
Standby>select * from v$archive_gap;no rows selected
主备库的起停和维护
Dataguard关闭(先关主库再关备库)
Dataguard开启(先开备库再开主库)
Failover切换方法
(1)判断主数据库确实出现严重的硬件故障或其他原因导致主数据库无法启动。
(2)在物理备用数据库上检查是否有archive redo log gaps
Standby>SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;no rows selected
如果有则消除archive redo log gaps
从主数据库上或其他备份的地方把没有传到物理备用数据库的archive redo log传到物理备用数据库上,并注册到物理备用数据库的controlfile中。
SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE 'archive redo log文件名称';
重复2,3步骤直到V$ARCHIVE_GAP视图无记录存在。
(3)查看归档文件是否完整
主库备库分别执行下面语句,取得各个线程已经归档的文件最大的序号,如果最大序号不同,则必须将多出的序号对应的归档文件复制到待转换的standby服务器(也有可能primary库已经无法打开了)
SQL> select distinct thread#, max(sequence#) over (partition by thread#) from v$archived_log; THREAD# MAX(SEQUENCE#)OVER(PARTITIONBYTHREAD#)---------- -------------------------------------- 1 84SQL> select max(sequence#) from v$archived_log;MAX(SEQUENCE#)-------------- 84
(4)在物理备用数据库上发起failover操作
SQL > ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE;
(5)把物理备用数据库转化成主用角色
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
(6)把新的主用数据库重新启动
SQL> SHUTDOWN IMMEDIATE;SQL> STARTUP;
(7)对新的主用数据库做全备份.