Oracle Stream
配置
环境:
OS:Redhat Linux
Oracle 10.2.0 .4
source:TEST
destnation:STANDBY
==
准备==
1.
归档日志配置:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/archivelog
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /home/oracle/archivelog
---
以下没有专门说明的都是sys用户---
2.
在源stream1上配置Supplemental loging:
在源上:
SQL> alter database add supplemental log data;
Database altered.
3.
两台机器上修改global_name:
stream1:
SQL> alter system set global_names=true scope=both;
SQL> alter database rename global_name to TEST.com;
stream2:
SQL> alter system set global_names=true scope=both;
SQL> alter database rename global_name to STANDBY.com;
4.
修改初始化参数:
参考官方文档确定需要来检查和设定参数
5.
创建stream管理用户并表空间,配置权限,source和dest:
5.1
为strmadmin用户创建独立表空间
TEST:
SQL> CREATE TABLESPACE streams_tbs DATAFILE '/oradata/TEST/streams_tbs.dbf'
SIZE 25M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
Tablespace created.
STANDBY:
SQL> CREATE TABLESPACE streams_tbs DATAFILE '/oradata/STANDBY/streams_tbs.dbf'
SIZE 25M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;
Tablespace created.
5.2 source
和dest创建相同用户和权限:
SQL> CREATE USER strmadmin IDENTIFIED BY strmadminpw
DEFAULT TABLESPACE streams_tbs
QUOTA UNLIMITED ON streams_tbs;
User created.
SQL> GRANT DBA TO strmadmin;
Grant succeeded.
SQL> BEGIN
2 DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(
3 grantee => 'strmadmin',
4 grant_privileges => true);
5 END;
6 /
PL/SQL procedure successfully completed.
6.
配置listener.ora和tnsnames.ora保证:
TEST 上:
sqlplus strmadmin/strmadminpw@STANDBY
STANDBY 上:
sqlplus strmadmin/strmadminpw@TEST
能够连通
---如果没有说明以下都是
strmadmin/strmadminpw 用户
---
7.
创建DB link:
单向复制之需要一个
database link即
source 到
dest:TEST-->STANDBY
TEST上:
sqlplus strmadmin/strmadminpw
SQL> CREATE DATABASE LINK STANDBY.com CONNECT TO strmadmin IDENTIFIED BY strmadminpw USING 'STANDBY';
GLOBAL_NAME
-----------------------------------------
STANDBY.com
==
开始stream的配置===
8. source
和dest 创建队列:
TEST,STANDBY都要创建
SQL> EXEC DBMS_STREAMS_ADM.SET_UP_QUEUE();
PL/SQL procedure successfully completed.
上面命令会创建一个队列缺省名:
streams_queue,队列表缺省是:
STREAMS_QUEUE_TABLE
队列存储的
object类型是
anaydata
可以用查询
dba_queues,dba_queue_tables来检查:
SQL> select owner,queue_table,name from dba_queues where owner='STRMADMIN';
OWNER QUEUE_TABLE NAME
---------------- ---------------------------------- ---------------------------------------------
STRMADMIN STREAMS_QUEUE_TABLE STREAMS_QUEUE
STRMADMIN STREAMS_QUEUE_TABLE AQ$_STREAMS_QUEUE_TABLE_E
SQL> select owner,queue_table,object_type from dba_queue_tables where owner='STRMADMIN';
OWNER QUEUE_TABLE OBJECT_TYPE
----------------- --------------------------------- -------------------------------
STRMADMIN STREAMS_QUEUE_TABLE SYS.ANYDATA
9.
在source: TEST上创建Stream propagation:
SQL> BEGIN
1 DBMS_STREAMS_ADM.ADD_SCHEMA_PROPAGATION_RULES(
2 schema_name => 'scott',
3 streams_name => 'TEST_to_STANDBY',
4 source_queue_name => 'strmadmin.streams_queue',
5 destination_queue_name => '[email protected] ',
6 include_dml => true,
7 include_ddl => true,
8 source_database => 'TEST.com',
9 inclusion_rule => true,
10 queue_to_queue => true);
11 END;
12 /
PL/SQL procedure successfully completed.
可以通过
dba_propagations查看结果:
SQL> select PROPAGATION_NAME,SOURCE_QUEUE_NAME,DESTINATION_QUEUE_NAME,DESTINATION_DBLINK,STATUS from dba_propagation;
PROPAGATION_NAME SOURCE_QUEUE_NAME DESTINATION_QUEUE_NAME DESTINATION_DBL STATUS
-------------------------------- ------------------------------ --------------------------------- --------------- --------
STREAM1_TO_STREAM2 STREAMS_QUEUE STREAMS_QUEUE STANDBY.COM ENABLED
9.
在source: TEST上创建Capture进程:
SQL> BEGIN
2 DBMS_STREAMS_ADM.ADD_SCHEMA_RULES(
3 schema_name => 'scott',
4 streams_type => 'capture',
5 streams_name => 'capture_TEST',
6 queue_name => 'strmadmin.streams_queue',
7 include_dml => true,
8 include_ddl => true,
9 inclusion_rule => true);
10 END;
11 /
PL/SQL procedure successfully completed.
可将hr改为scott
可以通过
dba_capture查看:
SQL> select CAPTURE_NAME,QUEUE_NAME,START_SCN,STATUS,CAPTURE_TYPE from dba_capture;
CAPTURE_NAME QUEUE_NAME START_SCN STATUS CAPTURE_TY
---------------------------- -------------------------- --------------- ------------ ----------
CAPTURE_STREAM1 STREAMS_QUEUE 504733 DISABLED LOCAL
SQL> select * from ALL_CAPTURE_PREPARED_SCHEMAS;
SCHEMA_NAME TIMESTAMP SUPPLEME SUPPLEME SUPPLEME SUPPLEME
-------------------- --------------- -------------- -------------- ------------- --------
HR 12-JUN-08 IMPLICIT IMPLICIT IMPLICIT NO
10.
将TEST上的scott schema数据导到STANDBY上:
在
stream2上:
可先将
scott用户删除
drop user scott cascade;
sqlplus strmadmin/strmadminpw
SQL> create public database link TEST.com connect to strmadmin identified by strmadminpw using 'TEST';
Database link created.
GLOBAL_NAME
------------------------------------------------------
TEST
导数据:
[oracle@localhost admin]$ impdp strmadmin/strmadminpw network_link=TEST.com schemas=scott
Import: Release 10.2.0 .2.0 - Production on Thursday, 12 June, 2008 17:47:59
Copyright (c) 2003, 2005, Oracle. All rights reserved.
.....
......
Processing object type SCHEMA_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
Job "SYSTEM"."SYS_IMPORT_SCHEMA_01" successfully completed at 17:50:32
遇到的问题:在导数据时发现导完后两边的表不一致,后发现在STANDBY从库上有scott用户及相关联的表,可使用命令drop user scott cascade 删除scott用户,再进行导数据即可解决此问题。
11.
在TEST上设置STANDBY上scott schema的Instantiation SCN
sqlplus strmadmin/strmadminpw
SQL> DECLARE
2 iscn NUMBER;
3 BEGIN
4 iscn := DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER();
5 [email protected](
6 source_schema_name => 'scott',
7 source_database_name => 'TEST.com',
8 instantiation_scn => iscn,
9 recursive => true);
10 END;
11 /
PL/SQL procedure successfully completed.
12.
在STANDBY上创建apply进程apply_STANDBY:
SQL> BEGIN
2 DBMS_STREAMS_ADM.ADD_SCHEMA_RULES(
3 schema_name => '',
4 streams_type => 'apply',
5 streams_name => 'apply_STANDBY',
6 queue_name => 'strmadmin.streams_queue',
7 include_dml => true,
8 include_ddl => true,
9 source_database => 'TEST.com',
10 inclusion_rule => true);
11 END;
12 /
PL/SQL procedure successfully completed.
可以通过:
dba_apply
v$streams_apply_reader
v$streams_apply_coordinator
v$streams_apply_server
查看状态
SQL> select apply_name,queue_name,status from dba_apply;
APPLY_NAME QUEUE_NAME STATUS
--------------------- ------------------------ --------
APPLY_STREAM2 STREAMS_QUEUE DISABLED
==
启动==
13.
启动capture和apply:
13.1 STANDBY
上启动 Apply Process
CONNECT strmadmin/strmadminpw
SQL> BEGIN
2 DBMS_APPLY_ADM.SET_PARAMETER(
3 apply_name => 'apply_STANDBY',
4 parameter => 'disable_on_error',
5 value => 'n');
6 END;
7 /
PL/SQL procedure successfully completed.
SQL> BEGIN
2 DBMS_APPLY_ADM.START_APPLY(
3 apply_name => 'apply_STANDBY');
4 END;
5 /
PL/SQL procedure successfully completed.
SQL> select apply_name,queue_name,status from dba_apply;
APPLY_NAME QUEUE_NAME STATUS
------------------------------ -------------------------- --------
APPLY_STREAM2 STREAMS_QUEUE ENABLED
这时候
alert log有:
Thu Jun 12 18:00:36 2008
Streams APPLY A001 started with pid=25, OS id=30819
Streams Apply Reader started P000 with pid=26 OS id=30821
Streams Apply Server started P001 with pid=27 OS id=30823
如果有问题,没有能启动就查dba_apply的error_messages列
13.2 TEST
上启动capture process:
sqlplus strmadmin/strmadminpw
SQL> BEGIN
2 DBMS_CAPTURE_ADM.START_CAPTURE(
3 capture_name => 'capture_stream1');
4 END;
5 /
PL/SQL procedure successfully completed.
SQL> select capture_name,status from dba_capture;
CAPTURE_NAME STATUS
------------------------------ ------------
CAPTURE_STREAM1 ENABLED
alert 日志有:
Thu Jun 12 18:04:46 2008
Streams CAPTURE C001 started with pid=27, OS id=11884
Thu Jun 12 18:04:49 2008
LOGMINER: Parameters summary for session# = 1
LOGMINER: Number of processes = 3, Transaction Chunk Size = 1
LOGMINER: Memory Size = 10M , Checkpoint interval = 10M
LOGMINER: session# = 1, builder process P001 started with pid=32 OS id=11966
LOGMINER: session# = 1, reader process P000 started with pid=29 OS id=11964
LOGMINER: session# = 1, preparer process P002 started with pid=33 OS id=11968
Thu Jun 12 18:04:53 2008
LOGMINER: Begin mining logfile: /u01/oradata/stream1_arch/1_13_657197948.dbf
Thu Jun 12 18:06:40 2008
Thread 1 advanced to log sequence 15
Current log# 2 seq# 15 mem# 0: /u01/oradata/stream1/redo02.log
Thu Jun 12 18:06:53 2008
Thread 1 advanced to log sequence 16
Current log# 3 seq# 16 mem# 0: /u01/oradata/stream1/redo03.log
...
LOGMINER: Begin mining logfile: /u01/oradata/stream1_arch/1_13_657197948.dbf
Thu Jun 12 18:07:34 2008
LOGMINER: End mining logfile: /u01/oradata/stream1_arch/1_13_657197948.dbf
Thu Jun 12 18:07:34 2008
LOGMINER: Begin mining logfile: /u01/oradata/stream1_arch/1_14_657197948.dbf
信息,说明已经开始
mining logfile.
===
测试===
14.
测试
在
TEST上:
SQL> conn scott/tiger
SQL> select employee_id,salary from employees where employee_id=197;
EMPLOYEE_ID SALARY
-------------- ----------
197 3000
SQL> update employees set salary=salary+1 where employee_id=197;
1 row updated.
SQL> commit;
Commit complete.
STANDBY 上检查结果
(可能有延迟
):
SQL> conn scott/tiger
Connected.
SQL> select employee_id,salary from employees where employee_id=197;
EMPLOYEE_ID SALARY
----------------- ----------
197 3001
这个时间间隔跟性能及其它情况有关,包括
capture mining logfile 的速度
propagation 的间隔
(默认
3秒
)及传输时间
apply log 的速度
问题诊断
5.1
如何知道捕捉
(Capture)
进程是否运行正常?
以
strmadmin
身份,登录主数据库,执行如下语句:
SQL> SELECT CAPTURE_NAME,
2 QUEUE_NAME,
3 RULE_SET_NAME,
4
NEGATIVE_RULE_SET_NAME,
5 STATUS
6 FROM DBA_CAPTURE;
结果显示如下:
CAPTURE_NAME QUEUE_NAME
------------------------------ ------------------------------
RULE_SET_NAME NEGATIVE_RULE_SET_NAME STATUS
------------------------------ ------------------------------ --------
CAPTURE_PROD PROD_QUEUE
RULESET$_14 ENABLED
ENABLED
如果
STATUS
状态是
ENABLED
,表示
Capture
进程运行正常;
如果
STATUS
状态是
DISABLED
,表示
Capture
进程处于停止状态,只需重新启动即可;
如果
STATUS
状态是
ABORTED
,表示
Capture
进程非正常停止,查询相应的
ERROR_NUMBER
、
ERROR_MESSAGE
列可以得到详细的信息;同时,
Oracle
会在跟踪文件中记录该信息。
5.2
如何知道
Captured LCR
是否有传播
GAP
?
以
strmadmin
身份,登录主数据库,执行如下语句:
SQL> SELECT CAPTURE_NAME, QUEUE_NAME, STATUS, CAPTURED_SCN, APPLIED_SCN
2 FROM DBA_CAPTURE;
结果显示如下:
CAPTURE_NAME QUEUE_NAME STATUS
------------------------------ ------------------------------ --------
CAPTURED_SCN APPLIED_SCN
------------ -----------
CAPTURE_PROD PROD_QUEUE ENABLED
17023672 17023672
如果
APPLIED_SCN
小于
CAPTURED_SCN
,则表示在主数据库一端,要么
LCR
没有被
dequeue
,要么
Propagation
进程尚未传播到从数据库一端。
5.3
如何知道
Appy
进程是否运行正常?
以
strmadmin
身份,登录从数据库,执行如下语句:
SQL> SELECT apply_name, apply_captured, status FROM dba_apply;
结果显示如下:
APPLY_NAME APPLY_ STATUS
---------------------- ------ ----------------
APPLY_H10G YES ENABLED
如果
STATUS
状态是
ENABLED
,表示
Apply
进程运行正常;
如果
STATUS
状态是
DISABLED
,表示
Apply
进程处于停止状态,只需重新启动即可;
如果
STATUS
状态是
ABORTED
,表示
Apply
进程非正常停止,查询相应的
ERROR_NUMBER
、
ERROR_MESSAGE
列可以得到详细的信息;同时,可以查询
DBA_APPLY_ERROR
视图,了解详细的
Apply
错误信息。
本文出自 “理想CTO” 博客,谢绝转载!