標籤:容災備份 tde 需要 執行 png bytes admin com dmi
安裝 Oracle
安裝 Oracle11g 32位【Oracle 32位的話,OGG 也必須是 32位,否則會有0xc000007b無法正常啟動 錯誤】 安裝目錄為 D:\oracle\product\11.1.0\db1 【這個目錄要設定為 環境變數 ORACLE_HOME】
設定環境變數
JAVAHOME C:\Program Files\Java\jdk1.8.0121
ORACLEHOME D:\oracle\product\11.1.0\db1
ORACLE_SID ORCL
如何尋找環境變數
擷取 ORACLESID : 開啟 SQLPlus,登入 SYS 賬戶,執行 select instancename from v$instance;
擷取 ORACLEHOME : 尋找 Oracle安裝目錄,這個目錄有個特徵:有一個子目錄名叫 RDBMS。就是說: %ORACLEHOME%\RDBMS\ 這個路徑要能正常開啟即為配置成功。
安裝 OGG
http://www.oracle.com/technetwork/cn/middleware/goldengate/downloads/index.html 拖到頁面最後面
搜尋 32位的 Oracle_11g 的 OGG
目標1
給安裝的Oracle_11g 建立 兩個使用者 admin 和 root 。
admin 對應了 ADMIN 結構,建立了一個 TB_ TEST表。
root 對應了 ROOT 結構,也建立一個 TB_ TEST (表結構一摸一樣)。
當 admin.TBTEST 中的表資料 變化時,root.TB TEST 的表資料 自動同步(備份)
PS. 實際的 容災備份,肯定是 兩個 Oracle 伺服器,通過網路傳輸 備份資料 —— 各位可以想象 admin 和 root 在兩台不同伺服器 上。
目標2
設定資料庫開啟 SQL Plus
SYS登入
啟用日誌存檔模式:
啟用強制記錄模式:
啟用 SUPPLEME:
關閉源端資料庫資源回收筒:
切換一下日誌,最好還能重啟一下 資料庫服務 —— 或者重啟一下系統:
建立使用者,授權DBA許可權(可以自己摸索OGG的最低許可權)。
建立資料表
開始配置 OGG
按順序 輸入如下指令:
> create subdirs
> edit param mgr
往記事本中,寫入 如下內容,儲存關閉:
PORT 7809
DYNAMICPORTLIST 7840-7850
> start mgr
> dblogin userid admin password admin
> add trandata admin.*
> add extract ext1, tranlog, begin now
> edit param ext1
填寫如下配置:
extract ext1
userid admin,password oracle
rmthost 127.0.0.1, mgrport 7809
rmttrail D:\oracle\product\11.1.0\x86_ogg4oracle\dirdat\r1
dynamicresolution
gettruncates
table admin.*;
> add rmttrail D:\oracle\product\11.1.0\x86_ogg4oracle\dirdat\r1 extract ext1
> start mgr
> start ext1
> info all
複製 OGG 檔案夾,準備開始配置 備份服務 root(使用者),【admin 表 TBTEST 會備份到 root 表 TBTEST】
雙擊 新複製的 ggsci.exe
> edit param mgr
> add replicat rep1 exttrail D:\oracle\product\11.1.0\x86_ogg4oracle_target\dirdat\r1, nodbcheckpoint
> edit param rep1
填寫如下內容:(這裡的配置是錯誤的,查錯後的正確配置在下面)
replicat rep1
userid root,password oracle
assumetargetdefs
reperror default,discard
discardfile c:\oradata\repsz.dsc,append,megabytes 100
map admin., target root.;
手動建立 上面的 C:\oradata\ 檔案夾。【不手動建立會報錯】
> start mgr
> start rep1
目前為止
目標1 測試開始
執行指令碼:
insert into TB_TEST(fid, fname, fbirthday, fsex) values (10, ‘路人甲‘, "TO_DATE"(‘1992-02-10‘, ‘yyyy-MM-dd‘), ‘男‘);
對比兩個表:
出現BUG了,作者想要冷靜一會兒。
仔細檢查,似乎發現了 BUG:
大喊一聲:神獸保佑,代碼無BUG。
先在 ADMIN OGG中輸入命令: > start mgr > start ext1
開啟 ROOT 的 MGR 7909: > start mgr > start rep1
這日子沒法過了。
猜想: 我們在複製 D:\oracle\product\11.1.0\x86ogg4oracle\ 到 x86ogg4oracle_target 時,是不是把 源端的配置 也複製過來了?
於是在 x86ogg4oracletarget 中搜尋 ext1 —— 確實搜尋除了 源端中的 ext1 配置。【目標端不需要這個配置,把搜尋出的 ext1 全部刪除】
再次執行 insert 語句 —— 問題依然沒有解決:還是無法同步 —— 心已經稀碎,碎了一地。
在一籌莫展時,意外在 x86ogg4oracletarget\ ggserr.log 中發現了一行錯誤:
將 x86ogg4oracle\dirdat\ 和 x86ogg4oracle_target\dirdat\ 兩個檔案夾一比較:
手動將 x86ogg4oracle\dirdat\ 中的檔案 複製到 x86ogg4oracle_target\dirdat\ ,重啟 源端、目標端 的 服務【start mgr 、start ext1、 start rep1、這些基本啟動命令,我在文章的下面 就不多說了】
再次insert —— 奇蹟發生了:
最終發現,想實現同步 就得讓 \x86ogg4oracletarget\dirdat\ 中 有資料。那麼這個目錄的資料 從哪裡來?
開始驗證猜想:
我們啟動 源端OGG,啟動 ext1,執行 insert指令碼 —— 結果發現:\x86_ogg4oracle\dirdata\ 不會組建檔案。
我們再啟動 目標端OGG,啟動 rep1,執行 insert指令碼 —— 結果發現 \x86_ogg4oracle\dirdata\ 檔案產生了。
—— 即:配置ext1 時的資料目錄,rmttrail 是 目標端目錄。
理論清晰了,開始重新設定 ext1 和 rep1:
重建 ext1:
extract ext1
userid admin,password oracle
rmthost 127.0.0.1, mgrport 7909
rmttrail D:\oracle\product\11.1.0\x86ogg4oracletarget\dirdat\r1
dynamicresolution
gettruncates
table admin.*;
重建 rep1:
replicat rep1
userid root,password oracle
assumetargetdefs
reperror default,discard
discardfile D:\oracle\product\11.1.0\x86ogg4oracletarget\dirdat\repsz.dsc,append,megabytes 100
map admin., target root.;
執行 insert 指令碼 —— 2秒鐘後,同步成功:
遺留問題
\x86_ogg4oracle\ 在啟動 ext1 時, 執行 insert —— 捕獲到的資料變化 存放在哪裡?
目標2,如何 編寫對應的 Java外掛程式 —— 待續。
OGG 是基於變化的同步 —— 之前沒同步的部分,啟用OGG之後也不會同步。
那麼: 源端 TBTEST.FID =10,目標端 TBTEST.FID =30(一開始就不同步)
『OGG 01』Win7 配置 Oracle GoldenGate 踩坑指南