DG之主库、备库切换(物理备库)
DG之主库、备库切换 一.开库与关库顺序 开库顺序 先启备库,再启主库(启动监听、打开告警日志) 关库顺序 先关主库,再关备库 二.主备库切换 1、操作过程一览 步骤1:启动备库、监听、告警; 步骤2:启动主库、监听、告警; 步骤3:主库(bj)查询信息 SQ
DG之主库、备库切换
一.开库与关库顺序
开库顺序 |
先启备库,再启主库(启动监听、打开告警日志) |
关库顺序 |
先关主库,再关备库 |
二.主备库切换
1、操作过程一览
步骤1:启动备库、监听、告警;
步骤2:启动主库、监听、告警;
步骤3:主库(bj)查询信息
SQL>selectname,dbid,database_role,protection_mode from v$database;
步骤4:备库(sh)上做recover
SQL>recovermanaged standby database disconnect from session;
步骤5:备库上插入数据
SQL>insert into scott.emp1 select * from scott.emp;
报错
虽然备库处于open状态,但它是一个read-only状态。
步骤6:查看主库(bj)、备库(sh)日志是否一致
SQL>selectmax(sequence#) from v$archived_log where name is not null;
或SQL>selectmax(sequence#) from v$archived_log;
举例:
主库:
备库:

上图表明已经归档的最大序列号均为34,说明日志是同步的,可以进行主备库切换。
步骤7:主库(bj)下检查是否可以切换
SQL>selectname,database_role,protection_mode,switchover_status from v$database;
switchover_status显示“TO STANDBY”表示允许做切换。

步骤8:备库(sh)下检查是否可以切换
SQL>selectname,database_role,protection_mode,switchover_status from v$database;

说明:备库是不允许主动去切成主库的,NOT ALLOWED状态说明正常。
步骤9:检查主库(bj)上的会话
SQL>select username,sid from v$session where username is notnull;
查看是否仍有用户使用数据库,若仍有人使用,是不允许切换的,切换前要通知确保无用户使用。
步骤10:主库(bj)变为物理备库(sh)
若没有会话,将主库(bj)变为物理备库(sh)
SQL> ALTER DATABASECOMMIT TO SWITCHOVER TO PHYSICAL STANDBY;
若有会话的话,关闭会话,将主库(bj)变为物理备库(sh)
SQL> alter database commit to switchover to physical standby withsession shutdown;
步骤11:关闭、重启之前的主库(bj)到mount状态
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP MOUNT;
SQL> selectswitchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
注:在这个时候,两个数据库都应该处于备库状态。
步骤12:查证备库的转换状态
SQL> SELECTSWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO_PRIMARY ——可以转换为主库,说明是备库状态
步骤13:将目标物理备库(sh)转换为主库
SQL> ALTER DATABASECOMMIT TO SWITCHOVER TO PRIMARY(WITHSESSION SHUTDOWN);
步骤14:完成备库(sh)到主库转换,物理备库启动到open
若物理备库(bj)在最近一次启动时不是处于只读模式 opened in read-only mode,直接将数据库打开,然后下一步。
SQL> select status fromv$instance;
STATUS
------------
MOUNTED
SQL> ALTER DATABASE OPEN;
SQL> select switchover_statusfrom v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
若物理备库(bj)在最近一次启动时是只读模式,则先将数据库正常关闭再起库。
SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP;
步骤15:在新备库(bj)上重新开启日志应用
SQL> ALTER DATABASERECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
步骤16:在新的主库(sh)上切换日志,开始传输数据给备库
SQL> ALTER SYSTEM SWITCHLOGFILE;
SQL> /
SQL> select max(sequence#)from v$archived_log;
MAX(SEQUENCE#)
--------------
56
SQL> col name for a50;
SQL> select NAME ,SEQUENCE# from v$archived_log; 查看归档日志
步骤17:在备库(bj)上查看归档,两值相等说明备库能收到日志
SQL> select max(sequence#)from v$archived_log;
MAX(SEQUENCE#)
--------------
56
SQL> col name for a50;
SQL> select NAME ,SEQUENCE# from v$archived_log; 查看归档日志
2、总结主备库切换重点
时 间 轴 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
|
主库 |
备库 |
查询能否切换(应该显示允许) |
|
|
|
备库查询能否切换(应该显示不允许) |
|
切换为物理备库 |
|
|
切换到mount状态 |
|
|
|
查看备库转换状态 |
|
|
转换为主库 |
|
|
切换到mount状态 |
|
启动到open |
|
|
|
|
|
|
启动到open状态 |
|
开启日志应用 |
|
|
|
切换日志 |
|
|
查看归档序列号 |
|
查看归档序列号 |
|
|
查询状态:备库 |
查询状态:主库 |
***********************************************声明************************************************
原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处(http://blog.csdn.net/huangyanlong)。
表述有错误之处,请您留言,不胜感激。
提醒:点击目录,更有助于您的查看。
*****************************************************************************************************

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Xiaomi 14Ultra is one of the most popular Xiaomi models this year. Xiaomi 14Ultra not only upgrades the processor and various configurations, but also brings many new functional applications to users. This can be seen from the sales of Xiaomi 14Ultra mobile phones. It is very popular, but there are some commonly used functions that you may not know yet. So how does Xiaomi 14Ultra switch between 4g and 5g? Let me introduce the specific content to you below! How to switch between 4g and 5g on Xiaomi 14Ultra? 1. Open the settings menu of your phone. 2. Find and select the "Network" and "Mobile Network" options in the settings menu. 3. In the mobile network settings, you will see the "Preferred network type" option. 4. Click or select this option and you will see

How to convert Win11 Home Edition to Win11 Professional Edition? In Win11 system, it is divided into Home Edition, Professional Edition, Enterprise Edition, etc., and most Win11 notebooks are pre-installed with Win11 Home Edition system. Today, the editor will show you the steps to switch from win11 home version to professional version! 1. First, right-click on this computer on the win11 desktop and properties. 2. Click Change Product Key or Upgrade Windows. 3. Then click Change Product Key after entering. 4. Enter the activation key: 8G7XN-V7YWC-W8RPC-V73KB-YWRDB and select Next. 5. Then it will prompt success, so you can upgrade win11 home version to win11 professional version.

Converting a virtual machine (VM) to a physical machine is the process of migrating a virtual instance and associated application software to a physical hardware platform. This conversion helps optimize operating system performance and hardware resource utilization. This article aims to provide an in-depth look at how to make this conversion. How to implement migration from virtual machine to physical machine? Typically, the conversion process between a virtual machine and a physical machine is performed outside the virtual machine by third-party software. This process consists of multiple stages involving the configuration of virtual machines and the transfer of resources. Prepare the physical machine: The first step is to ensure that the physical machine meets the hardware requirements for Windows. We need to back up the data on a physical machine as the conversion process will overwrite the existing data. *Username and password for an administrator account with administrator rights to create system images. will be virtual

Many friends may not be used to the win system when they first come into contact with it. There are dual systems in the computer. At this time, you can actually switch between the two systems. Let's take a look at the detailed steps for switching between the two systems. How to switch between two systems in win10 system 1. Shortcut key switching 1. Press the "win" + "R" keys to open Run 2. Enter "msconfig" in the run box and click "OK" 3. In the open "System Configuration" In the interface, select the system you need and click "Set as Default". After completion, "Restart" can complete the switch. Method 2. Select switch when booting 1. When you have dual systems, a selection operation interface will appear when booting. You can use the keyboard " Up and down keys to select the system

How to switch between Apple dual systems when starting up Apple computers are powerful devices. In addition to their own macOS operating system, you can also choose to install other operating systems, such as Windows, to achieve dual system switching. So how do we switch between the two systems when booting? This article will introduce to you how to switch between dual systems on Apple computers. First of all, before installing dual systems, we need to confirm whether our Apple computer supports dual system switching. Generally speaking, Apple computers are based on

In the application of excel software, we are accustomed to using shortcut keys to make some operations easier and faster. Sometimes there is related data between multiple tables in excel. When we view it, we have to constantly switch between tasks. If there is a faster switching method, it will save a lot of wasted time on switching, which will greatly help improve work efficiency. What method can be used to complete quick switching? To address this issue, the editor will talk about it today The content is: How to use the shortcut keys for switching workbooks in Excel. 1. First, you can see multiple workbooks at the bottom of the open excel table. You need to quickly switch between different workbooks, as shown in the figure below. 2. Then press the Ctrl key on the keyboard without moving, and select the job to the right if you need to

Win11 supports users to use the alt+tab shortcut key to bring up the desktop switching tool, but recently a friend encountered the problem that win11 alt+tab cannot switch the interface. I don’t know the reason or how to solve it. Why can't win11 alt+tab switch the interface? Answer: Because the shortcut key function is disabled, here is the solution: 1. First, we press "win+r" on the keyboard to open the run. 2. Then enter "regedit" and press Enter to open the group policy. 3. Then enter "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer"

With the rapid development of smartphones, Huawei, as a leading technology company, has launched many popular mobile phone products. Among them, Huawei dual system is a feature that makes many users excited. Through Huawei dual system, users can run two operating systems, such as Android and HarmonyOS, on the same mobile phone at the same time. This feature allows for greater flexibility and convenience. So, how to switch settings between Huawei dual systems? Let’s find out together. First, before switching to dual system setup on your Huawei phone,
