我是靠谱客的博主 懵懂镜子,最近开发中收集的这篇文章主要介绍oracle dg主备切换 更换ip,【DG】主备切换,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

一:DG之主备切换(主切备、备切主)

1)主切备:

SYS@ORA11GR2>select

database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PRIMARYSESSIONS ACTIVE

SYS@ORA11GR2>alter databasecommit toswitchover tophysical

standbywith session shutdown;(主切备,后台进程关掉了数据库)

ERROR:

ORA-01034: ORACLE not available

Process ID: 17761

Session ID: 106 Serial number: 1421

Database altered.

SYS@ORA11GR2>conn / as sysdba

Connected to an idle instance.

SYS@ORA11GR2>startup mount;

ORACLE instance started.

Total System Global Area830930944 bytes

Fixed Size2257800 bytes

Variable Size503319672 bytes

Database Buffers322961408 bytes

Redo Buffers2392064 bytes

Database mounted.

SYS@ORA11GR2>select

database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PHYSICAL STANDBYRECOVERY NEEDED

——需应用日志:

SYS@ORA11GR2>recover managed standby database using current logfile disconnect from

session;

Media recovery complete.

此时转换后的备库一直在应用日志,如果需要再次转换为主库需结束应用日志:

SYS@ORA11GR2>select database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PHYSICAL STANDBYTO PRIMARY

2)备切主:

[oracle@bing ~]$ export ORACLE_SID=OCMU

[oracle@bing ~]$ echo $ORACLE_SID

OCMU

[oracle@bing ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on

Thu Oct 20 13:25:13 2016

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>select

database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PHYSICAL STANDBYNOT

ALLOWED (没有主库,状态显示不正常,正常应为to primary)

——切换一下

SQL>alter databasecommit toswitchover to primarywithsession shutdown;

alter database commit to switchover to

primary with session shutdown

*

ERROR at line 1:

ORA-16139: media recovery required

——根据提示,应用日志:

SQL>recover managed standby database using current logfile disconnect from session;

Media recovery complete.

再次查看状态:

SQL>select database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PHYSICAL STANDBYTO PRIMARY(正常了)

(因为有主库,则状态为not allowed;如果没有主库,则状态都为to primary)

——备切主操作:

SQL>alter databasecommit

toswitchover to primarywithsession shutdown;

(备切主后,后台进程直接关库,再将库启动到mount下)

Database altered.

SQL>select database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PRIMARYNOT

ALLOWED(备切主后数据库状态为mount)

——启库:

SQL>alter database open;

Database altered.

SQL>select database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PRIMARYRESOLVABLE GAP

——转换后的备库正在应用日志,过会再看一下转换后的主库状态:

SQL>select database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PRIMARYTO STANDBY(正常)

——过会再看一下转换后的主库状态:

SQL>select database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PRIMARYSESSIONS ACTIVE(正常)

二:反切(即将切换后的备库切换回主库,切换后的主库切换回备库)

1).主切备操作:

SQL>select database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PRIMARYSESSIONS ACTIVE

SQL>alter database commit to switchover

tophysical standbywith session shutdown;

Database altered.(主切备,后台进程关掉了数据库)

SQL> select open_mode from v$database;

select open_mode from v$database

*

ERROR at line 1:

ORA-01034: ORACLE not available

Process ID: 8010

Session ID: 1 Serial number: 7

SQL> conn / as sysdba

Connected to an idle instance.

SQL>startup mount;

ORACLE instance started.

Total System Global Area830930944 bytes

Fixed Size2257800 bytes

Variable Size675286136 bytes

Database Buffers150994944 bytes

Redo Buffers2392064 bytes

Database mounted.

SQL>

SQL> select

database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PHYSICAL STANDBYRECOVERY NEEDED

SQL>recover managed standby database using current logfile

disconnect from session;

Media recovery complete.

SQL> select

database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PHYSICAL STANDBYTO PRIMARY

SQL>recover managed standby database

cancel;

Media recovery complete.

SQL>

2).备切主操作:

SYS@ORA11GR2>select

database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PHYSICAL

STANDBYTO PRIMARY

SYS@ORA11GR2>alter databasecommit to switchover to primary with session shutdown;

Database altered.(备切主后,后台进程直接关库,再将库启动到mount下)

SYS@ORA11GR2>alter database open;

Database altered.

SYS@ORA11GR2>select database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PRIMARYSESSIONS ACTIVE

3).再次查看下切换后的备库状态:

SQL> select

database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PHYSICAL STANDBYRECOVERY NEEDED

SQL>recover managed standby database using current

logfile disconnect from session;

Media recovery complete.

SQL>

SQL>select database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PHYSICAL STANDBY NOT ALLOWED

SQL>recover managed standby

database cancel;

Media recovery complete.

SQL>select database_role,switchover_status from v$database;

DATABASE_ROLESWITCHOVER_STATUS

---------------- --------------------

PHYSICAL

STANDBYNOT ALLOWED

完成!!!!!!!!!!!!!!!!!!

最后

以上就是懵懂镜子为你收集整理的oracle dg主备切换 更换ip,【DG】主备切换的全部内容,希望文章能够帮你解决oracle dg主备切换 更换ip,【DG】主备切换所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(35)

评论列表共有 0 条评论

立即
投稿
返回
顶部