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

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
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
MySQL String Types: Storage, Performance, and Best PracticesMySQL String Types: Storage, Performance, and Best PracticesMay 10, 2025 am 12:02 AM

MySQLstringtypesimpactstorageandperformanceasfollows:1)CHARisfixed-length,alwaysusingthesamestoragespace,whichcanbefasterbutlessspace-efficient.2)VARCHARisvariable-length,morespace-efficientbutpotentiallyslower.3)TEXTisforlargetext,storedoutsiderows,

Understanding MySQL String Types: VARCHAR, TEXT, CHAR, and MoreUnderstanding MySQL String Types: VARCHAR, TEXT, CHAR, and MoreMay 10, 2025 am 12:02 AM

MySQLstringtypesincludeVARCHAR,TEXT,CHAR,ENUM,andSET.1)VARCHARisversatileforvariable-lengthstringsuptoaspecifiedlimit.2)TEXTisidealforlargetextstoragewithoutadefinedlength.3)CHARisfixed-length,suitableforconsistentdatalikecodes.4)ENUMenforcesdatainte

What are the String Data Types in MySQL?What are the String Data Types in MySQL?May 10, 2025 am 12:01 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,2)VARCHARforvariable-lengthtext,3)BINARYandVARBINARYforbinarydata,4)BLOBandTEXTforlargedata,and5)ENUMandSETforcontrolledinput.Eachtypehasspecificusesandperformancecharacteristics,sochoose

How to Grant Permissions to New MySQL UsersHow to Grant Permissions to New MySQL UsersMay 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

How to Add Users in MySQL: A Step-by-Step GuideHow to Add Users in MySQL: A Step-by-Step GuideMay 09, 2025 am 12:14 AM

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

MySQL: Adding a new user with complex permissionsMySQL: Adding a new user with complex permissionsMay 09, 2025 am 12:09 AM

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

MySQL: String Data Types and CollationsMySQL: String Data Types and CollationsMay 09, 2025 am 12:08 AM

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

MySQL: What length should I use for VARCHARs?MySQL: What length should I use for VARCHARs?May 09, 2025 am 12:06 AM

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

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

Video Face Swap

Video Face Swap

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

Hot Tools

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.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.