Home Database Mysql Tutorial 基于同一主机配置Oracle 11g Data Guard(logical standby)

基于同一主机配置Oracle 11g Data Guard(logical standby)

Jun 07, 2016 pm 05:31 PM

Oracle Data Guard逻辑备库是利用主库的一个备份首先建立一个物理备库,然后再将其转换为逻辑备库。这之后主库将日志传递到备库,

Oracle Data Guard逻辑备库是利用主库的一个备份首先建立一个物理备库,然后再将其转换为逻辑备库。这之后主库将日志传递到备库,备库利用logminer从主库的日志中解析出主库所执行过的SQL,在备库上重新执行一遍,从而保证与主库的数据在逻辑上保持一致。与物理备库相对应的是,物理备库使用的是redo apply,逻辑备库使用的是sql apply。因此逻辑备库仅仅保证数据与主库是在逻辑上是一致的,从而逻辑备库可以处于open状态下并进行相应的DML操作。本文描述了创建逻辑备库的注意事项以及给出了如何创建逻辑备库。

相关参考:
Oracle Data Guard 重要配置参数 
基于同一主机配置 Oracle 11g Data Guard 
 

1、逻辑备库的一些限制
对于逻辑备库,存在很多限制,如对于一些特殊的些数据类型象object,nested table,rowid,对象类型,自定义的数据类型等不被支持,以及不
支持段压缩,不支持一些特定的DDL语句等等一大堆的东西了。具体可以参考Oracle Data Guard Concepts and Administration。尽管如此,逻
辑备库依旧有很多物理备库所不具备的特点。下面仅仅列出逻辑备库几个重要关注的信息。

a、确定不被支持的schema
--对于Oracle数据库自带的相关schema会被跳过,因此不要基于这些schema来创建对象或测试,可使用下面的查询来查看
SQL> SELECT OWNER FROM DBA_LOGSTDBY_SKIP WHERE STATEMENT_OPT = 'INTERNAL SCHEMA';


c、确定存在唯一性问题的对象
由于逻辑standby与原数据库是逻辑相同,因此逻辑standby上的rowid并不等同于主库上的rowid。关于rowid可参考:Oracle ROWID
对于主库上的update,delete操作,Oracle通过主键和唯一索引/补充日志确保主库与备库所操作的对象为同一对象上的同一记录
对于启用了主键和唯一索引,补充日志的情形,每一条update语句如何去鉴别被更新的行呢?针对下面的情形在写redo的时候会附加列值唯一信息
表存在主键,则主键值会随同被更新列一起做为update语句的一部分
表无主键,存在非空的唯一索引/约束时,则最短的非空的唯一索引/约束会随同被更新列做为update语句的一部分
表无主键,无唯一索引/约束,所有可定长度的列(除long,lob,long raw,object type,collection类型列)连同被更新列作为update语句的一部分
注,存在函数唯一索引的表能够被实现SQL Apply,只要修改的行能够被唯一鉴别,但该索引函数不能用作唯一性去鉴别更新的行
对于那些可由应用程序确保表上的行记录唯一的,又不希望创建主键的情形,可以通过创建RELY约束,以避免维护主键所带来的额外开销
--可使用下面的方式为表添加RELY约束
SQL> ALTER TABLE tb_name ADD PRIMARY KEY (id, name) RELY DISABLE;

--数据字典DBA_LOGSTDBY_NOT_UNIQUE记录了那些不存在主键以及唯一索引的表或者是说没有足够的信息能够保证主库与逻辑standby锁定相同对象
SQL> SELECT owner, table_name FROM dba_logstdby_not_unique
2 WHERE (owner, table_name) NOT IN (SELECT DISTINCT owner, table_name FROM dba_logstdby_unsupported) AND bad_column = 'Y';

--查看主库是否启用补充日志,在主库执行包dbms_logstdby.build后即开始启用
SQL> select supplemental_log_data_pk,supplemental_log_data_ui from v$database;

2、逻辑备库的几个重要进程
逻辑备库需要一系列的进程来完成日志的捕获和应用工作。主要由两个组件组成:挖掘引擎与应用引擎。也就是一个负责从重归档日志或备用日
志提取SQL语句集,一个负责将其SQL语句集应用到逻辑备库。这两个引擎的相关进程可以通过V$LOGSTDBY_PROCESS视图中查询获得其相关信息。
挖掘引擎进程:
READER : 进程从主库传过来的归档或者standby redo logfile中解析重做记录(redo record)
PREPARER :进程负责将READER进程解析到的重做记录转换为LCR(Logical change record)
可以有多个PREPARER进程。解析出来的LCR存放在shared pool的一个叫做LCR cache的区域中
BUILDER :进程将LCR打包成事务,将多个LCR合成单个LCR,另外还负责管理LCR cache。如进行内存换页,推进日志挖掘检查点等

应用引擎进程:
ANALYZER :该进程负责检查一组LCR中包含的事务片段,过滤掉不需要应用的事务,检查不同事务的依赖关系等
COORDINATOR :该进程分配事务给APPLIER进程,监控事务依赖关系和协调提交顺序
APPLIER : 可以有多个该进程,它负责将LCR应用到备库

3、创建逻辑备库

a、首先创建物理备库
  创建物理备库的方法很多,对于Oracle 11g而言,可以直接从active database来创建,也可以基于10g 的RMAN使用duplicate方式来创建。
  关于物理备库的创建,此处不演示。
  可以参考:基于同一主机配置 Oracle 11g Data Guard 


b、 校验主库与物理备库
  --主库: CNBO,,备库: HKBO
  --主库上的信息
  CNBO> select name,database_role,switchover_status from v$database;
 
  NAME              DATABASE_ROLE    SWITCHOVER_STATUS
  ----------------- ---------------- ------------------------
  CNBO              PRIMARY          TO STANDBY
 
  --备库上的信息
  HKBO> select name,open_mode,database_role,protection_mode from v$database;
 
  NAME      OPEN_MODE            DATABASE_ROLE    PROTECTION_MODE 
  --------- -------------------- ---------------- --------------------   
  HKBO      MOUNTED              PHYSICAL STANDBY MAXIMUM PERFORMANCE
 
  --SRL被apply的情形
  HKBO> select sequence#, first_time, next_time,applied from v$archived_log where rownum                                                                                                                   
  SEQUENCE# FIRST_TIME          NEXT_TIME          APPLIED                                                     
  ---------- ------------------- ------------------- ---------------------------                                 
          7 2013/08/16 10:38:03 2013/08/16 10:46:11 YES                                                         
          6 2013/08/16 10:38:00 2013/08/16 10:38:03 YES                                                         

Statement of this Website
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

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

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1243
24
When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

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.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

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: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

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.

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Explain the role of InnoDB redo logs and undo logs. Explain the role of InnoDB redo logs and undo logs. Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

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's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

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.

See all articles