共计 3253 个字符,预计需要花费 9 分钟才能阅读完成。
Oracle 11g DataGuard 主备切换
1. 检查主备的环境
dg1 节点:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/oradata/tong/archive
Oldest online log sequence 59
Next log sequence to archive 61
Current log sequence 61
SQL>
dg2 节点:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/oradata/tong/archive
Oldest online log sequence 60
Next log sequence to archive 0
Current log sequence 61
SQL>
2. 查看主备的角色
dg1 节点 (primary 角色):
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
——————– —————-
TO STANDBY PRIMARY
SQL>
dg2 节点 (standby 角色):
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
——————– —————-
NOT ALLOWED PHYSICAL STANDBY
SQL>
3. 在主库上执行切换命令 (primary 节点)
SQL> alter database commit to switchover to physical standby; – 将 primary 角色转换为 standby 角色
Database altered.
SQL> shutdown immediate – 关闭数据库, 启动到 mount 状态
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount
Total System Global Area 830930944 bytes
Fixed Size 2217912 bytes
Variable Size 545261640 bytes
Database Buffers 281018368 bytes
Redo Buffers 2433024 bytes
Database mounted.
SQL> select switchover_status,database_role from v$database; – 查看目前 primary 角色的状态
SWITCHOVER_STATUS DATABASE_ROLE
——————– —————-
TO PRIMARY PHYSICAL STANDBY
SQL>
4. 在备库上执行 (standby 节点)
SQL> select switchover_status,database_role from v$database; – 查看 standby 备库角色的状态
SWITCHOVER_STATUS DATABASE_ROLE
——————– —————-
TO PRIMARY PHYSICAL STANDBY
SQL> alter database commit to switchover to primary; – 将备库的角色修改为 primary
Database altered.
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
——————– —————-
NOT ALLOWED PRIMARY
SQL> alter database open; – 打开数据库
Database altered.
SQL>
5. 在备库上执行 (standby 节点)
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
——————– —————-
RECOVERY NEEDED PHYSICAL STANDBY
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION; – 修改以前主库为日志应用
Database altered.
SQL>
6. 测试主备节点是否切换成功
dg2 节点 (primary 角色):
SQL> select * from tt;
A
———-
1
3
4
5
6
7
6 rows selected.
SQL> insert into tt values(8);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from tt where a=8;
A
———-
8
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/oradata/tong/archive
Oldest online log sequence 78
Next log sequence to archive 80
Current log sequence 80
SQL>
dg1 节点 (standby 角色):
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/oradata/tong/archive
Oldest online log sequence 79
Next log sequence to archive 0
Current log sequence 80
SQL> alter database recover managed standby database cancel;
Database altered.
SQL> alter database open read only;
Database altered.
SQL> select * from tt;
A
———-
1
3
4
5
6
7
8
7 rows selected.
SQL>
Oracle DataGuard 升级 [11.2.0.1 -> 11.2.0.4] http://www.linuxidc.com/Linux/2017-02/140557.htm
更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2017-04/142937.htm