Oracle stream容災的配置,oraclestream容災

來源:互聯網
上載者:User

Oracle stream容災的配置,oraclestream容災
Oracle stream流複製的配置

配置:主庫 100.100.100.20  linux系統,  資料庫執行個體名db1  版本10.2.0.1

                  備庫 100.100.100.254 windows系統資料庫名     dbwin2版本10.2.0.1

過程為:備庫捕捉主庫 u1使用者下所有表的變化,即時同步

1.1 主庫的配置1.1.1 主庫oracle參數配置

alter system set aq_tm_processes=2 scope=both;

alter system set global_names=true scope=both;

alter system set job_queue_processes=10 scope=both;

alter system set parallel_max_servers=20 scope=both;

alter system set undo_retention=3600 scope=both;

alter system set nls_date_format='YYYY-MM-DD HH24:MI:SS' scope=spfile;

 

#自動分配

alter system set streams_pool_size=25M scope=spfile;

alter system set utl_file_dir='*' scope=spfile;

alter system set open_links=4 scope=spfile;

 

開啟歸檔日誌

1.1.2 主庫建立stream系統管理使用者

第一步, 建立streams系統管理使用者資料表空間stream_tbs

SQL>  create tablespace stream_tbs datafile '/home/oracle/oradata/db3/stream01.dbf'

  2  size 200m

  3  autoextend on      

  4  extent management local;

 

第二步,建立stream系統管理使用者(例子中為了簡化名稱,設定為test),為了簡化賦予DBA許可權。

create user test identified by test default tablespace stream_tbs;

SQL> grant dba to test;

 

第三步,將logminer的資料字典從system資料表空間轉移到建立的資料表空間stream_tbs

System使用者執行

SQL> execute dbms_logmnr_d.set_tablespace('stream_tbs');

 

第四步、授權test使用者為stream管理員(system使用者執行)

SQL> begin 

dbms_streams_auth.grant_admin_privilege(

grantee => 'test',

grant_privileges => true);

end;

 /

1.1.3 主庫建立dblink和配置主庫的TNS網路

第一步,在主庫(db1)中建立備庫(dbwin2)的dblink(stream系統管理使用者test建立)

Connect test/test

create database link dbwin2 connect to test identified by test using 'dbwin2';

 

第二步,配置主庫的TNS網路,加上備庫(dbwin2)的tns名稱

db1 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 100.100.100.20)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = db1)

    )

  )

 

dbwin2 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 100.100.100.254)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = dbwin2)

    )

  )

1.1.4 主庫建立master流隊列

使用stream系統管理使用者test建立流隊列db1_queue,隊列資訊的表名稱為db1_queue_table

SQL> connect test/test

begin

dbms_streams_adm.set_up_queue(

queue_table => 'db1_queue_table',

queue_name => 'db1_queue');

end;

 /

1.1.5 主庫建立捕獲進程

使用stream系統管理使用者test建立捕獲進程capture_db1,捕獲主庫u1(schema_name => 'u1',

指定)使用者表的變化,將變化資訊傳給master隊列test.db1_queue(如上一步)

connect test/test

begin

dbms_streams_adm.add_schema_rules(

schema_name => 'u1',

streams_type => 'capture',

streams_name => 'capture_db1',

queue_name => 'test.db1_queue',

include_dml => true,

include_ddl => true,

include_tagged_lcr => false,

source_database => null,

inclusion_rule => true);

end;

/

1.1.6 主庫建立傳播進程

第一步,使用stream管理使用者 test建立傳播進程db1_to_dbwin2,將捕獲主庫變化的master隊列(test.db1_queue)傳給備庫的backup隊列(test.dbwin2_queue,建立過程見下一章)。

重點參數為:destination_queue_name => 'test.dbwin2_queue@dbwin2',(備庫dbwin2的backup隊列.dbwin2_queue),source_queue_name => 'test.db1_queue'主庫的記錄表變化資訊的mater隊列db1_queue

 

connect test/test

 

begin

dbms_streams_adm.add_schema_propagation_rules(

schema_name => 'u1',

streams_name => 'db1_to_dbwin2',

source_queue_name => 'test.db1_queue',

destination_queue_name => 'test.dbwin2_queue@dbwin2',

include_dml => true,

include_ddl => true,

include_tagged_lcr => false,

source_database => 'db1',

inclusion_rule => true);

end;

第二步,修改propagation休眠時間為0,表示即時傳播LCR。

begin

dbms_aqadm.alter_propagation_schedule(

queue_name => 'db1_queue',

destination => 'dbwin2',

latency => 0);

end;

1.2 備庫的配置1.2.1 備庫oracle參數配置

alter system set aq_tm_processes=2 scope=both;

alter system set global_names=true scope=both;

alter system set job_queue_processes=10 scope=both;

alter system set parallel_max_servers=20 scope=both;

alter system set undo_retention=3600 scope=both;

alter system set nls_date_format='YYYY-MM-DD HH24:MI:SS' scope=spfile;

 

#自動分配

alter system set streams_pool_size=25M scope=spfile;

alter system set utl_file_dir='*' scope=spfile;

alter system set open_links=4 scope=spfile;

 

開啟歸檔日誌

1.2.2 備庫建立stream系統管理使用者

第一步, 建立streams系統管理使用者資料表空間stream_tbs

SQL>  create tablespace stream_tbs datafile '/home/oracle/oradata/db3/stream01.dbf'

  2  size 200m

  3  autoextend on      

  4  extent management local;

 

第二步,建立stream系統管理使用者(例子中為了簡化名稱,設定為test),為了簡化賦予DBA許可權。

