温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何实现Oracle Data Guard主库备库角色切换

发布时间:2021-11-05 11:01:02 来源:亿速云 阅读:92 作者:柒染 栏目:建站服务器

如何实现Oracle Data Guard主库备库角色切换,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

步骤1:验证主库能否进行角色切换,TO STANDBY表示可以进行

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;

SWITCHOVER_STATUS 

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

TO STANDBY 

1 row selected

The TO STANDBY value in the SWITCHOVER_STATUS column indicates that it is 

possible to switch the primary database to the standby role. If the TO STANDBY value

is not displayed, then verify the Data Guard configuration is functioning correctly (fo

example, verify all LOG_ARCHIVE_DEST_n parameter values are specified correctly).

If the value in the SWITCHOVER_STATUS column is SESSIONS ACTIVE, perform. the

steps described in SectionA.4, "Problems Switching Over to a Standby Database" on 

pageA-4 to identify and terminate active user or SQL sessions that might prevent a 

switchover from being processed. If, after performing these steps, the SWITCHOVER_

STATUS column still displays SESSIONS ACTIVE, you can successfully perform. a 

switchover by appending the WITH SESSION SHUTDOWN clause to the ALTER 

DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY statement 

described in Step 2.

See Oracle Database Reference for information about other valid values for the 

SWITCHOVER_STATUS column of the V$DATABASE view.

步骤2:在主库上执行角色切换到从库角色

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY;

After this statement completes, the primary database is converted into a standby 

database. The current control file is backed up to the current SQL session trace file 

before the switchover. This makes it possible to reconstruct a current control file, if 

necessary.

步骤3:关闭并重新启动之前的主库实例

SQL> SHUTDOWN IMMEDIATE;

SQL> STARTUP MOUNT;

At this point in the switchover process, both databases are configured as standby 

databases.

步骤4:在备库的V$DATABASE视图中查看备库的切换状态

SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE; 

SWITCHOVER_STATUS 

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

TO_PRIMARY 

1 row selected

If the value in the SWITCHOVER_STATUS column is SESSIONS ACTIVE, perform. the 

steps described in SectionA.4, "Problems Switching Over to a Standby Database" on 

pageA-4 to identify and terminate active user or SQL sessions that might prevent a 

switchover from being processed. If, after performing these steps, the SWITCHOVER_

STATUS column still displays SESSIONS ACTIVE, you can proceed to Step 5, and 

append the WITH SESSION SHUTDOWN clause to the switchover statement. See Oracle 

Database Reference for information about other valid values for the SWITCHOVER_

STATUS column of the V$DATABASE view

步骤5:切换备库到主库角色

You can switch a physical standby database from the standby role to the primary role 

when the standby database instance is either mounted in Redo Apply mode or open 

for read-only access. It must be in one of these modes so that the primary database 

switchover request can be coordinated. After the standby database is in an appropriate 

mode, issue the following SQL statement on the physical standby database that you 

want to change to the primary role:

SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;

步骤6:完成备库到主库的切换

1. 如果备库没有以只读模式打开,直接执行以下语句打开到新的主库。

SQL> ALTER DATABASE OPEN;

2. 如果备库以只读模式打开,先关闭数据,然后再重新启动。

SQL> SHUTDOWN IMMEDIATE;

SQL> STARTUP;

步骤7:如果有必要,重新启动一下新的备库上的重做日志应用服务

For the new physical standby database and for each other physical or logical standby 

database in the Data Guard configuration, if log apply services were not previously 

configured to continue operating through a switchover, use an appropriate command 

to restart log apply services. See Chapter6, "Log Apply Services" for more information 

about how to configure and start log apply services.

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

(注:可以通过select message from v$dataguard_status;查看当前备库应用重做日志的状态)

步骤8:开始发送重做数据到备库上

Issue the following statement on the new primary database: 

SQL> ALTER SYSTEM SWITCH LOGFILE;

NOT ALLOWED

当前的数据库不是带有备用数据库的主数据库

PREPARING DICTIONARY

该逻辑备用数据库正在向一个主数据库和其他备用数据库发送它的重做数据,以便为切换做准备

PREPARING SWITCHOVER

接受用于切换的重做数据时,逻辑备用配置会使用它

RECOVERY NEEDED

备用数据库还没有接收到切换请求

SESSIONS ACTIVE

在主数据库中存在活动的SQL会话;在继续执行之前必须断开这些会话

SWITCHOVER PENDING

适用于那些已收到主数据库切换请求但是还没有处理该请求的备用数据库

SWITCHOVER LATENT

切换没有完成并返回到主数据库

TO LOGICAL STANDBY

主数据库已经收到了来自逻辑备用数据库的完整的字典

TO PRIMARY

该备用数据库可以转换为主数据库

TO STANDBY

该主数据库可以转换为备用数据库

v$database Switchover_Status值的含义

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI