DataGuard单实例部署

DataGuard单实例部署

配置说明:

在主库上安装数据库软件,并建监听和实例,在备库上安装数据库软件,并建监听,但不建实例。

配置清单:

主机1(主库) 主机2(备库)
操作系统 Red Hat Linux 7.0 Red Hat Linux 7.0
主机名 dg1 dg2
IP 192.168.1.141 192.168.1.141
数据库软件版本 oracle 11.2.0.4 oracle 11.2.0.4
ORACLE_BASE /u01/app/oracle /u01/app/oracle
ORACLE_HOME /u01/app/oracle/product/11.2.0/db_1 /u01/app/oracle/product/11.2.0/db_1
ORACLE_SID dg1
存储系统 文件系统(FileSystem) 文件系统(FileSystem)
归档 开启

部署流程:

1.主库上创建和修改所需文件
2.主库全备并将备份集拷贝到备库相同目录下
3.备库创建和修改所需文件
4.备库恢复主库的备份集

1.主库配置

1.1创建所需目录

mkdir -p /oracle/archive
mkdir -p /oracle/datafile/dg1
mkdir -p /oracle/backup
chown -R oracle:oinstall /oracle

1.2打开强制日志

alter database force logging;
show parameter recover;
alter system set db_recovery_file_dest_size=2g;
alter system set db_recovery_file_dest='/oracle/archive';

1.3打开归档

shutdown immediate;
startup mount;
alter database archivelog;
alter database open;

检查日志是否成功切换:

SQL> archive log list;
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     17
Next log sequence to archive   19
Current log sequence	       19

SQL> alter system switch logfile;
System altered.

SQL> archive log list;
Database log mode	       Archive Mode
Automatic archival	       Enabled
Archive destination	       USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence     18
Next log sequence to archive   20
Current log sequence	       20

1.4添加STANDBY 日志文件

建议比在线重做日志文件多1组
#查看日志文件大小
select GROUP#,THREAD#,SEQUENCE#,BYTES,MEMBERS from v$log;   
    GROUP#    THREAD#  SEQUENCE#      BYTES    MEMBERS
---------- ---------- ---------- ---------- ----------
	 1	    1	       1   52428800	     1
	 2	    1	       2   52428800	     1
	 3	    1	       0   52428800	     1

#查看日志文件路劲
SQL> set line format 200
SQL> col MEMBER format a50
SQL> select * from v$logfile;   
    GROUP# STATUS  TYPE    MEMBER					      IS_
---------- ------- ------- -------------------------------------------------- ---
	 3	   ONLINE  /u01/app/oracle/oradata/dg1/redo03.log	      NO
	 2	   ONLINE  /u01/app/oracle/oradata/dg1/redo02.log	      NO
	 1	   ONLINE  /u01/app/oracle/oradata/dg1/redo01.log	      NO


alter system set standby_file_management=manual;
alter database add standby logfile group 6  '/u01/app/oracle/oradata/dg1/stredo06.log' size 104857600;
alter database add standby logfile group 7  '/u01/app/oracle/oradata/dg1/stredo07.log' size 104857600;
alter database add standby logfile group 8  '/u01/app/oracle/oradata/dg1/stredo08.log' size 104857600;
alter database add standby logfile group 9  '/u01/app/oracle/oradata/dg1/stredo09.log' size 104857600;
alter database add standby logfile group 10  '/u01/app/oracle/oradata/dg1/stredo10.log' size 104857600;
alter database add standby logfile group 11  '/u01/app/oracle/oradata/dg1/stredo11.log' size 104857600;
alter system set standby_file_management=auto;


#检查
    GROUP# STATUS  TYPE    MEMBER					      IS_
