cd $ORACLE_BASE/oradata #创建强制日志路径 mkdir standbylog
alter database add standby logfile group 11 '/u01/oracle/app/oradata/standbylog/standby11.log' size 50m;
alter database add standby logfile group 12 '/u01/oracle/app/oradata/standbylog/standby12.log' size 50m;
alter database add standby logfile group 13 '/u01/oracle/app/oradata/standbylog/standby13.log' size 50m;
alter database add standby logfile group 14 '/u01/oracle/app/oradata/standbylog/standby14.log' size 50m;
#查看standby日志组 SQL> select group#,sequence#,status,bytes/1024/1024 from v$standby_log; SQL> select group#,status,type,member from v$logfile;
GROUP# STATUS TYPE ---------- ------- ------- MEMBER -------------------------------------------------------------------------------- 1 ONLINE /u01/oracle/app/oradata/orcl/redo01.log
用spfile创建一个pfile,用于修改 SQL> create pfile from spfile;
SQL> show parameter spfile;
NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string /u01/oracle/app/oracle/product /11.2.0/dbhome_1/dbs/spfileorc l.ora
NAME TYPE VALUE ------------------------------------ ----------- ------------------------------ spfile string /u01/oracle/app/oracle/product /11.2.0/dbhome_1/dbs/spfileorc l.ora
SQL> select name,log_mode,force_logging from v$database;
NAME LOG_MODE FOR --------- ------------ --- ORCL ARCHIVELOG YES
Recovery Manager: Release 11.2.0.4.0 - Production on Wed Jul 6 17:32:26 2022
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: ORCL (DBID=1637071856) connected to auxiliary database: STD (not mounted)
RMAN> duplicate target database for standby from active database nofilenamecheck; RMAN> exit
------------------------------
SQL> sqlplus / as sysdba SQL> alter database recover managed standby database disconnect from session; SQL> select sequence#,applied from v$archived_log order by 1;
----------------------- ##如果发现不能同步,在备库端进行以下操作: SQL> alter database recover managed standby database cancel; SQL> shu immediate; SQL> startup nomount; SQL> alter database mount standby database; SQL> alter database open read only; SQL> alter database recover managed standby database using current logfile disconnect from session; ------------------------
#主库操作 #启动broken SQL> alter system set dg_broker_start=true; System altered.
#开启闪回
SQL> alter database flashback on; System altered.
SQL> select open_mode,database_role,log_mode,flashback_on from v$database;
DGMGRL> switchover to 'std' Performing switchover NOW, please wait... Operation requires a connection to instance "std" on database "std" Connecting to instance "std"... Connected. New primary database "std" is opening... Operation requires startup of instance "orcl" on database "orcl" Starting instance "orcl"... ORACLE instance started. Database mounted. Database opened. Switchover succeeded, new primary is "std"
------------------------------
DGMGRL> switchover to 'orcl' Performing switchover NOW, please wait... Operation requires a connection to instance "orcl" on database "orcl" Connecting to instance "orcl"... Connected. New primary database "orcl" is opening... Operation requires startup of instance "std" on database "std" Starting instance "std"... ORACLE instance started. Database mounted. Database opened. Switchover succeeded, new primary is "orcl"
create or replace procedure cmc_taf_service_proc is v_role VARCHAR(30); begin select DATABASE_ROLE into v_role from V$DATABASE; if v_role = 'PRIMARY' then DBMS_SERVICE.START_SERVICE('HAHA'); else DBMS_SERVICE.STOP_SERVICE('HAHA'); end if; end;
create or replace TRIGGER cmc_taf_service_trg_startup after startup on database begin cmc_taf_service_proc; end;
create or replace TRIGGER cmc_taf_service_trg_rolechange after db_role_change on database begin cmc_taf_service_proc; end;
SQL> exec cmc_taf_service_proc; SQL> alter system archive log current;
遇到的问题(ORA-16829: fast-start failover configuration is lagging)
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
4.过一段时间再检查备库状态,发现恢复正常
DGMGRL> show database orcl
Database - orcl
Role: PHYSICAL STANDBY Intended State: APPLY-ON Transport Lag: 0 seconds (computed 1 second ago) Apply Lag: 0 seconds (computed 1 second ago) Apply Rate: 0 Byte/s Real Time Query: ON Instance(s): orcl 但是接着又出现apply lag
DGMGRL> show database orcl
Database - orcl
Role: PHYSICAL STANDBY Intended State: APPLY-ON Transport Lag: 0 seconds (computed 0 seconds ago) Apply Lag: 2 minutes 37 seconds (computed 0 seconds ago) Apply Rate: 0 Byte/s Real Time Query: ON Instance(s): orcl
5.将DelayMins设置0
DGMGRL> edit database orcl set property DelayMins=0; Property "delaymins" updated
DGMGRL> edit database std set property DelayMins=0; Property "delaymins" updated
继续不断检查dg的状态
DGMGRL> show database orcl
Database - orcl
Role: PHYSICAL STANDBY Intended State: APPLY-ON Transport Lag: 0 seconds (computed 0 seconds ago) Apply Lag: 0 seconds (computed 0 seconds ago) Apply Rate: 0 Byte/s Real Time Query: ON Instance(s): orcl
Database Status: SUCCESS
6.重新开启fast_start failover
DGMGRL> enable fast_start failover Enabled.
DGMGRL> show configuration
Configuration - orcl
Protection Mode: MaxPerformance Databases: orcl - Primary database Warning: ORA-16819: fast-start failover observer not started
dg - (*) Physical standby database Warning: ORA-16819: fast-start failover observer not started
Fast-Start Failover: ENABLED
Configuration Status: WARNING
这时发现ORA-16829错误已经消失
6.备库执行取消同步语句,全部使用DGMGRL工具管理
SQL> alter database recover managed standby database cancel;
Database altered.
取消后发现错误再次出现
DGMGRL> show database dg;
Database - dg
Role: PHYSICAL STANDBY Intended State: APPLY-ON Transport Lag: 0 seconds (computed 0 seconds ago) Apply Lag: 0 seconds (computed 0 seconds ago) Apply Rate: (unknown) Real Time Query: OFF Instance(s): dg
Database Error(s): ORA-16766: Redo Apply is stopped
Database Warning(s): ORA-16829: fast-start failover configuration is lagging ORA-16819: fast-start failover observer not started
Database Status: ERROR
7.对备库使用DGMGRL重启APLLY
DGMGRL> edit database orcl set state="APPLY-OFF"; Succeeded. DGMGRL> edit database orcl set state="APPLY-ON"; Succeeded.
最后发现一切正常
DGMGRL> show database orcl;
Database - orcl
Role: PHYSICAL STANDBY Intended State: APPLY-ON Transport Lag: 0 seconds (computed 1 second ago) Apply Lag: 0 seconds (computed 1 second ago) Apply Rate: 0 Byte/s Real Time Query: ON Instance(s): orcl
Database Warning(s): ORA-16819: fast-start failover observer not started