- 最后登录
- 2011-12-9
- 在线时间
- 0 小时
- 威望
- 0
- 金钱
- 60
- 注册时间
- 2011-12-9
- 阅读权限
- 10
- 帖子
- 9
- 精华
- 0
- 积分
- 0
- UID
- 102
|
1#
发表于 2011-12-9 15:15:39
|
查看: 11735 |
回复: 18
1.
环境介绍
目前两台服务器均安装Centos 6.0 64+TOMCAT 7.0 +Oracle 11g r2 64,这两天服务器的TOMCAT作为应用服务,通过LVS +Keepalived实现业务的HA自动切换,两台TOMCAT业务分别读写各自的Oracle数据库,为达到TOMCAT的HA切换后两个数局库保持一致,需要实现两个Oracle数据库的数据同步。
服务器1:mtcp1
服务器2:mtcp2
--oracle 流复制
1.第一步创建流管理员和复制过程中用到的表空间
create tablespace streams_tbs DATAFILE '/opt/oracle/oradata/streams_tbs01.dbf' size 100M REUSE Autoextend on maxsize unlimited;
2.创建流复制管理员
CREATE USER strmadmin IDENTIFIED BY strmadmin
DEFAULT TABLESPACE streams_tbs QUOTA UNLIMITED ON streams_tbs;
3.给流管理员赋权限
GRANT DBA TO strmadmin;
#授权Stream管理用户
grant connect,resource,dba,aq_administrator_role to strmadmin;
/
Grant DBA TO STRMADMIN;
begin
DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE('STRMADMIN');
end;
/
GRANT SELECT ANY DICTIONARY TO STRMADMIN;
grant insert any table TO STRMADMIN;
grant update any table TO STRMADMIN;
grant delete any table TO STRMADMIN;
grant select any table TO STRMADMIN;
grant alter any table TO STRMADMIN;
grant read on directory data_pump_dir to strmadmin;
grant write on directory data_pump_dir to strmadmin;
--检查授权
SELECT * FROM dba_streams_administrator;
-----页面配置时出错后搜权
execute MGMT_USER.MAKE_EM_USER
----
4.对两台数据库设置参数
-----------------
alter system set "_job_queue_interval"=1 scope=spfile;
alter system set global_names=true scope=spfile;
alter system set job_queue_processes=1000;
alter system set PARALLEL_MAX_SERVERS=40;
alter system set sga_target=0;
alter system set streams_pool_size=500M;
---
重新启动后方能生效
--------
设置oracle为归档模式
alter system set log_archive_dest_1=' location=/opt/oracle/oradata' scope=spfile;
alter system set log_archive_start=TRUE scope=spfile;
alter system set log_archive_format=' arch_%t-%s-%r.arc' scope=spfile;
shutdown immediate;
startup mount;
alter database archivelog;
alter database open;
---#将logminer的数据字典从system表空间转移到新建的表空间,防止撑满system表空间
execute dbms_logmnr_d.set_tablespace('streams_tbs');
---------------------------
5.追加日志
先检查追加日值日的属性
SELECT SCHEMA_NAME,
SUPPLEMENTAL_LOG_DATA_PK log_pk,
SUPPLEMENTAL_LOG_DATA_FK log_fk,
SUPPLEMENTAL_LOG_DATA_UI log_ui,
SUPPLEMENTAL_LOG_DATA_ALL log_all
FROM DBA_CAPTURE_PREPARED_SCHEMAS;
--追加日志
NAME
prepare_schema_instantiation()
FUNCTION
prepare a schema for instantiation
PARAMETERS
schema_name - (IN) the name of the schema to prepare
supplemental_logging - (IN) supplemental logging level
('NONE', 'KEYS', or 'ALL')
NOTES
KEYS means PRIMARY KEY, UNIQUE INDEX, and FOREIGN KEY levels combined.
----------------------------------------------------------------------------*/
PROCEDURE prepare_schema_instantiation(
schema_name IN VARCHAR2,
supplemental_logging IN VARCHAR2 DEFAULT 'KEYS');
--------------
6.在源库上创建到目标库strmadmin用户的database link:
--在mtcp1主机上
conn strmadmin/strmadmin;
Connected.
create database link orcl.mtcp2.com connect to strmadmin identified by strmadmin using 'orcl.mtcp2.com';
Database link created.
/* orcl.mtcp2.com 为目标库的全局数据库名,orcl为db_name,mtcp2.com为domain_name */
---在mtcp2主机上
conn strmadmin/strmadmin;
Connected.
create database link orcl.mtcp1.com connect to strmadmin identified by strmadmin
using 'orcl.mtcp1.com';
Database link created.
----------------------------------
---------------------------------
7.在源库中分别为capture(捕获)和apply(应用)创建队列queue:
begin
dbms_streams_adm.set_up_queue(
queue_table => 'apply_srctab',
queue_name => 'apply_src',
queue_user => 'strmadmin');
end;
/
PL/SQL procedure successfully completed.
begin
dbms_streams_adm.set_up_queue(
queue_table => 'capture_srctab',
queue_name => 'capture_src',
queue_user => 'strmadmin');
end;
/
PL/SQL procedure successfully completed.
-----------------------------------------------
在目标库分别为capture和apply创建队列queue:
conn [email=strmadmin/strmadmin@orcl.mtcp2.com]strmadmin/strmadmin@orcl.mtcp2.com[/email]
Connected.
begin
dbms_streams_adm.set_up_queue(
queue_table => 'apply_desttab',
queue_name => 'apply_dest',
queue_user => 'strmadmin');
end;
/
PL/SQL procedure successfully completed.
begin
dbms_streams_adm.set_up_queue(
queue_table => 'capture_desttab',
queue_name => 'capture_dest',
queue_user => 'strmadmin');
end;
/
PL/SQL procedure successfully completed.
================================================
在源库mtcp1上为gateway_yd模式创建创获进程 capture process:
conn [email=strmadmin/strmadmin@orcl.mtcp1.com]strmadmin/strmadmin@orcl.mtcp1.com[/email]
Connected.
begin
dbms_streams_adm.add_schema_rules(
schema_name => 'gateway_yd',
streams_type => 'capture',
streams_name => 'capture_src',
queue_name => 'capture_src',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => null,
inclusion_rule => true);
end;
/
PL/SQL procedure successfully completed.
9.在源库mtcp1上创建应用进程apply process
conn [email=strmadmin/strmadmin@orcl.mtcp1.com]strmadmin/strmadmin@orcl.mtcp1.com[/email]
Connected.
begin
dbms_streams_adm.add_schema_rules (
schema_name => 'gateway_yd',
streams_type => 'apply',
streams_name => 'applys_src',
queue_name => 'apply_src',
include_dml => true,
include_ddl => true,
source_database => 'orcl.mtcp1.com');
end;
/
PL/SQL procedure successfully completed.
10.在源库mtcp1上配置propagation process:
conn [email=strmadmin/strmadmin@orcl.mtcp1.com]strmadmin/strmadmin@orcl.mtcp1.com[/email]
Connected.
begin
dbms_streams_adm.add_schema_propagation_rules (
schema_name => 'gateway_yd',
streams_name => 'prop_src_to_dest',
source_queue_name => 'capture_src',
destination_queue_name => [email=]'apply_dest@orcl.mtcp2.com'[/email],
include_dml => true,
include_ddl => true,
source_database => 'orcl.mtcp1.com');
end;
/
-----出现错误
ERROR at line 1:
ORA-26723: user "STRMADMIN" requires the role "DV_STREAMS_ADMIN"
ORA-06512: at "SYS.DBMS_STREAMS_ADM_UTL_INVOK", line 349
ORA-06512: at "SYS.DBMS_STREAMS_ADM", line 439
ORA-06512: at "SYS.DBMS_STREAMS_ADM", line 397
ORA-06512: at line 2
---以sys用户再登陆后运行---
BEGIN
DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(
grantee => 'STRMADMIN',
grant_privileges => TURE);
END;
/
-----------------------
再次运行正常!!
------------------------
11.在目标库mtcp2上配置capture process:
conn [email=strmadmin/strmadmin@orcl.mtcp2.com]strmadmin/strmadmin@orcl.mtcp2.com[/email]
Connected.
begin
dbms_streams_adm.add_schema_rules(
schema_name => 'gateway_yd',
streams_type => 'capture',
streams_name => 'captures_dest',
queue_name => 'capture_dest',
include_dml => true,
include_ddl => true);
end;
/
---出错!
*
ERROR at line 1:
ORA-26723: user "STRMADMIN" requires the role "DV_STREAMS_ADMIN"
ORA-06512: at "SYS.DBMS_STREAMS_ADM_UTL_INVOK", line 349
ORA-06512: at "SYS.DBMS_STREAMS_ADM", line 439
ORA-06512: at "SYS.DBMS_STREAMS_ADM", line 397
ORA-06512: at line 2
-------------
---以sys用户再登陆后运行---
BEGIN
DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(
grantee => 'STRMADMIN',
grant_privileges => TURE);
END;
/
---------------------------------------------------
仍然出错
求高手帮忙看看如何解决!! |
|