---------- ------- ------- -------------------------------------------------- ---
	 3	   ONLINE  /u01/app/oracle/oradata/dg1/redo03.log	      NO
	 2	   ONLINE  /u01/app/oracle/oradata/dg1/redo02.log	      NO
	 1	   ONLINE  /u01/app/oracle/oradata/dg1/redo01.log	      NO
	 6	   STANDBY /u01/app/oracle/oradata/dg1/stredo06.log	      NO
	 7	   STANDBY /u01/app/oracle/oradata/dg1/stredo07.log	      NO
	 8	   STANDBY /u01/app/oracle/oradata/dg1/stredo08.log	      NO
	 9	   STANDBY /u01/app/oracle/oradata/dg1/stredo09.log	      NO
	10	   STANDBY /u01/app/oracle/oradata/dg1/stredo10.log	      NO
	11	   STANDBY /u01/app/oracle/oradata/dg1/stredo11.log	      NO

1.5主库参数文件配置

创建pfile

create pfile='/oracle/backup/pfile.ora' from spfile;

修改pfile

#打开pfile文件,在后面添加:
db_unique_name='dg1'
LOG_ARCHIVE_CONFIG='DG_CONFIG=(dg1,dg2)'
LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg1'
LOG_ARCHIVE_DEST_2='SERVICE=dg2 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dg2'
log_archive_format='%t_%s_%r.arc'
fal_client='dg1'
FAL_SERVER='dg2'
DB_FILE_NAME_CONVERT='/oracle/datafile/dg2','/u01/app/oracle/oradata/dg1'
LOG_FILE_NAME_CONVERT='/oracle/datafile/dg2','/u01/app/oracle/oradata/dg1'
standby_file_management=AUTO

以pfile启动主库

shutdown immediate;
startup nomount pfile='/oracle/backup/pfile.ora';
alter database mount;
alter database open;
create spfile from pfile='/oracle/backup/pfile.ora';

1.6配置静态监听

[oracle@dg1 ~]$ cd $ORACLE_HOME/network/admin 
[oracle@dg1 admin]$ vi listener.ora 
SID_LIST_LISTENER=
  (SID_LIST=
      (SID_DESC=
         (GLOBAL_DBNAME=dg1)
         (SID_NAME=dg1)
         (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
       )
   )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg1)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

1.7TNS配置别名解析

[oracle@dg1 admin]$ vi tnsnames.ora 
dg1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.21)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = dg1)
    )
  )

dg2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.22)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = dg2)
    )
  )

检测是否配置成功

#重启监听
[oracle@dg1 admin]$ lsnrctl stop
[oracle@dg1 admin]$ lsnrctl start
[oracle@dg1 admin]$ tnsping dg1 4
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 17-JUN-2021 13:22:24
Copyright (c) 1997, 2013, Oracle.  All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.21)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = dg1)))
OK (0 msec)
OK (10 msec)
OK (0 msec)
OK (0 msec)

[oracle@dg1 admin]$ sqlplus sys/oracle@dg1 as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Thu Jun 17 13:27:14 2021
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> 
#配置完成

1.8备份全库

rman target /
backup full database format='/oracle/backup/full_%u_%s_%p';
#将备份集拷贝到备库相同目录下
scp full* oracle@192.168.100.22:/oracle/backup/

2.备库配置

2.1创建所需目录

创建/oracle,用于存放下面配置的一些文件:

mkdir -p /u01/app/oracle/admin/dg2/adump
mkdir -p /oracle/archive
mkdir -p /oracle/controlfile/dg2
mkdir -p /oracle/datafile/dg2
mkdir -p /oracle/backup
chown -R oracle:oinstall /oracle

2.2修改参数文件

在主库上拷贝到备库

[oracle@dg1 ~]$ scp /oracle/backup/pfile.ora oracle@192.168.100.22:/oracle/backup/

修改以下参数文件

*.audit_file_dest='/u01/app/oracle/admin/dg2/adump'
*.control_files='/oracle/controlfile/dg2/control01.ctl','/oracle/backup/control02.ctl'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=dg2XDB)'
db_unique_name='dg2'
LOG_ARCHIVE_CONFIG='DG_CONFIG=(dg2,dg1)'
LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=dg2'
LOG_ARCHIVE_DEST_2='SERVICE=dg1 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=dg1'
log_archive_format='%t_%s_%r.arc'
fal_client='dg2'
FAL_SERVER='dg1'
DB_FILE_NAME_CONVERT='/u01/app/oracle/oradata/dg1','/oracle/datafile/dg2'
LOG_FILE_NAME_CONVERT='/u01/app/oracle/oradata/dg1','/oracle/datafile/dg2'
standby_file_management=AUTO

