逻辑备数据库的切换和故障转移
欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入 本文描述如何执行包含逻辑备数据库的切换和故障转移。 一、 逻辑备数据库的切换 当你执行切换,在主数据库和逻辑备数据库之间更改角色,总是在主数据库上发起切换并在逻辑备数据库上完成。这些步骤
欢迎进入Oracle社区论坛,与200万技术人员互动交流 >>进入
本文描述如何执行包含逻辑备数据库的切换和故障转移。
一、 逻辑备数据库的切换
当你执行切换,在主数据库和逻辑备数据库之间更改角色,总是在主数据库上发起切换并在逻辑备数据库上完成。这些步骤必须以所描述的顺序执行,否则切换将不会成功。
注:如果主数据库是RAC 数据库,确保除了一个以外关闭所有实例,并且在发起切换之前禁止相应的线程。类似地,如果逻辑备数据库是RAC 数据库,确保除了一个以外的所有实例关闭SQL 应用,并且在发起切换之前禁止相应的线程。一旦切换操作成功完成,你能重新允许这些线程并启动实例。虽然实例是关闭的,但是当它们重启时,角色更改将不会自动传递到这些实例。
第 1 步在主数据库上检验是否有可能执行切换
在当前的主数据库上,查询在主数据库上的 V$DATABASE 固定视图的SWITCHOVER_STATUS 列,以检验是否可能执行切换。
例如:
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO STANDBY
1 row selected。
在 SWITCHOVER_STATUS 列中的TO STANDBY 或SESSIONS ACTIVE 的值指出可能切换主数据库到逻辑备角色。如果这些值之一没有显示,则检验Data Guard 配置是否正确起作用(例如,检验所有LOG_ARCHIVE_DEST_n 参数值是否正确指定)。
第 2 步为切换准备当前主数据库
要为逻辑备数据库角色准备当前主数据库,在主数据库上执行下面的 SQL 语句:
SQL> ALTER DATABASE PREPARE TO SWITCHOVER TO LOGICAL STANDBY;
这条语句通知当前主数据库,它将马上切换到逻辑备角色并开始从新的主数据库接收重做数据。你在主数据库上执行这个步骤,为接收LogMiner Multiversioned Data Dictionary记录在当前逻辑备数据库的重做流中做准备,如步骤3 中描述。如果这个操作成功,则 V$DATABASE.SWITCHOVER_STATUS 列中显示PREPARING SWITCHOVER 值。
第 3 步为切换准备目标逻辑备数据库
使用下面命令在作为切换目标的逻辑备数据库上建立 LogMiner Multiversioned Data Dictionary:
SQL> ALTER DATABASE PREPARE TO SWITCHOVER TO PRIMARY;
这条语句也在逻辑备数据库上开始重做传输服务 ,开始传送其重做数据到当前主数据库和Data Guard 配置中的其它备数据库。从这个逻辑备数据库接收重做数据的站点接收重做数据但不应用。
依赖于完成的工作量和数据库的大小,切换需要花费一些时间来完成。
当 LogMiner Multiversioned Data Dictionary 正在重做流中记录时,在逻辑备数据库上的V$DATABASE.SWITCHOVER_STATUS 最初显示PREPARING DICTIONARY。一旦这个成功完成,SWITCHOVER_STATUS 列显示PREPARING SWITCHOVER。
第 4 步确保当前主数据库为将来的主数据库的重做流做好准备
在你能完成主数据库到逻辑备角色的转换之前,通过查询主数据库上的V$DATABASE固定视图的SWITCHOVER_STATUS 列,检验LogMiner Multiversioned Data Dictionary 是否被主数据库接收到。没有收到LogMiner Multiversioned Data Dictionary,切换无法进行,因为当前的主数据库将不能解释从未来的主数据库发送的重做记录。SWITCHOVER_STATUS列显示了切换的过程。
当查询返回 TO LOGICAL STANDBY 值,你能进行到步骤5。
例如:
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO LOGICAL STANDBY
1 row selected
注:
你能通过以下面的顺序执行下面的语句来取消切换操作:
1.在主数据库上取消切换:
SQL> ALTER DATABASE PREPARE TO SWITCHOVER CANCEL;
2.在逻辑备数据库上取消切换:
SQL> ALTER DATABASE PREPARE TO SWITCHOVER CANCEL;
第 5 步切换主数据库到逻辑备数据库角色
要完成主数据库到逻辑备数据库的角色转换,执行下面 SQL 语句:
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO LOGICAL STANDBY;
这条语句等待主数据库上的所有当前事务结束,并阻止任何新的用户开始新事务,并在切换将要提交的地方建立一个时间点。
执行这条语句也将阻止用户对由逻辑备数据库维护的数据进行更改。要确保更快地执行,确保主数据库在执行切换语句之前处于安静的状态,没有更新活动(例如,要求所有用户暂时从主数据库退出登录)。你能查询V$TRANSACTIONS 视图以获得任何当前正在处理的事务的状态,这些事务可能延迟这条语句的执行。
主数据库现在可以经历角色转换以运行到备数据库角色。
当主数据库经历角色转换到逻辑备数据库角色时,你不需要关闭和重启数据库。
第 6 步确保所有可用的重做应用到将要成为新的主数据库的目标逻辑备数据库上
在你完成主数据库到逻辑备角色的角色转换,以及配置中的备数据库接收到切换通知之后,你应该检验切换通知是否被目标备数据库处理,通过查询目标备数据库上的V$DATABASE 固定视图的SWITCHOVER_STATUS 列。一旦所有可用的重做记录应用到逻辑备数据库,SQL 应用自动关闭以准备预料中的角色转换。
SWITCHOVER_STATUS 值更新以显示切换中的过程。当状态为TO PRIMARY,你能进行步骤7。
例如:
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
-----------------
TO PRIMARY
1 row selected
第 7 步切换目标逻辑备数据库到主数据库角色
在你希望切换到主角色的逻辑备数据库上,使用下面的 SQL 语句来切换逻辑备数据库到主角色:
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
没有必要关闭并重启在 Data Guard 配置中的任何逻辑备数据库。其它现有的逻辑备数据库将在切换完成后继续正常起作用。然而,所有现有的物理备数据库在切换后无法参与到Data Guard 配置中了。
第 8 步在新的逻辑备数据库上开始SQL 应用
在新的逻辑备数据库,开始 SQL 应用:
SQL> ALTER DATABASE START LOGICAL STANDBY APPLY;
[1] [2]

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











MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

Oracle views can be exported through the EXP utility: Log in to the Oracle database. Start the EXP utility, specifying the view name and export directory. Enter export parameters, including target mode, file format, and tablespace. Start exporting. Verify the export using the impdp utility.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.
