oracle dg主备切换 更换ip,【DG】主备切换

本文详细介绍了Oracle数据库的主备切换过程,包括主库切换到备库(主切备)和备库切换到主库(备切主),以及后续的反切操作。在主切备中,通过`ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY`命令关闭主库并转换角色。在备切主时,需先应用日志并使用相同命令切换角色。反切过程中,确保日志正确应用和数据库状态的调整是关键步骤。
摘要由CSDN通过智能技术生成

一: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

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值