使用maintain_global来配置一个单向的downstream capture的全库复制,目标库已经在。
|
源端(source database) |
目标端(destination database) |
|
Hostname |
Rhel63db |
Tan63rep |
|
Db_name |
Strmtan |
Strmdest |
|
Gblobal_name |
Strmtan |
Strmdest |
|
Instance_name |
Strmtan |
Strmdest |
|
Db_unique_name |
Strmtan |
Strmdest |
|
应当创建一个新用户和表空间,不应用sys,system用户,system系统表空间。
SQL> create tablespace streamtbs datafile
'/data01/apps/oracle/oradata/strmtan/streamtbs01.dbf' size 50m
autoextend on maxsize unlimited segment space management auto;
将logminer的数据字典从system分离,防止撑满system表空间
SQL> execute dbms_logmnr_d.set_tablespace('streamtbs');
SQL> create user strmadmin identified by strmadmin default tablespace streamtbs;
SQL> grant dba to strmadmin;
1. The DBA role is required for a user to create or altercapture processes, synchronous captures, and apply processes. When the user does not need to perform these tasks,DBA role can be revoked from the user.
用GRANT_ADMIN_PRIVILEGE给一些特有权限
BEGIN
DBMS_STREAMS_AUTH.GRANT_ADMIN_PRIVILEGE(
grantee => 'strmadmin',
grant_privileges => TRUE);
END;
/
网络配置已经做好,而且简单,不再做说明,只做database link部分
每个dblink必须用 streams administrator’s chema (就是前面创建的strmadmin)
源端(source database):
SQL> conn strmadmin/strmadmin
create database link strmdest connect to strmadmin
identified by strmadmin using 'strmdest';
Database link created.
目标端(destination database)
SQL> conn strmadmin/strmadmin
create database link strmtan connect to strmadmin
identified by strmadmin using 'strmtan';
检查
SQL> conn /as sysdba
Connected.
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/strmtan/arch1
Oldest online log sequence 1
Next log sequence to archive 2
源端和目标端都需要密码文件,目标端需要从源端拷贝。有了密码文件以及相应参数(remote_login_passwordfile)正确,就可以远程以sys用户登陆,此过程没有完成会影响日志文件的传输。
所有库都需要改的
alter system set aq_tm_processes=2 scope=both;
alter system set global_names=true scope=both;
alter system set undo_retention=3600 scope=both;
alter system set job_queue_processes=10 scope=both;
alter system set parallel_max_servers=20 scope=both;
alter system set nls_date_format='YYYY-MM-DD HH24:MI:SS' scope=spfile;
alter system set streams_pool_size=100M scope=spfile;
alter system set shared_pool_size=100m scope=both;
alter system set open_links=4 scope=spfile;
alter system set LOG_ARCHIVE_DEST_STATE_2=enable scope=both;
alter system set timed_statistics= TRUE scope=spfile;
alter system set LOG_ARCHIVE_CONFIG='DG_CONFIG=(strmtan,strmdest)' scope=both;
log_archive_dest_n
源端:
--real time log方式
Alter system set LOG_ARCHIVE_DEST_2='SERVICE=STRMDEST LGWR ASYNC OPTIONAL NOREGISTER VALID_FOR=(ONLINE_LOGFILE,PRIMARY_ROLE) DB_UNIQUE_NAME=STRMDEST' scope=both;
目标端
alter system set log_archive_dest_1='LOCATION=/u01/strmdest/arch1/ MANDATORY VALID_FOR=(ONLINE_LOGFILE,PRIMARY_ROLE)' scope=both;
Alter system set LOG_ARCHIVE_DEST_2='LOCATION=/u01/strmdest/arch2 MANDATORY VALID_FOR=(STANDBY_LOGFILE,PRIMARY_ROLE)' scope=both;
可以在Database级或table级启用supplemental log 。在table级别,确认schema下所有table都有合理的主键(Primary key),则不再需要启用追加日志
源端
database级
SQL> alter database add supplemental log data ;
源端:
SQL> select bytes from V$log;
52428800
察看redo log大小,设置的standby redo log 大小不能小于redo log 大小。
SQL> SELECT COUNT(GROUP#) FROM V$LOG;
3
确定downstream database的log file groups的id,至少为source database的n+1。downstream日志组的数量可以是一个或多个。
目标端:
SQL>ALTER DATABASE ADD STANDBY LOGFILE GROUP 4
('/data01/apps/oracle/oradata/strmdest/slog4.rdo',
'/data01/apps/oracle/oradata/strmdest/slog4b.rdo') SIZE 500M;
SQL> SELECT GROUP#, THREAD#, SEQUENCE#, ARCHIVED, STATUS
FROM V$STANDBY_LOG;
GROUP# THREAD# SEQUENCE# ARC STATUS
---------- ---------- ---------- --- ----------
4 0 0 YES UNASSIGNED
源端
alter system archive log current;
然后在目标端dest_2找相应的log文件,表明以上配置成功。
源端
conn strmadmin/strmadmin
create directory dir_source as '/u01/admin';
目标端:
conn strmadmin/strmadmin
create directory dir_dest as '/u01/admin';
conn strmadmin/strmadmin@strmdest
begin
DBMS_STREAMS_ADM.MAINTAIN_GLOBAL(
source_directory_object => 'dir_source ',
destination_directory_object => 'dir_dest ',
source_database => 'strmtan',
destination_database => 'strmdest',
perform_actions => true,
dump_file_name => 'streams_rep.dmp',
bi_directional => false,
include_ddl => true,
instantiation => DBMS_STREAMS_ADM.INSTANTIATION_FULL);
end;
/
等了将30分钟后出结果
PL/SQL procedure successfully completed.
SQL> create table test1(id number(10));
SQL> insert into test1 values(111);
SQL> commit;
Conn /as sysdba
SQL> alter system archive log current;
在源库的scott用户上执行了以上操作后,等待5分钟左右后,在目标库上找到了结果,说明目标库应用源库的DDL操作和DML操作。