search
HomeDatabaseMysql TutorialOracle 11g Active Dataguard Switchover实验

Oracle Data Guard是Oracle HA架构体系的重要组成部分,也是Oracle MAA(Maximum Availability Architecture)的关键技术方案。借

Oracle Data Guard是Oracle HA架构体系的重要组成部分,也是Oracle MAA(Maximum Availability Architecture)的关键技术方案。借助Data Guard的Switchover和Failover特性,我们可以实现运维系统高可用性需求,最大限度的降低计划内和非计划内宕机时间。
 
Data Guard建立在数据库软硬件、数据冗余策略,通过搭建和主库Primary Database数据相同、软硬件独立的物理(Physical)和逻辑(Logical)备库Standby,并且借助Redo Log传递应用确保数据同步。当单独数据库(通常为Primary)发生故障,不能继续提供服务时,额外的Standby可以作为备用数据库来支持应用,减少系统整体数据丢失和停机影响。
 
Switchover和Failover是Dataguard里面一组有区别又有联系的概念,其本质都是Primary停止对外服务,由Standby支持对外数据服务,变为新的Primary。但是两者从概念到操作上都有很大差异。
 
Switchover的核心是“Planned”,也就是计划内的停机切换动作。我们的运维系统在运行过程中,经常有如设备检修、软件升级补丁等维护操作。这个时候,如果是一些SLA要求很高的系统,停机时间窗口就是一个问题。特别是一些7*24的系统,业务部门是不会允许过长的停机时间。Switchover就是对Dataguard或者RAC环境下,临时性的Primary点停机进行升级工作,由Standby变为Primary支持服务,最后再切换回来的过程。这个过程在Oracle中成为角色转换role transition。由于是有准备、有计划的操作,Switchover是平顺的,不会引起数据的丢失。
 
Failover的核心则是“unplanned”,是和Switchover相对应,更贴近Data Guard的原始设计初衷。如果Primary出现故障,,不能支持服务的时候。Standby可以在很短的时间内,自动或者手动的切换到Primary角色。之后由这个新的Primary支持服务。如果Primary可以修复好,则可能需要重新搭建DG或者Apply为新的Standby,之后切换回Primary角色。Failover由于涉及到Primary站点的故障类型程度,所以是可能出现数据丢失的。
 
进行Switchover和Failover的工具方法很多,最常用的有三个:SQL Command、Data Guard Broker和DB Grid Control。本文介绍如何使用SQL Command进行Switchover操作。
 
 

相关参考:

Oracle Data Guard 重要配置参数

基于同一主机配置 Oracle 11g Data Guard

探索Oracle之11g DataGuard

Oracle Data Guard (RAC+DG) 归档删除策略及脚本

Oracle Data Guard 的角色转换

Oracle Data Guard的日志FAL gap问题

Oracle 11g Data Guard Error 16143 Heartbeat failed to connect to standby 处理方法

1、环境介绍

 

我们选择环境已经搭建好Dataguard,版本为11.2.0.4(Primary和Standby相同)。操作系统版本为Red Hat Linux 6.5。

 

 

SQL> select * from v$version;

 

BANNER

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

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production

PL/SQL Release 11.2.0.4.0 - Production

CORE 11.2.0.4.0 Production

 

Primary数据库unique名称为ora11g。

 

SQL> select name, LOG_MODE, OPEN_MODE, database_role, SWITCHOVER_STATUS, db_unique_name from v$database;
 
 

NAME      LOG_MODE    OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS    DB_UNIQUE_NAME
 
--------- ------------ -------------------- ---------------- -------------------- ------------------------------
 
ORA11G    ARCHIVELOG  READ WRITE          PRIMARY          SESSIONS ACTIVE      ora11g
 
 

Standby数据库名称为ora11gsy,此时开启实时数据同步应用。

 

SQL> alter database recover managed standby database using current logfile disconnect from session;
 
 

Database altered

 

SQL> select name, LOG_MODE, OPEN_MODE, database_role, SWITCHOVER_STATUS, db_unique_name from v$database;
 
 

NAME      LOG_MODE    OPEN_MODE            DATABASE_ROLE    SWITCHOVER_STATUS    DB_UNIQUE_NAME
 
--------- ------------ -------------------- ---------------- -------------------- ------------------------------
 
ORA11G    ARCHIVELOG  READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED          ora11gsy
 
 

