[转帖]Data Guard之Logical Standby Database_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
2
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2201 | 回复: 1   主题: [转帖]Data Guard之Logical Standby Database        上一篇   下一篇 
bliaoo
注册用户
等级:新兵
经验:71
发帖:1
精华:0
注册:2018-9-7
状态:离线
发送短消息息给bliaoo 加好友    发送短消息息给bliaoo 发消息
发表于: IP:您无权察看 2019-9-19 11:03:33 | [全部帖] [楼主帖] 楼主

1、首先搭建Physical Standby Database,具体可参考"Data Guard之Physical Standby Database"
2、查询列出主数据库表中逻辑数据库不支持的表的方案名和表名

 SQL> SELECT DISTINCT OWNER,TABLE_NAME FROM DBA_LOGSTDBY_UNSUPPORTED ORDER BY OWNER,TABLE_NAME;
SQL> SELECT OWNER, TABLE_NAME FROM DBA_LOGSTDBY_NOT_UNIQUE WHERE (OWNER, TABLE_NAME) NOT IN
(SELECT DISTINCT OWNER, TABLE_NAME FROM DBA_LOGSTDBY_UNSUPPORTED) AND BAD_COLUMN = 'Y';


3、查询不支持的表中的列名和数据类型

 SQL> SELECT COLUMN_NAME,DATA_TYPE FROM DBA_LOGSTDBY_UNSUPPORTED WHERE OWNER='owner' AND TABLE_NAME = 'table_name';


4、确保主库中的表行能被唯一标志

 SQL> SELECT OWNER, TABLE_NAME,BAD_COLUMN FROM DBA_LOGSTDBY_NOT_UNIQUE WHERE TABLE_NAME NOT IN (SELECT TABLE_NAME FROM DBA_LOGSTDBY_UNSUPPORTED);


如果可以确认表中有唯一标示的字段,但是又不想真正创建主键或者索引来增加更新的开销,那么可以创建disabled RELY类型的约束

 SQL> ALTER TABLE mytab ADD PRIMARY KEY (id, name) RELY DISABLE;


5、检查supplemental logging是否已经被激活

 SQL> SELECT SUPPLEMENTAL_LOG_DATA_PK, SUPPLEMENTAL_LOG_DATA_UI FROM V$DATABASE;


用以下方法激活Primary库的supplemental logging属性

 SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE INDEX) COLUMNS;


注意,如果在一个有物理备用数据库的Data Guard配置中,你在主数据库激活追加日志功能,之后你必须在每一个物理备用数据库执行

 SQL> ALTER DATABASE ADD SUPPLEMENTAL LOG DATA;


这个语句,来确保将来的switchover能够正确工作
6、创建一个新的表空间,用于LogMiner,否则Logical Standby需要的对象将默认创建在SYSTEM表空间中

 SQL> CREATE TABLESPACE logmnrts DATAFILE '/data/app/oracle/oradata/boss/logmnrts.dbf' SIZE 50M AUTOEXTEND ON MAXSIZE UNLIMITED;
SQL> EXECUTE DBMS_LOGMNR_D.SET_TABLESPACE('logmnrts');


查看日志是否都已传入到standby database

 SQL> SELECT NAME FROM V$ARCHIVED_LOG WHERE (SEQUENCE#=(SELECT MAX(SEQUENCE#) FROM V$ARCHIVED_LOG
WHERE DICTIONARY_BEGIN = 'YES' AND STANDBY_DEST= 'NO'));


如能找到,例如找到如下记录

 NAME
--------------------------------------------------------------------------------
/data/archive_dets/march/1_29.dbf


在standby上,先注册primary库还未传到standby库的日志

 SQL> STARTUP MOUNT;
SQL> ALTER DATABASE GUARD ALL;
SQL> ALTER DATABASE REGISTER LOGICAL LOGFILE ‘/data/archive_dets/march/1_29.dbf‘;


7、确保待转换的物理Standby数据库已经停止REDO应用

 SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;


8、修改主库LOG_ARCHIVE_DEST_n参数

 SQL> Alter SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=/data/archive_dest/march VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=boss';
SQL> Alter SYSTEM SET LOG_ARCHIVE_DEST_3='LOCATION=/data/archive_dest/sarch VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=boss';
SQL> Alter SYSTEM SET LOG_ARCHIVE_DEST_STATE_3=ENABLE;


注:LOG_ARCHIVE_DEST_STATE_3仅仅只在主库切换时使用
9、Primary数据库生成数据字典

 SQL> EXECUTE DBMS_LOGSTDBY.BUILD;


10、转换物理Standby为逻辑Standby

 SQL> SHOW PARAMETER DB_NAME
SQL> SHOW PARAMETER SPFILE
SQL> ALTER DATABASE RECOVER TO LOGICAL STANDBY bosstdy;


注意:此时standby数据库参数文件最好是spfile,否则会报错

 ORA-16254: change db_name to STDBYDB in the client-side parameter file (pfile)


11、standby数据库重置密码文件
由于数据库更名,包括DBID、INCARNATION等均已被重新初始化,此时需要重新创建备库的密码文件,注意保持和主库相同

 [oracle@oracle-db2~]$ orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle


12、重启standby数据库

 SQL> SHUTDOWN IMMEDIATE;
SQL> STARTUP MOUNT;


为什么要重启?因为上述操作涉及逻辑Standby数据库更名,包括DBID、INCARNATION等均已被重新初始化

 SQL> SHOW PARAMETER DB_NAME;


13、调整逻辑Standby数据库初始化参数

 SQL> Alter SYSTEM SET LOG_ARCHIVE_DEST_1='LOCATION=/data/archive_dest/march VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=bosstdy';
SQL> Alter SYSTEM SET LOG_ARCHIVE_DEST_3='LOCATION=/data/archive_dest/sarch VALID_FOR=(STANDBY_LOGFILES,STANDBY_ROLE) DB_UNIQUE_NAME=bosstdy';
SQL> Alter SYSTEM SET LOG_ARCHIVE_DEST_STATE_3=ENABLE;


14、打开逻辑Standby
由于逻辑Standby与Primary数据库事务并不一致,因此第一次打开时必须指定RESETLOGS子句

 SQL> ALTER DATABASE OPEN RESETLOGS;
SQL> ALTER DATABASE START LOGICAL STANDBY APPLY INITIAL;
SQL> ALTER DATABASE START LOGICAL STANDBY APPLY;
SQL> ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATE;


如果要启用实时应用,建议首先创建Standby Redo logs,如有则无需创建

 SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 4 ('/data/app/oracle/oradata/boss/sredo04.log') size 50M;
SQL> ALTER DATABASE ADD STANDBY LOGFILE GROUP 5 ('/data/app/oracle/oradata/boss/sredo05.log') size 50M;


注意:至少要比ORL多一组
重新执行启动REDO应用的命令,附加APPLY IMMEDIATE子句,以打开实时应用

 SQL> ALTER DATABASE STOP LOGICAL STANDBY APPLY;


若创建了standby redologs 后就必须用下面的SQL语句开启实时应用

 SQL> ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATE;


如要停止SQL Apply应用,输入以下命令

 SQL> ALTER DATABASE STOP LOGICAL STANDBY APPLY;


15、验证环境
所有配置完成,接下来尝试在Primary数据库端执行修改操作,看看是否能够分别在逻辑Standby和物理Standby端应用
验证重做数据是否被正确应用
在逻辑备用数据库,查询V$LOGSTDBY_STATS视图,例如:

 SQL> COLUMN NAME FORMAT A30
SQL> COLUMN VALUE FORMAT A30
SQL> SELECT NAME, VALUE FROM V$LOGSTDBY_STATS WHERE NAME = 'coordinator state';
NAME VALUE
------------------------------ ------------------------------
coordinator state INITIALIZING


了解协调进程的状态非常重要,因为它是指示其他逻辑备用进程的LSP后台进程。
查看V$LOGSTDBY视图来观察当前sql apply的行为
初始化阶段V$LOGSTDBY的输出:

 SQL> COLUMN STATUS FORMAT A50
SQL> COLUMN TYPE FORMAT A12
SQL> SELECT TYPE, HIGH_SCN, STATUS FROM V$LOGSTDBY;
TYPE HIGH_SCN STATUS
------------ ---------- --------------------------------------------------
COORDINATOR ORA-16115: loading Log Miner dictionary data
READER ORA-16127: stalled waiting for additional transact
ions to be applied
BUILDER ORA-16117: processing
PREPARER ORA-16116: no work available
SQL> SELECT TYPE, HIGH_SCN, STATUS FROM V$LOGSTDBY;
TYPE HIGH_SCN STATUS
------------ ---------- --------------------------------------------------
COORDINATOR ORA-16126: loading table or sequence object number
READER ORA-16116: no work available
BUILDER ORA-16116: no work available
PREPARER ORA-16116: no work available


应用阶段的V$LOGSTDBY的输出:

 SQL> COLUMN NAME FORMAT A30
SQL> COLUMN VALUE FORMAT A30
SQL> SELECT NAME, VALUE FROM V$LOGSTDBY_STATS WHERE NAME = 'coordinator state';
NAME VALUE
------------------------------ ------------------------------
coordinator state APPLYING
SQL> COLUMN STATUS FORMAT A50
SQL> COLUMN TYPE FORMAT A12
SQL> SELECT TYPE, HIGH_SCN, STATUS FROM V$LOGSTDBY;
TYPE HIGH_SCN STATUS
------------ ---------- --------------------------------------------------
COORDINATOR ORA-16117: processing
READER ORA-16127: stalled waiting for additional transact
ions to be applied
BUILDER 191896 ORA-16116: no work available
PREPARER 191902 ORA-16117: processing
ANALYZER 191820 ORA-16120: dependencies being computed for transaction at SCN 0x0000.0002ed4e
APPLIER 191209 ORA-16124: transaction 1 16 1598 is waiting on another transaction
APPLIER 191205 ORA-16116: no work available
APPLIER 191206 ORA-16124: transaction 1 5 1603 is waiting on another transaction
APPLIER 191213 ORA-16117: processing
APPLIER 191212 ORA-16124: transaction 1 20 1601 is waiting on another transaction
APPLIER 191216 ORA-16124: transaction 1 4 1602 is waiting on another transaction


