oracle Stream主从配置

2017-01-05 20:05:53来源:CSDN作者:u010123794人点击

--第一步:进行Stream前的参数配置(双机一致)
su - ora11g
mkdir /home/u02/oradata/arch
mkdir /home/u02/oradata/data
sqlplus / as sysdba;
SQL>alter system set aq_tm_processes=2 scope=both;
SQL>alter system set global_names=true scope=both;
SQL>alter system set job_queue_processes=20 scope=both;
SQL>alter system set parallel_max_servers=20 scope=both;
SQL>alter system set undo_retention=3600 scope=both;
SQL>alter system set nls_date_format='YYYY-MM-DD HH24:MI:SS' scope=spfile;
SQL>alter system set streams_pool_size=25M scope=spfile;
SQL>alter system set utl_file_dir='*' scope=spfile;
SQL>alter system set open_links=4 scope=spfile;
SQL>alter system set log_archive_dest='/home/u02/oradata/arch' scope=spfile;
SQL>alter system set log_archive_start=TRUE scope=spfile;
SQL>alter system set log_archive_format='arch%t_%s_%r.arc' scope=spfile;
--第二步:查看系统归档状态(双机一致)
SQL>archive log list
SQL>shutdown immediate
SQL>startup mount
SQL>alter database archivelog;
SQL>alter database open;
SQL>archive log list;
--第三步:创建Stream用户和表空间(双机一致)
SQL>create tablespace tbs_stream datafile '/home/u02/oradata/data/datatbs_stream01.dbf' size 100m autoextend on next 100m maxsize 1000m segment space management auto;
SQL>execute dbms_logmnr_d.set_tablespace('tbs_stream');
SQL>create user strmadmin identified by strmadmin default tablespace tbs_stream temporary tablespace temp;
SQL>grant connect,resource,dba,aq_administrator_role to strmadmin;
SQL>begin
dbms_streams_auth.grant_admin_privilege(
grantee => 'strmadmin',
grant_privileges => true);
end;
/
--第四步:配置各自双方的数据库连接
在source机器上添加dest数据源,名称为DEST
vi /home/u02/11g/network/admin/tnsnames.ora
DEST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.1.110)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME =dest)
)
)
在dest机器上添加source数据源,名称为SOURCE
vi /home/u02/11g/network/admin/tnsnames.ora
SOURCE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 10.10.1.111)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME =source)
)
)
--第五步:启用追加日志 (双机一致)
SQL>alter database add supplemental log data;
SQL>ALTER DATABASE ADD SUPPLEMENTAL LOG DATA (PRIMARY KEY, UNIQUE, FOREIGN KEY) COLUMNS;
--第六步:创建主数据库数据库链,以连接到从数据库
SQL>select * from global_name;    --查询从库
SQL>conn strmadmin/strmadmin;
SQL>create database link dest connect to strmadmin identified by strmadmin using 'dest'; --dest为上面的查询结果 'dest'为tnsnames中的别称
SQL>select * from tab@dest;
--第七步:创建从数据库数据库链,以连接到主数据库
SQL>select * from global_name;    --查询主库
SQL>conn strmadmin/strmadmin;
SQL>create database link orcl connect to strmadmin identified by strmadmin using 'orcl'; --source为上面的查询结果 'source'为tnsnames中的别称
SQL>select * from tab@orcl;
--第八步:创建Master 流队列 (主库)
SQL>connect strmadmin/strmadmin
SQL>begin
dbms_streams_adm.set_up_queue(
queue_table => 'orcl_queue_table',
queue_name => 'orcl_queue');
end;
/
--第九步:创建Backup 流队列(从库)
SQL>connect strmadmin/strmadmin
SQL>begin
dbms_streams_adm.set_up_queue(
queue_table => 'dest_queue_table',
queue_name => 'dest_queue');
end;
/
--第十步:增加用户步骤(双机一致)
SQL>CREATE TEMPORARY TABLESPACE cispac_temp TEMPFILE '/home/u02/oradata/data/cispac_temp01.dbf' SIZE 32M AUTOEXTEND ON NEXT 32M MAXSIZE 2048M EXTENT MANAGEMENT LOCAL;
SQL>CREATE TABLESPACE cispac LOGGING DATAFILE '/home/u02/oradata/data/cispac_data01.dbf' SIZE 32M AUTOEXTEND ON NEXT 32M MAXSIZE 2048M EXTENT MANAGEMENT LOCAL;
SQL>CREATE USER onccc IDENTIFIED BY admin123 DEFAULT TABLESPACE cispac TEMPORARY TABLESPACE cispac_temp;
SQL>GRANT CREATE SESSION, CREATE ANY TABLE, CREATE ANY VIEW ,CREATE ANY INDEX, CREATE ANY PROCEDURE, ALTER ANY TABLE, ALTER ANY PROCEDURE, DROP ANY TABLE, DROP ANY VIEW, DROP ANY INDEX, DROP ANY PROCEDURE, SELECT ANY TABLE, INSERT ANY TABLE, UPDATE ANY TABLE, DELETE ANY TABLE TO onccc;
SQL>GRANT CONNECT,RESOURCE TO onccc;
--第十一步:主数据库导出,从数据库导入 (初始化同步主库从库)
exp onccc/admin123@orcl file=/home/init.dmp object_consistent=y rows=y
scp ./init.dmp ora11g@10.6.104.237:/home
imp onccc/admin123@dest fromuser=onccc touser=onccc ignore=y commit=y file=/home/init.dmp streams_instantiation=y
--第十二步:在master 创建捕获进程 schema_name必须是用户名。
SQL>connect strmadmin/strmadmin
SQL>begin
dbms_streams_adm.add_schema_rules(
schema_name => 'onccc',
streams_type => 'capture',
streams_name => 'capture_orcl',
queue_name => 'strmadmin.orcl_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => null,
inclusion_rule => true);
end;
/
第十三步:在master 创建传播进程 (@dest 为 从库dblink的名字)
SQL>connect strmadmin/strmadmin
SQL> begin
dbms_streams_adm.add_schema_propagation_rules(
schema_name => 'onccc',
streams_name => 'orcl_to_dest',
source_queue_name => 'strmadmin.orcl_queue',
destination_queue_name => 'strmadmin.dest_queue@dest',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'orcl',
inclusion_rule => true);
end;
/
SQL>begin
dbms_aqadm.alter_propagation_schedule(
queue_name => 'orcl_queue',
destination => 'dest',
destination_queue => 'dest_queue',
latency => 5);
end;
/
第十四步:在Backup 创建应用进程 (source_database => 'source' 为主库dblink的名字)
SQL>connect strmadmin/strmadmin
SQL> begin
dbms_streams_adm.add_schema_rules(
schema_name => 'onccc',
streams_type => 'apply',
streams_name => 'apply_dest',
queue_name => 'strmadmin.dest_queue',
include_dml => true,
include_ddl => true,
include_tagged_lcr => false,
source_database => 'orcl',
inclusion_rule => true);
end;
/
第十五步:在Backup 启动Apply进程
SQL>connect strmadmin/strmadmin
SQL> begin
dbms_apply_adm.start_apply(
apply_name => 'apply_dest');
end;
/
第十六步:在Master 启动Capture进程
SQL>connect strmadmin/strmadmin
SQL>begin
dbms_capture_adm.start_capture(
capture_name => 'capture_orcl');
end;
/

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台