dg之主备切换
Posted xixi艾
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了dg之主备切换相关的知识,希望对你有一定的参考价值。
主备切换前,一定要注意日志全都应用
主备切换报错,如何切换回去?
- 现备库(原主库)切回主库
QL> select database_role,switchover_status from v$database;
DATABASE_ROLE
SWITCHOVER_STATUS
PHYSICAL STANDBY
SESSIONS ACTIVE
SQL> alter database commit to switchover to primary with session shutdown;
Database altered.
SQL> select status from v$instance;
STATUS
MOUNTED
SQL> alter database open ;
Database altered.
SQL> select status from v$instance;
STATUS
OPEN
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE
SWITCHOVER_STATUS
PRIMARY
SESSIONS ACTIVE
- 备库
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
PHYSICAL STANDBY RECOVERY NEEDED
SQL> alter database recover managed standby database disconnect from session;
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
PHYSICAL STANDBY NOT ALLOWED
- 再次查看原主库
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
PRIMARY TO STANDBY
alter system set log_file_name_convert= ‘/u01/app/oracle/oradata/sw/’,’/u01/app/oracle/oradata/standby/’,’/u01/app/oracle/oradata/sw1/’,’/u01/app/oracle/oradata/standby/’ scope=pfile;
- 主库切换为备库。
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
PRIMARY SESSIONS ACTIVE
SQL> alter database commit to switchover to standby with session shutdown;
Database altered.
SQL> startup
ORACLE instance started.
Total System Global Area 1169149952 bytes
Fixed Size 2252624 bytes
Variable Size 318767280 bytes
Database Buffers 838860800 bytes
Redo Buffers 9269248 bytes
Database mounted.
Database opened.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE
SWITCHOVER_STATUS
PHYSICAL STANDBY
TO PRIMARY
- 备库切换为主库。
SQL> select database_role,switchover_status from v$database;(原始状态)
DATABASE_ROLE SWITCHOVER_STATUS
PHYSICAL STANDBY NOT ALLOWED
SQL> select database_role,switchover_status from v$database;(在主库切换备库后查询状态)
DATABASE_ROLE SWITCHOVER_STATUS
PHYSICAL STANDBY SESSIONS ACTIVE
SQL> alter database commit to switchover to primary;
alter database commit to switchover to primary
*
ERROR at line 1:
ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected
因为SESSIONS ACTIVE次状态,所以直接执行会报错,加上with session shutdown。
SQL> alter database commit to switchover to primary with session shutdown ;
Database altered.
SQL> select database_role,switchover_status from v$database; 此时处于mounted状态
DATABASE_ROLE SWITCHOVER_STATUS
PRIMARY NOT ALLOWED
SQL> alter database open;
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
PRIMARY RESOLVABLE GAP ,日志应用需要时间,多次查询即可变为TO STANDBY
SQL> /
DATABASE_ROLE SWITCHOVER_STATUS
PRIMARY TO STANDBY
- 新备库开启mrp进程(原主库)。
alter database recover managed standby database disconnect from session;
SQL> select process,status from v$managed_standby;
PROCESS STATUS
ARCH CONNECTED
ARCH CONNECTED
ARCH CONNECTED
ARCH CONNECTED
RFS IDLE
RFS IDLE
RFS IDLE
MRP0 WAIT_FOR_LOG
SQL> select sequence#,applied,archived from v$archived_log where rownum < 10;
SEQUENCE# APPLIED ARCHIVED
5 YES YES
6 YES YES
7 YES YES
8 YES YES
9 YES YES
9 YES YES
10 YES YES
10 YES YES
11 YES YES
- 再次切回 现主库(原备库)切回备库
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
PRIMARY TO STANDBY
SQL> alter database commit to switchover to standby ;
Database altered.
SQL> startup
ORACLE instance started.
Total System Global Area 1169149952 bytes
Fixed Size 2252624 bytes
Variable Size 318767280 bytes
Database Buffers 838860800 bytes
Redo Buffers 9269248 bytes
Database mounted.
Database opened.
QL>
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
PHYSICAL STANDBY TO PRIMARY
- 现备库(原主库)切回主库
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
PHYSICAL STANDBY TO PRIMARY
SQL> alter database commit to switchover to primary;
Database altered.
SQL> select status from v$instance;
STATUS
MOUNTED
SQL> alter database open;
Database altered.
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
PRIMARY RESOLVABLE GAP ,日志应用需要时间,多次查询即可变为TO STANDBY
SQL> /
DATABASE_ROLE SWITCHOVER_STATUS
PRIMARY TO STANDBY
6. 新备库开启mrp进程(原备库)。
alter database recover managed standby database disconnect from session;
SQL> select process,status from v$managed_standby;
PROCESS STATUS
ARCH CONNECTED
ARCH CONNECTED
ARCH CONNECTED
ARCH CONNECTED
RFS IDLE
RFS IDLE
RFS IDLE
MRP0 WAIT_FOR_LOG
SQL> select sequence#,applied,archived from v$archived_log where rownum < 10;
SEQUENCE# APPLIED ARCHIVED
5 YES YES
6 YES YES
7 YES YES
8 YES YES
9 YES YES
9 YES YES
10 YES YES
10 YES YES
11 YES YES
以上是关于dg之主备切换的主要内容,如果未能解决你的问题,请参考以下文章