Oracle数据库切换DG操作步骤整理
**oracle数据库切换DG步骤**
备注:应用服务要先停止对外服务
1.先将主库切换成备库,然后将原主库启动到物理库的状态
```
SQL> Alter database commit to switchover to physical standby with session shutdown;
```
2.关闭主库
```
SQL> shutdown immediate;
```
3.打开数据库nomount
```
SQL> startup nomount;
```
4.更改主库为备库
```
SQL> alter database mount standby database;
SQL> alter database recover managed standby database disconnect from session;
```
如果配置了 standby redo log 并需要启用实时同步则执行以下代码
```
SQL>alter database recover managed standby database using current logfile disconnect from session;
```
5.将备库切换成主库
```
SQL> select switchover_status from v$database;
SQL> select * from v$version where rownum<2;
SQL> alter database commit to switchover to primary with session shutdown;
```
如果备库还有未应用的日志则执行
```
SQL>alter database recover managed standby database disconnect from session;
SQL> shutdown immediate;
SQL> startup;
```
切换日志进行检查
```
SQL> select max(sequence#) from v$log;
SQL>select sequence#,applied from v$archived_log;
SQL> alter system switch logfile;
```