概况:Os,下面我们就来聊聊关于oracle的ogg和dg服务?接下来我们就一起去了解一下吧!

oracle的ogg和dg服务(ORACLEDG主备切换最佳实践)

oracle的ogg和dg服务

概况:

Os

db

db_name

db_name

role

Rhel 6.10

Oracle 11G

rac

Demo

PRIMARY

Rhel 6.10

Oracle 11G

单实例

adgdemo

STANDBY

一、切换前状态检查

1、查看两边归档是否对得上

主库:

SQL> select max(SEQUENCE#) from v$archived_log where applied='YES'; MAX(SEQUENCE#) -------------- 63

备库:

SQL> select max(sequence#) from v$archived_log where applied='YES'; MAX(SEQUENCE#) -------------- 63

2、状态检查:

主库:

select switchover_status,open_mode,database_role from v$database; SWITCHOVER_STATUS OPEN_MODE DATABASE_ROLE -------------------- -------------------- ---------------- SESSION ACTIVE READ WRITE PRIMARY

备库:

SWITCHOVER_STATUS OPEN_MODE DATABASE_ROLE -------------------- -------------------- ---------------- NOT ALLOWED READ ONLY WITH APPLY PHYSI CAL STANDBY

二、切换DG

步骤:关闭:先主库,后备机

1.主库切换成备库,然后将原主库启动到物理库的状态

SQL> alter database commit to switchover to physical standby with session shutdown;

2.打开数据库nomount

SQL> startup nomount

3.更改主库为备库

SQL> alter database mount standby database;

4、单节点应用日志

SQL> alter database recover managed standby database disconnect from session;

5、将备库切换成主库

原主库已经关闭,注意原备库switchover_status已经切换为TO PRIMARY

SQL> select switchover_status,open_mode,database_role from v$database; SWITCHOVER_STATUS OPEN_MODE DATABASE_ROLE -------------------- -------------------- ---------------- TO PRIMARY READ ONLY WITH APPLY PHYSICAL STANDBY

6、切换转换standby 到primary 角色

SQL> alter database commit to switchover to primary;

7、完成转换,打开新的primary 数据库

SQL> alter database open;

三、原主库切换成备库

当前的备库是mount状态了,运行以下语句

1、取消日志的运用

SQL>alter database recover managed standby database cancel;

2、打开数据库

SQL> alter database open;

3、启用日志实时应用

alter database recover managed standby database using current logfile disconnect from session;

四、切换后的状态检查

1、切换后的新主库

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

2、切换后的新备库

SQL> select switchover_status,open_mode,database_role from v$database; SWITCHOVER_STATUS OPEN_MODE DATABASE_ROLE -------------------- -------------------- ---------------- NOT ALLOWED READ ONLY WITH APPLY PHYSICAL STANDBY

结束。

,