修改说明:

db_unique_name='备库'
LOG_ARCHIVE_CONFIG='DG_CONFIG=(备库,主库)'   --自己是发送端
LOG_ARCHIVE_DEST_1='LOCATION=USE_DB_RECOVERY_FILE_DEST VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=备库'
LOG_ARCHIVE_DEST_2='SERVICE=主库 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=主库'
log_archive_format='%t_%s_%r.arc'   --生成日志文件命名的格式
fal_client='备库'   --自己是客户端
FAL_SERVER='主库'   --别人是服务端
DB_FILE_NAME_CONVERT='备库路径','主库路径'   --数据文件名字转换(备库在前,主库在后)
LOG_FILE_NAME_CONVERT='备库路径','主库路径'   --日志文件名字转换(备库在前,主库在后)
standby_file_management=AUTO

--在LOG_ARCHIVE_DEST_N参数上使用“DELAY=”,比如:DELAY=360(单位为分钟),表示延时360分钟(6h)
--如果指定了DELAY参数,但是没有指定具体的值,默认是30分钟,需要LGWR SYNC日志传输模式才能生效
--需要注意的是,如果已经启用了实时日志应用(real-time apply),DELAY这个参数会被忽略
--alter system set LOG_ARCHIVE_DEST_2='SERVICE=hsdb LGWR SYNC DELAY=10 VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=hsdb'

2.3生成密钥文件

[oracle@dg2 backup]$ orapwd FILE=/oracle/backup/orapwdg2 password=oracle;

或者是从主库拷贝到备库

scp $ORACLE_HOME/dbs/orapwdg1 oracle@192.168.100.22:$ORACLE_HOME/dbs/orapwdg2

2.4配置静态监听

[oracle@dg2 admin]$ vi listener.ora 
SID_LIST_LISTENER=
  (SID_LIST=
      (SID_DESC=
         (GLOBAL_DBNAME=dg2)
         (SID_NAME=dg2)      
         (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
       )
   )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = dg2)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

ADR_BASE_LISTENER = /u01/app/oracle

2.5TNS配置别名解析

[oracle@dg2 admin]$ vi tnsnames.ora 
dg1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.21)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = dg1)
    )
  )

dg2 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.22)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = dg2)
    )
  )

检测是否配置成功

[oracle@dg2 admin]$ lsnrctl start
[oracle@dg2 admin]$ tnsping dg2 4
TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 18-JUN-2021 09:28:24
Copyright (c) 1997, 2013, Oracle.  All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.100.22)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = dg2)))
OK (0 msec)
OK (0 msec)
OK (0 msec)
OK (0 msec)

[oracle@dg2 admin]$ sqlplus sys/oracle@dg1 as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Fri Jun 18 09:32:19 2021
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL> 
#配置完成

2.6备库启动到nomount

#修改将pfile文件拷贝到
[oracle@dg2 backup]$ cp /oracle/backup/pfile.ora $ORACLE_HOME/dbs
[oracle@dg2 backup]$ cd $ORACLE_HOME/dbs
[oracle@dg2 dbs]$ mv pfile.ora initdg2.ora

#启动到nomount
[oracle@dg2 dbs]$ sqlplus / as sysdba
SQL> startup nomount pfile='/u01/app/oracle/product/11.2.0/db_1/dbs/initdg2.ora';

2.7备份恢复主库数据

方法一:在主库全备将备份scp到备库,在恢复(本文例子)

方法二:在主库全备到NAS盘,在将NAS盘挂到备库

恢复前提:

1.主备库tns能ping通
2.主库开启到open,备库开启到nomount

开始恢复

#连接dg1辅助dg2恢复
[oracle@dg2 dg2]$ rman target sys/oracle@dg1  auxiliary sys/oracle@dg2
RMAN> duplicate target database for standby;


