oracle ADG主备切换

1.主库切换备库

bash 复制代码
SQL> select name,open_mode,switchover_status from v$database;

NAME OPEN_MODE SWITCHOVER_STATUS
--------- -------------------- --------------------
PROD1 READ WRITE TO STANDBY

SQL> alter system switch logfile;

System altered.

SQL> alter system archive log current;

System altered.

SQL> alter database commit to switchover to physical standby with session shutdown;

Database altered.

SQL> shutdown abort
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.

Total System Global Area 849530880 bytes
Fixed Size 1348244 bytes
Variable Size 511708524 bytes
Database Buffers 331350016 bytes
Redo Buffers 5124096 bytes
Database mounted.
SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
RECOVERY NEEDED

SQL> alter database open;

Database altered.

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO PRIMARY

2.备库切换主库

bash 复制代码
这里可能会出现错误:
ORA-16139: media recovery required。
下面有解决方法
解决完后,可以不要再次执行了。直接执行下面的命令。
bash 复制代码
SQL>  alter database commit to switchover to primary with session shutdown;                       
alter database commit to switchover to primary with session shutdown
*
ERROR at line 1:
ORA-16139: media recovery required

怀疑可能是由于有日志未应用造成的,执行如下语句查询:
SQL> select APPLIED,SEQUENCE# from v$archived_log;

APPLIED    SEQUENCE#
--------- ----------
YES                8
YES                9
YES               12
YES               13
YES               15
YES               16
YES               17
YES               10
YES               14
YES               11
YES               19

APPLIED    SEQUENCE#
--------- ----------
YES               18
NO                20
NO                21
NO                22
NO                23

16 rows selected.

正确步骤:

SQL> ALTER  DATABASE RECOVER MANAGED STANDBY  DATABASE DISCONNECT FROM SESSION;

Database altered.

SQL> alter database commit to switchover to primary;

Database altered.


SQL> alter database open;

Database altered.

SQL> select name,open_mode,switchover_status from v$database;

NAME OPEN_MODE SWITCHOVER_STATUS
--------- -------------------- --------------------
PROD1 READ WRITE TO STANDBY

3. 新备库(原主库)启用实时日志应用

bash 复制代码
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> select name,open_mode,switchover_status from v$database;

NAME OPEN_MODE SWITCHOVER_STATUS
--------- -------------------- --------------------
RMANPRI READ ONLY RECOVERY NEEDED

4.新主库切换日志

bash 复制代码
SQL> alter system switch logfile;

System altered.

5、分别查看当前主备库切换后当前日志序列号

bash 复制代码
主库:

SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/archive
Oldest online log sequence 52
Next log sequence to archive 54
Current log sequence 54

备库:

SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/archive
Oldest online log sequence 53
Next log sequence to archive 0
Current log sequence 54

6、查看当前主备库状态

bash 复制代码
主库:

SQL> select name,open_mode,switchover_status from v$database;

NAME OPEN_MODE SWITCHOVER_STATUS
--------- -------------------- --------------------
RMANPRI READ WRITE TO STANDBY

 

备库:

SQL> select name,open_mode,switchover_status from v$database;

NAME OPEN_MODE SWITCHOVER_STATUS
--------- -------------------- --------------------
RMANPRI READ ONLY WITH APPLY NOT ALLOWED
相关推荐
审判长烧鸡27 分钟前
PostgreSQL之索引/函数/触发器
数据库·postgresql·触发器·函数·索引
Data_Journal32 分钟前
如何使用cURL更改User Agent
大数据·服务器·前端·javascript·数据库
Python私教1 小时前
GenericAgent PySide6 桌面应用深度解析:悬浮按钮 + 聊天面板的原生 Qt 方案
开发语言·数据库·qt
byoass1 小时前
企业云盘与设计软件深度集成:AutoCAD/Revit/SolidWorks插件开发与API集成实战
服务器·网络·数据库·安全·oracle·云计算
爬山算法2 小时前
MongoDB(113)如何使用第三方工具进行MongoDB监控?
数据库·mongodb
早日退休!!!3 小时前
大模型推理瓶颈七层分析模型
java·服务器·数据库
大山同学3 小时前
claudecode精炼版-CoreCoder
数据库·人工智能·claude code·corecoder
of Watermelon League3 小时前
5、使用 pgAdmin4 图形化创建和管理 PostgreSQL 数据库
数据库·postgresql
Dontla4 小时前
Python asyncpg库介绍(基于Python asyncio的PostgreSQL数据库驱动)连接池、SQLAlchemy
数据库·python·postgresql
俺不要写代码4 小时前
数据库:DQL
数据库·sql·mysql