create user test identified by test default tablespace stream_tbs;

SQL> grant dba to test;

 

第三步,將logminer的資料字典從system資料表空間轉移到建立的資料表空間stream_tbs

System使用者執行

SQL> execute dbms_logmnr_d.set_tablespace('stream_tbs');

 

第四步、授權test使用者為stream管理員(system使用者執行)

SQL> begin 

dbms_streams_auth.grant_admin_privilege(

grantee => 'test',

grant_privileges => true);

end;

 /

1.2.3 備庫建立dblink和配置備庫的TNS網路

第一步,在備庫(dbwin2)中建立主庫(db1)的dblink(stream系統管理使用者test建立)

Connect test/test

create database link db1 connect to test identified by test using 'db1';

 

第二步,配置備庫(dbwin2)的TNS網路,加上主庫(db1)的tns名稱

db1 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 100.100.100.20)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = db1)

    )

  )

 

dbwin2 =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = 100.100.100.254)(PORT = 1521))

    (CONNECT_DATA =

      (SERVER = DEDICATED)

      (SERVICE_NAME = dbwin2)

    )

  )

1.2.4 備庫建立backup流隊列

使用stream系統管理使用者test建立流隊列dbwin2_queue,儲存隊列新表名稱為dbwin2_queue_table

 

SQL> connect test/test

SQL> connect test/test

begin

dbms_streams_adm.set_up_queue(

queue_table => 'dbwin2_queue_table',

queue_name => 'dbwin2_queue');

end;

 /

註:

                在主庫的傳播進程db1_to_dbwin2中,將主庫中記錄變化的master隊列db1_queue資訊傳播到備庫的backup隊列dbwin2_queue,配置截取如下:

source_queue_name => 'test.db1_queue',

destination_queue_name => 'test.dbwin2_queue@dbwin2',

 

1.2.5 備庫配置apply進程

使用stream系統管理使用者test建立備庫應用進程apply_dbwin2,同步到備庫U1使用者的表中

 

connect test/test

begin

dbms_streams_adm.add_schema_rules(

schema_name => 'u1',

streams_type => 'apply',

streams_name => 'apply_dbwin2',

queue_name => 'test.dbwin2_queue',

include_dml => true,

include_ddl => true,

include_tagged_lcr => false,

source_database => 'db1',

inclusion_rule => true);

end;

  /

1.3 oracle stream的啟動停止1.3.1 oracle stream的啟動和監控

第一步,備庫使用stream系統管理使用者test啟動apply進程

Connect test/test

begin

dbms_apply_adm.start_apply(

apply_name => 'apply_dbwin2');

end;

/

第二步,主庫使用stream系統管理使用者test啟動capture進程

Connect test/test

begin

dbms_capture_adm.start_capture(

capture_name => 'capture_db1');

end;

第三步,備庫監控apply進程為enable

SQL> select apply_name,queue_name,status from dba_apply;

 

APPLY_NAME                    QUEUE_NAME                     STATUS

------------------------------ ------------------------------ --------

APPLY_DBWIN2                   DBWIN2_QUEUE                   ENABLED

第四步,主庫監控capture進程為enable

SQL> SELECT capture_name, capture_type, status, status_change_time, queue_name, captured_scn, applied_scn, error_message FROM DBA_CAPTURE;

 

CAPTURE_NAME                  CAPTURE_TYPE STATUS   STATUS_CHANGE_TIME QUEUE_NAME                     CAPTURED_SCN APPLIED_SCN ERROR_MESSAGE

------------------------------ ------------ -------- ------------------ ------------------------------ ------------ ----------- --------------------------------------------------------------------------------

CAPTURE_DB1                    LOCAL        ENABLED  2014/9/23 13:04:57 DB1_QUEUE                            735788      735788

1.3.2 oracle stream的停止

第一步,主庫關閉capture進程,srream系統管理使用者

Connect test/test

begin

dbms_capture_adm.stop_capture(

capture_name => 'capture_db1');

end;

第二步,備庫關閉apply進程,sream系統管理使用者

begin

dbms_apply_adm.stop_apply(

apply_name => 'apply_dbwin2');

end;

1.4 oracle stream的測試

主庫建表

SQL> create table u3(id3 number(10));

 

Table created

 

SQL> commit;

Commit complete

備庫檢查

SQL> select * from u3;

 

        ID3

-----------

 

主庫插入記錄

SQL> insert into u3 values(3);

 

1 row inserted

 

SQL> commit;

 

Commit complete

 

備庫檢查

 

SQL> select * from u3;

 

        ID3

-----------

          3

 


oracle 自身的dataguard用於容災備份是不錯,但是配置比較麻煩,而且需要專門的DBA進行維護,

dataguard已經不是什麼新技術了,技術成熟使用廣泛,維護成本也很低。
既然資料要做容災,說明資料是比較重要的,管理重要資料的Oracle不配個DBA似乎也說不過去吧。
可視化的容災備份可以用Oracle grid control,用這個東西來配置和管理dataguard非常方便。
 
oracle中的容災到底指的是什?

1、容災(Disaster Tolerance),搜搜容災吧,沒必要copy過來給你。
總之為了保持商務持續性,資料庫出現災難要能儘快恢複或有備用的能立刻頂上。
2、oracle提供完備容災解決方案和高可用性HA(High Availability),比如:
a) 冷備份imp/exp功能
b) DataGuard功能
c) RAC(Real Application Cluster)功能
d)進階複製(AdvanceRepication)
e)oracle流(Oracle Streams)
f) 分區(Oracle Partition)
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.