注意:此时standby的open mode为Read only with apply,这个是11g Active Data Guard的特性。传统DG在进行Apply的过程中,是处在mount状态的,不支持实时数据只读操作。11g支持在apply中打开数据库到只读状态。
 
 

2、Switchover过程中Primary主库操作

 

进行Switchover的过程分为三个步骤,一个是在Primary上停止工作,切换到Standby状态,第二个是在选择一个Standby实例,切换角色到Primary状态,最后是将其他Standby的Apply过程启动。
 
注意在上面我们查看Primary数据库ora11g的v$database视图,其中switchover_status取值是我们需要关注的,如果取值为session active或者to standby,我们是可以进行切换的。如果其他值,说明配置的log传输机制存在问题,需要解决调整。
 
 

--在ora11g上

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

 

注意:如果swtichover_status状态为session active,就需要在命令中加入with session shutdown子句。执行后,我们发现Primary ora11g已经关闭。
 
 

 

SQL> select status from v$instance;

select status from v$instance

*

ERROR at line 1:

ORA-03135: connection lost contact

Process ID: 2357

Session ID: 1 Serial number: 5

 

 

SQL> exit

Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - Production
 
With the Partitioning, OLAP, Data Mining and Real Application Testing options

 

--实例进程消失

[oracle@SimpleLinux trace]$ ps -ef | grep pmon

oracle    2107    1  0 15:35 ?        00:00:01 ora_pmon_ora11gsy

oracle    2473  1848  1 16:03 pts/1    00:00:00 grep pmon

 

此时,alert log中也记录了实例停止的情况。

 

ALTER DATABASE ADD STANDBY LOGFILE 'srl1.f' SIZE 52428800;

ALTER DATABASE ADD STANDBY LOGFILE 'srl2.f' SIZE 52428800;

ALTER DATABASE ADD STANDBY LOGFILE 'srl3.f' SIZE 52428800;

ALTER DATABASE ADD STANDBY LOGFILE 'srl4.f' SIZE 52428800;

Archivelog for thread 1 sequence 19 required for standby recovery

Switchover: Primary controlfile converted to standby controlfile succesfully.

Switchover: Complete - Database shutdown required

USER (ospid: 2365): terminating the instance

Instance terminated by USER, pid = 2365

Completed: alter database commit to switchover to physical standby with session shutdown
 
 

Shutting down instance (abort)

License high water mark = 6

Sun Apr 20 16:02:11 2014

Instance shutdown complete

 

在这个过程中,为了确保数据无损失,Primary一定将所有的日志信息传递到Standby上。此时,可以启动Primary,到mount standby状态。

 

[oracle@SimpleLinux trace]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Sun Apr 20 16:06:47 2014

 

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

 

SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup nomount

ORACLE instance started.

 

Total System Global Area  372449280 bytes

Fixed Size                  1364732 bytes

Variable Size            331353348 bytes

Database Buffers          33554432 bytes

Redo Buffers                6176768 bytes

 

SQL> alter database mount standby database;

Database altered.

注意:如果需要进行设备维修或者停机操作,是可以不启动Primary的。

更多详情见请继续阅读下一页的精彩内容:

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Reduce the use of MySQL memory in DockerReduce the use of MySQL memory in DockerMar 04, 2025 pm 03:52 PM

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

How to solve the problem of mysql cannot open shared libraryHow to solve the problem of mysql cannot open shared libraryMar 04, 2025 pm 04:01 PM

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

How do you alter a table in MySQL using the ALTER TABLE statement?How do you alter a table in MySQL using the ALTER TABLE statement?Mar 19, 2025 pm 03:51 PM

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

Run MySQl in Linux (with/without podman container with phpmyadmin)Run MySQl in Linux (with/without podman container with phpmyadmin)Mar 04, 2025 pm 03:54 PM

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

What is SQLite? Comprehensive overviewWhat is SQLite? Comprehensive overviewMar 04, 2025 pm 03:55 PM

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

Running multiple MySQL versions on MacOS: A step-by-step guideRunning multiple MySQL versions on MacOS: A step-by-step guideMar 04, 2025 pm 03:49 PM

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

How do I configure SSL/TLS encryption for MySQL connections?How do I configure SSL/TLS encryption for MySQL connections?Mar 18, 2025 pm 12:01 PM

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?What are some popular MySQL GUI tools (e.g., MySQL Workbench, phpMyAdmin)?Mar 21, 2025 pm 06:28 PM

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment