標籤:
環境:
Windows 2008 伺服器,Oracle 11g r2 資料庫
任務要求:
有三個資料庫執行個體,一個執行個體供管理子系統使用,一個執行個體供利用子系統使用,還有一個執行個體專門做備份。
選擇的技術:
Oracle Stream Replication(流複製)
建立另外兩個執行個體
源執行個體:orcl
目標1:target
目標2:target2
停止應用伺服器,防止使用者因為使用應用伺服器而對資料庫做出的改變。
並匯出 orcl 執行個體中使用者的資料,用 exp 命令
例如 exp nt_gxt/[email protected] file=E:\nt_gxt_201508140923.dmp
環境設定
使用命令列登入資料庫
sqlpus sys/[email protected] as sysdbaalter 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=512M scope=spfile;alter system set utl_file_dir=‘*‘ scope=spfile;alter system set open_links=4 scope=spfile;
--下面為設定歸檔模式的命令:(注意:修改路徑)
alter system set log_archive_dest_1=‘location=E:\DevProgramsFile\Oracle\archive\target‘ 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;
(如果startup mount報如上錯誤,需要對執行個體進行靜態註冊,在listener.ora檔案中添加如下內容,並重新啟動監聽服務)
alter database archivelog;alter database open;--如果要查看歸檔模式是否設定成功可以用命令:archive log list --如果出現如下內容則說明設定成功,
8. 建立 stream 系統管理使用者
1). 建立主環境系統管理使用者
Sqlplus sys/[email protected] as sysdba#建立主環境的 stream 專用資料表空間(注意修改路徑)create tablespace tbs_stream datafile ‘E:\DevProgramsFile\Oracle\oradata\orcl\tbs_stream01.dbf‘ size 100m autoextend on maxsize unlimited segment space management auto;#將logminer的資料字典從system資料表空間轉移到建立的資料表空間,防止撐滿system資料表空間execute dbms_logmnr_d.set_tablespace(‘tbs_stream‘);#建立Stream系統管理使用者 create user strmadmin identified by strmadmin default tablespace tbs_stream temporary tablespace temp; #授權Stream系統管理使用者grant connect,resource,dba,aq_administrator_role to strmadmin;begindbms_streams_auth.grant_admin_privilege(grantee => ‘strmadmin‘,grant_privileges => true);end;/
2). 建立從環境的 stream 系統管理使用者
Sqlplus sys/[email protected] as sysdba#建立Stream專用資料表空間create tablespace tbs_stream datafile ‘E:\DevProgramsFile\Oracle\oradata\target\tbs_stream01.dbf‘ size 100m autoextend on maxsize unlimited segment space management auto;#同樣,將logminer的資料字典從system資料表空間轉移到建立的資料表空間,防止撐滿system資料表空間 execute dbms_logmnr_d.set_tablespace(‘tbs_stream‘);#建立Stream系統管理使用者 create user strmadmin identified by strmadmin default tablespace tbs_stream temporary tablespace temp;#授權Stream系統管理使用者 grant connect,resource,dba,aq_administrator_role to strmadmin;begindbms_streams_auth.grant_admin_privilege(grantee => ‘strmadmin‘,grant_privileges => true);end;/
3). 建立 DBlink
3.1) 建立主要資料庫資料鏈
根據Oracle 10gR2 Stream官方文檔,針對主要資料庫建立的資料庫鏈的名字必須和從資料庫的global_name
相同。如果需要修改global_name,執行“alter database rename global_name to xxx”。
#以strmadmin身份,登入主要資料庫。Sqlplus strmadmin/[email protected]create database link target connect to strmadmin identified by strmadmin using ‘target‘;create database link target2 connect to strmadmin identified by strmadmin using ‘target2‘;
3.2)建立從資料庫的資料鏈
#以strmadmin身份,登入從資料庫。Sqlplus strmadmin/[email protected]create database link orcl connect to strmadmin identified by strmadmin using ‘orcl‘;
4). 啟動歸檔日誌
alter database add supplemental log data;
8. 使用oracle內建的管理器來建立流複製相關的進程
1). 啟動orcl 執行個體的dbconsole
2). 點擊 Database Control – orcl, 啟動em
3). 在開啟的瀏覽器視窗中用 strmadmin 使用者登入
4). 點擊資料移動
5). 選擇 ‘流’ – ‘設定‘
6). 選擇 複製方案,下面的主機身份證明輸入電腦系統管理員的使用者名稱和密碼,並勾選另存新檔首選身份證明。
然後點擊繼續。
7). 在包含方案中選擇館系統使用者(我的是 nt_gxt)
8). 進行配置
9). 設定立即啟動
10). 如果最後一步提交時報如下錯誤
執行語句(execute MGMT_USER.MAKE_EM_USER(‘STRMADMIN‘);),用系統使用者登入orcl執行個體執行。
已同樣的方法為target2建立進程。實現多執行個體即時同步。
注意:
11g資料庫空表匯出問題。
Sql代碼
查看
show parameter deferred_segment_creation;
修改
alter system set deferred_segment_creation=false;
三個執行個體都完成後,服務啟動情況,
最後一張oracle原理圖
oracle資料庫多執行個體即時同步(利用oracle管理平台實現)