检查sql apply的整个处理过程。

 SQL> SELECT APPLIED_SCN, NEWEST_SCN FROM DBA_LOGSTDBY_PROGRESS;
APPLIED_SCN NEWEST_SCN
----------- ----------
180702 180702


如果备用重做日志文件没有配置,APPLIED_SCN 和NEWEST_SCN列的值是相等的,表明在归档重做日志文件中所有可用数据都被应用了。
这些值可以与DBA_LOGSTDBY_LOG视图中的FIRST_CHANGE#列的值比较,查看有多少日志文件信息被应用,多少剩余。 




赞(0)    操作        顶端 
联动大白
注册用户
等级:列兵
经验:91
发帖:0
精华:0
注册:2015-5-27
状态:离线
发送短消息息给联动大白 加好友    发送短消息息给联动大白 发消息
发表于: IP:您无权察看 2019-11-22 0:30:00 | [全部帖] [楼主帖] 2  楼

为了方便大家阅读,我对文章中错误号来解释一下吧!

Error Id: ORA-16254

Title: change db_name to string in the client-side parameter file (pfile)

Description:

change db_name to string in the client-side parameter file (pfile)

Action:

The client-side parameter file must be edited so that db_name is set to the given name before mounting the database again.

Cause:

An ALTER DATABASE RECOVER TO LOGICAL STANDBY new-dbname command was successfully executed without a server parameter file (spfile).


Error Id: ORA-16211

Title: unsupported record found in the archived redo log

Description:

unsupported record found in the archived redo log

Action:

1. Use DBMS_LOGSTDBY.INSTANTIATE_TABLE to re-create the table on the standby database or simply drop the table if it’s unimportant. 2. ALTER DATABASE START LOGICAL STANDBY APPLY; 3. Examine the current_scn column in the DBA_LOGSTDBY_EVENTS view to determine which log file contains the unsupported record. 4. Provide the log file to Oracle Support Services.

Cause:

Log apply services encountered a record in the archived redo log that could not be interpreted.


Error Id: ORA-16115

Title: %s\% of LogMiner dictionary loading is done

Description:

%s\% of LogMiner dictionary loading is done

Action:

No action necessary, this informational statement is provided to record the event for diagnostic purposes.

Cause:

The process is loading dictionary information from the redo stream. This activity may take a few minutes.


Error Id: ORA-16117

Title: processing

Description:

processing

Action:

No action necessary, this informational statement is provided to record the event for diagnostic purposes.

Cause:

The process is performing its primary function and is not waiting on any significant event.


Error Id: ORA-16116

Title: no work available

Description:

no work available

Action:

No action necessary, this informational statement is provided to record the event for diagnostic purposes.

Cause:

The process is idle waiting for additional changes to be made available.


Error Id: ORA-16124

Title: transaction string string string is waiting on another transaction

Description:

transaction string string string is waiting on another transaction

Action:

No action necessary, this informational statement is provided to record the event for diagnostic purposes.

Cause:

The apply process is waiting to apply additional changes. This transaction likely depends on another.


Error Id: ORA-16120

Title: dependencies being computed for transaction at SCN string

Description:

dependencies being computed for transaction at SCN string

Action:

No action necessary, this informational statement is provided to record the event for diagnostic purposes.

Cause:

The transaction committed at the given SCN is being analyzed for dependencies.


Error Id: ORA-16127

Title: stalled waiting for additional transactions to be applied

Description:

stalled waiting for additional transactions to be applied

Action:

No action necessary, this informational statement is provided to record the event for diagnostic purposes. If this message occurs often and changes are not being applied quickly, increase available SGA or the number of apply processes.

Cause:

This process is waiting for additional memory before continuing. Additional log information cannot be read into memory until more transactions have been applied to the database, thus freeing up additional memory.


Error Id: ORA-16126

Title: loading table or sequence string

Description:

loading table or sequence string

Action:

No action necessary, this informational statement is provided to record the event for diagnostic purposes.

Cause:

Information on the given table or sequence is being loaded into an in memory cache for future use.


Error Id: ORA-16130

Title: supplemental log information is missing from log stream

Description:

supplemental log information is missing from log stream

Action:

Issue the following command to enable supplemental logging. ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE INDEX) COLUMNS;

Cause:

Supplemental logging is not enabled at the primary database.


也许你已明白,但对一个人有用也是我存在的理由!^_^ By:持之以恒的大白

-- 来自: 北京联动北方科技有限公司



赞(0)    操作        顶端 
总帖数
2
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论