oracle11GR2 dataguard SWITCHOVER FAILOVER
1. switch:用户主动切换; 2. failover:主库出现故障,强行切换; switchover:一般switchover切换都是计划中的切换,特点是切换后,不会丢失任何数据,而且这个过程是可逆的,整个dataguard环境不会被破坏,原来dataguard环境中的所有物理和逻辑standby都
1. switch:用户主动切换;
2. failover:主库出现故障,强行切换;
switchover:一般switchover切换都是计划中的切换,特点是切换后,不会丢失任何数据,而且这个过程是可逆的,整个dataguard环境不会被破坏,原来dataguard环境中的所有物理和逻辑standby都可以继续工作。
在进行dataguard的物理standby切换前需要注意:
1、确认主库和从库间网络连接通畅;
2、确认没有活动的会话连接在数据库中;
3、primary数据库处于打开的状态,standby数据库处于mount状态;
4、确保standby数据库处于archivelog模式;
5、如果设置了redo应用延迟,那么将这个设置去掉;
6、确保配置了主库和从库的初始化参数,使得切换完成后,dataguard机制可以顺利的运行。
switch切换过程:先主库再备库
主库:
由于主库处于open状态,有访问的,所以v$database视图中,switch_status为session active,而由primary切换到standby需要数据库为open状态,因此,执行切换命令时,带上with session shutdown选项即可。
执行完切换命令后,关闭数据库,重新启动数据库到mount状态等待日志传输,开启日志应用。
查看alert log可以看到主库做了哪些动作:主库断开所有session(未提交事务会回滚),备份控制文件,切换日志并归档,传输日志到备库,给备库一个End-Of-REDO的信号,切换为standby,重新启动到mount。
查看switchover状态:
SQL> select database_role,switchover_status from v$database;
附: A:switchover_status出现session active/not allowed
当出现session active的时候表示还有活动的session
SQL> alter database commit to switchover to physical standby with session shutdown;
SQL> shutdown immediate;
SQL> startup nomount;
SQL> alter database mount standby database;
备库:
确认是否可以切换为主库,如果switchover_status为recovery needed或switchover latent,需要apply完所有归档日志才能切换。如果是sessions active则带上with session shutdown选项。apply完所有日志后,即可切换为primary,然后打开数据库。
查看alert.log可以看到备库做了哪些动作:关闭arch进程,接收主库日志,接收到主库End-Of-REDO的信号,apply完所有日志,清空online redo log以便打开数据库,切换为primary,打开数据库。
SQL> select database_role,switchover_status from v$database;
SQL> alter database commit to switchover to primary with session shutdown;
ERROR at line 1:
ORA-16139: media recovery required
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 STANDBYTO PRIMARY
SQL> alter database commit to switchover to primary with session shutdown;
Database altered.
SQL> shutdown immediate;
SQL> startup;
以上过程,由于主库断开所有session并归档,传输日志到备库,发给备库end-ofredo的信号,因此正常swithch时,是不会丢失数据的。
切换完成后可以在主库归档,验证一下是否切换成功,备库是否能正常接收日志。
开启日志应用:(主库-原备库)
SQL> alter database recover managed standby database using current logfile disconnect from session;
FailOver:当主库当掉,无法使用时,此时的切换即为failover,如果保护模式为最大性能模式,是可能丢失数据的。
备库端:
如果是最大保护和最大可用性模式,则可以直接在备库端执行failover切换。如果是最大性能模式,为了尽可能减少数据丢失,需要检查主库是否有日志没有传输到备库,手动传输备库进行注册和恢复。注意RAC环境下,归档日志是分线程的。
1. 停止日志应用
alter database recover managed standby database cancel;
2. 关闭standby日志传输
alter database recover managed standby database finish force;
3. 切换到primary
alter database commit to switchover to primary with session shutdown;
做这一步的时候,若存在gap,则会报ORA-16139:Switchover: Media recovery required – standby not in limbo 错误。
做测试的时候,若先起主库再起备库,且未等待备库相关日志传输完毕,就会出现这个问题。此时需要强制切换
alter database activate physical standby database;
4. 重启数据库到open状态
[oracle@testdb dev01]$ scp * oracle@192.168.0.8:/u01/archive/dev01dg
注册归档日志有如下两种方法,较为简单当然是用rman了,一次注册多个。
RMAN>catalog start with ‘/u01/archive/dev01′;
SYS@dev01dg>alter database register logfile ‘/u01/archive/dev01dg/arch_e8fe6364_1_712757927_460.dbf’;
apply归档日志也有两种方法。
SYS@dev01dg>alter database recover managed standby database disconnect from session;
Database altered.
SYS@dev01dg>recover standby database;
ORA-00279: change 2863819 generated at 03/20/2010 21:58:17 needed for thread 1
ORA-00289: suggestion : /u01/archive/dev01dg/arch_e8fe6364_1_712757927_461.dbf
ORA-00280: change 2863819 for thread 1 is in sequence #461
当手动apply完所有的日志后,就可以failover切换到primary了,但是要注意的是,由于备库没有收到主库的end-of-redo的信号,所以直接转换会报错,要求介质恢复,此时需要提交命令告诉备库,日志恢复已经finish,需要进行failover切换,注意switch时千万不要带有finish选项,否则就会变成failover了。
SYS@dev01dg> 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
SYS@dev01dg> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
—————- ——————–
PHYSICAL STANDBYNOT ALLOWED
SYS@dev01dg>alter database recover managed standby databasefinish[force];
Database altered.
SYS@dev01dg> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
—————- ——————–
PHYSICAL STANDBYTO PRIMARY
SYS@dev01dg>alter database commit to switchover to primary with session shutdown;
Database altered.
SYS@dev01dg>alter database open;
Database altered.
SYS@dev01dg> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
—————- ——————–
PRIMARY SESSIONS ACTIVE
failover完成后,数据库其实是以resetlogs方式打开的,如果log_archive_format=’arch_%d_%t_%r_%s.dbf’,可以看到归档日志的文件名会有新的resetlogs ID和sequence number,以此与原有的归档日志进行区分。
补充11g官方文档处理顺序和操作语句
1、主库切换
SELECT SWITCHOVER_STATUS FROM V$DATABASE;
ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY WITH SESSION SHUTDOWN;
shutdown immediate;
startup nomount;
alter database mount standby database;
2、备库切换
SELECT SWITCHOVER_STATUS FROM V$DATABASE;
ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY WITH SESSION SHUTDOWN;
ALTER DATABASE OPEN;
3、开启应用(新备库–原主库)
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT FROM SESSION;
原文地址:oracle11GR2 dataguard SWITCHOVER FAILOVER, 感谢原作者分享。

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











Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.