Starting Duplicate Db at 19-JUN-21
using target database control file instead of recovery catalog
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=20 device type=DISK
contents of Memory Script:
{
   restore clone standby controlfile;
}
executing Memory Script
Starting restore at 19-JUN-21
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /oracle/backup/full_0201pu6l_2_1
channel ORA_AUX_DISK_1: piece handle=/oracle/backup/full_0201pu6l_2_1 tag=TAG20210619T130158
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/oracle/controlfile/dg2/control01.ctl
output file name=/oracle/backup/control02.ctl
Finished restore at 19-JUN-21
contents of Memory Script:
{
   sql clone 'alter database mount standby database';
}
executing Memory Script
sql statement: alter database mount standby database
contents of Memory Script:
{
   set newname for tempfile  1 to 
 "/oracle/datafile/dg2/temp01.dbf";
   switch clone tempfile all;
   set newname for datafile  1 to 
 "/oracle/datafile/dg2/system01.dbf";
   set newname for datafile  2 to 
 "/oracle/datafile/dg2/sysaux01.dbf";
   set newname for datafile  3 to 
 "/oracle/datafile/dg2/undotbs01.dbf";
   set newname for datafile  4 to 
 "/oracle/datafile/dg2/users01.dbf";
   restore
   clone database
   ;
}
executing Memory Script
executing command: SET NEWNAME
renamed tempfile 1 to /oracle/datafile/dg2/temp01.dbf in control file
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
Starting restore at 19-JUN-21
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /oracle/datafile/dg2/system01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /oracle/datafile/dg2/sysaux01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /oracle/datafile/dg2/undotbs01.dbf
channel ORA_AUX_DISK_1: restoring datafile 00004 to /oracle/datafile/dg2/users01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /oracle/backup/full_0101pu66_1_1
channel ORA_AUX_DISK_1: piece handle=/oracle/backup/full_0101pu66_1_1 tag=TAG20210619T130158
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:15
Finished restore at 19-JUN-21
contents of Memory Script:
{
   switch clone datafile all;
}
executing Memory Script
datafile 1 switched to datafile copy
input datafile copy RECID=1 STAMP=1075643495 file name=/oracle/datafile/dg2/system01.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=2 STAMP=1075643495 file name=/oracle/datafile/dg2/sysaux01.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=3 STAMP=1075643495 file name=/oracle/datafile/dg2/undotbs01.dbf
datafile 4 switched to datafile copy
input datafile copy RECID=4 STAMP=1075643495 file name=/oracle/datafile/dg2/users01.dbf
Finished Duplicate Db at 19-JUN-21

2.8开启实时同步

[oracle@dg2 dg2]$ sqlplus / as sysdba
SQL> alter database recover managed standby database using current logfile disconnect from session;

取消同步使用下面的语句:

alter database recover managed standby database cancel;

3.验证同步

至此DG搭建完成,开始验证是否能够实现实时同步

3.1查看是否有报错

通过查看archive_log_dest_2列是否有error报错,如果有报错,则需要先根据报错内容解决问题
SQL>col dest_name format a30
SQL>col error format a20
SQL>select dest_name,error from v$archive_dest;
DEST_NAME		       ERROR
------------------------------ --------------------
LOG_ARCHIVE_DEST_1
LOG_ARCHIVE_DEST_2
LOG_ARCHIVE_DEST_3
LOG_ARCHIVE_DEST_4
LOG_ARCHIVE_DEST_5
LOG_ARCHIVE_DEST_6
LOG_ARCHIVE_DEST_7
LOG_ARCHIVE_DEST_8
LOG_ARCHIVE_DEST_9
LOG_ARCHIVE_DEST_10
LOG_ARCHIVE_DEST_11

DEST_NAME		       ERROR
------------------------------ --------------------
LOG_ARCHIVE_DEST_12
LOG_ARCHIVE_DEST_13
LOG_ARCHIVE_DEST_14
LOG_ARCHIVE_DEST_15
LOG_ARCHIVE_DEST_16
LOG_ARCHIVE_DEST_17
LOG_ARCHIVE_DEST_18
LOG_ARCHIVE_DEST_19
LOG_ARCHIVE_DEST_20
LOG_ARCHIVE_DEST_21
LOG_ARCHIVE_DEST_22

DEST_NAME		       ERROR
------------------------------ --------------------
LOG_ARCHIVE_DEST_23
LOG_ARCHIVE_DEST_24
LOG_ARCHIVE_DEST_25
LOG_ARCHIVE_DEST_26
LOG_ARCHIVE_DEST_27
LOG_ARCHIVE_DEST_28
LOG_ARCHIVE_DEST_29
LOG_ARCHIVE_DEST_30
LOG_ARCHIVE_DEST_31
STANDBY_ARCHIVE_DEST

32 rows selected.
#注意:上面显示是否报错

3.2查询主备库归档序号

主库上执行

SQL>select max(sequence#) from v$archived_log;
 MAX(SEQUENCE#)
--------------
	     9

备库上执行

SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
	     9

主库上执行日志切换

SQL> alter system archive log current;
System altered.
SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
	    10

备库上再次验证

SQL> select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
	    10

3.3查看主备库状态

主库上执行

SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- ----------------
SESSIONS ACTIVE      PRIMARY

备库上执行

SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- ----------------
NOT ALLOWED	     PHYSICAL STANDBY

创建一张dg表测试

主库上执行

SQL>create table dg(id number);
Tablecreated.
SQL>insert into dg values(1);
1row created.
SQL>commit;
Commitcomplete.
SQL>select * from dg;
	ID
----------
	 1

备库上执行

SQL> select * from dg;
	ID
----------
	 1

以上说明DG实时同步

4.切换与恢复

我们配置DG的目的就是为了在主库出现故障时,备库能够提供服务,保证业务的正常运行。DG的故障切换分为switchover和failover两种

4.1 DG正常切换

DG切换:需要使用switchover,switchover是用户有计划的正常停机切换,能够保证不丢失数据

主库上操作:

SQL> select switchover_status,database_role from v$database; 
SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- ----------------
SESSIONS ACTIVE      PRIMARY
#上面查询结果为TO STANDBY 或 SESSIONS ACTIVE表明可以进行切换

SQL> alter database commit to switchover to physical standby;
Database altered.


SQL> startup mount
Database mounted.

SQL>  select database_role from v$database;
DATABASE_ROLE
----------------
PHYSICAL STANDBY

备库上操作:

SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS    DATABASE_ROLE
-------------------- ----------------
SESSIONS ACTIVE      PHYSICAL STANDBY
#上面查询结果显示为TO PRIMARY 或 SESSIONS ACTIVE表明可以切换成主库;

SQL>  alter database commit to switchover to primary with session shutdown;
Database altered.

SQL> alter database open;
Database altered.

SQL> select switchover_status,database_role,open_mode from v$database;
SWITCHOVER_STATUS    DATABASE_ROLE    OPEN_MODE
-------------------- ---------------- --------------------
RESOLVABLE GAP	     PRIMARY	      READ WRITE

主库上操作:

SQL> alter database open;
Database altered.

SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
#到此DG switover切换完成,验证方法同上。

4.2DG故障转移

DG故障转移:failover是当主库真正出现严重系统故障,如数据库宕机,软硬件故障导致主库不能支持服务,从而进行的切换动作。

模拟故障

主库上操作:

SQL> shu abort
ORACLE instance shut down.

备库上操作:

SQL> alter database recover managed standby database cancel;
Database altered.

SQL> alter database recover managed standby database finish force;
Database altered.

SQL> select database_role from v$database;
DATABASE_ROLE
----------------
PHYSICAL STANDBY

SQL> alter database commit to switchover to primary;
Database altered.

SQL> alter database open;
Database altered.

SQL> select switchover_status,database_role,open_mode from v$database;
SWITCHOVER_STATUS    DATABASE_ROLE    OPEN_MODE
-------------------- ---------------- --------------------
RESOLVABLE GAP	     PRIMARY	      READ WRITE
#至此failover操作完成,原来的备库已经切换为主库,可以给业务提供服务了。

4.3原主库恢复

通过备份恢复一些数据,在做一次DG

5.监控DG相关视图

select * from v$dataguard_stats where name='apply lag';

DataGuard单实例部署

select * from v$managed_standby;

DataGuard单实例部署

上一篇:dataguard删除掉从库


下一篇:dataguard 备库删除已应用过的过期归档