dataguard 切換後更換IP,service_name
本帖最後由 selectshen 於 2014-10-28 16:55 編輯
測試DB資訊:
--DB1
os:rhel5.6 ip:123.0.0.52 oracle version:10.2.0.4 sid:rh10g03 db_role:primary
--DB2
os:rhel5.6 ip:123.0.0.54 oracle version:10.2.0.4 sid:rh10g02 db_role:standby
先做一個簡單的switchover
-----------------DB1
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE
----上條語句的結果如果是to_standby,切換就不需要加with session shutdown
SQL> alter database commit to switchover to physical standby with session shutdown;
Database altered.
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 599785472 bytes
Fixed Size 2085776 bytes
Variable Size 293604464 bytes
Database Buffers 297795584 bytes
Redo Buffers 6299648 bytes
Database mounted.
SQL> alter database recover managed standby database disconnect from session ;
Database altered.
---------------DB2
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
SQL> alter database commit to switchover to primary;
Database altered.
SQL> alter database open;
Database altered.
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
--如果你的沒有出什麼錯的話,應該可以看到,就表示已經switchover成功了.
---------------DB2
SQL> select process,thread#,sequence#,status from v$managed_standby;
PROCESS THREAD# SEQUENCE# STATUS
--------- ---------- ---------- ------------
ARCH 1 281 CLOSING
ARCH 1 282 CLOSING
LNS 1 283 WRITING
---------------DB1
SQL> select process,thread#,sequence#,status from v$managed_standby;
PROCESS THREAD# SEQUENCE# STATUS
--------- ---------- ---------- ------------
ARCH 0 0 CONNECTED
ARCH 1 280 CLOSING
MRP0 1 283 WAIT_FOR_LOG
RFS 1 283 IDLE
RFS 0 0 IDLE
順便說一下failover,failover時是不用管DB1了,因為假設或事實DB1已經掛了,
只需在DB2上alter database recover managed standby database finish force;應用日誌,
然後alter database commit to switchover to primary;就行了.
上面的很簡單,但生產環境可能就不只是這樣了.如果我們只是簡單的switchover,客戶端的
tnsnames裡存的可是之前的IP和service_name,此時客戶端就需要修改tnsnames裡對應的IP和
service_name,如果是B/s程式還好,直接的C/S程式每個客戶端都要修,有時甚至已經不現實.
所以常常會在switchover之後,還要修改對應的IP和service_name.最近產生了一個個人覺得比較好
的方案,就是我們只需要修改IP就可以了,不需要修改service_name,而是在建dataguard時就加
一個共有的service_name,客戶端連線都透過這個service_name,而主從之間的傳輸可用原本預設
的service_name(常常就是各自的sid).新加的service_name可以透過靜態註冊或動態註冊都可以.
這樣可以有效避免,常規方式中,客戶端連線的service_name就是primary預設的service_name,
當switchover後,如果在要在新的primary上能讓使用者連線,就要加這個service_name.但如果加了這個
service_name,原有的主從就會因為名稱的衝突無法傳輸.這時的解決辦法可以是重建standby或是修改
sid等,就比較複雜了.
以下測試修改IP:
--假設客戶端連線的IP:123.0.0.52 service_name:rh10g 這裡的service_name已經是兩邊有加的service_name
透過DB1和DB2在 listener.ora中加入:
(SID_DESC =
(SID_NAME = rh10g03)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(global_dbname = rh10g)
用於靜態註冊.或是透過在DB1和DB2中執行:
SQL> alter system set service_names=rh10g;
用於動態註冊.
--------------------DB1
--需要先把DB1的IP改為一箇中間IP:123.0.0.55,避免修改IP後衝突
--修改裡面IP對應的主機名
vi /etc/hosts
123.0.0.55 srhel10g03
--修改IP為中間IP123.0.0.55
vi /etc/sysconfig/network-scripts/ifcfg-eth0
--修改tnsnames.ora
RH10G02 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 123.0.0.52)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rh10g02)
)
)
RH10G03 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 123.0.0.54)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rh10g03)
)
)
--重啟網路
service network restart
---------------------------DB2
--修改裡面IP對應的主機名
vi /etc/hosts
123.0.0.52 srhel10g02
--修改IP
vi /etc/sysconfig/network-scripts/ifcfg-eth0
--修改tnsnames.ora
RH10G02 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 123.0.0.52)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rh10g02)
)
)
RH10G03 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 123.0.0.54)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rh10g03)
)
)
--重啟網路
service network restart
-------------------------DB1
--修改裡面IP對應的主機名
vi /etc/hosts
123.0.0.54 srhel10g03
----修改正確IP 123.0.0.54
vi /etc/sysconfig/network-scripts/ifcfg-eth0
--重啟網路
service network restart
-------------------------DB2
--網路修改完後,在DB2上切幾次日誌檢測是否正常
上面是switchover的方法,如果是failover那就簡單了,直接透過靜態或動態註冊加入原primary的service_name,
然後修改IP就可以了.
--dataguard的幾個引數:
log_archive_config='DG_CONFIG=(orcl01,orcl02)'
log_archive_dest_1='LOCATION=/u09/archivelog/orcl01 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl01'
LOG_ARCHIVE_DEST_2='SERVICE=orcl02 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,primary_ROLE) DB_UNIQUE_NAME=orcl02'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=defer
FAL_SERVER=orcl02
FAL_CLIENT=orcl01
db_file_name_convert='orcl02','orcl01' scope=spfile;
log_file_name_convert='orcl02','orcl01' scope=spfile;
standby_file_management=auto
測試DB資訊:
--DB1
os:rhel5.6 ip:123.0.0.52 oracle version:10.2.0.4 sid:rh10g03 db_role:primary
--DB2
os:rhel5.6 ip:123.0.0.54 oracle version:10.2.0.4 sid:rh10g02 db_role:standby
先做一個簡單的switchover
-----------------DB1
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE
----上條語句的結果如果是to_standby,切換就不需要加with session shutdown
SQL> alter database commit to switchover to physical standby with session shutdown;
Database altered.
SQL> shutdown immediate;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 599785472 bytes
Fixed Size 2085776 bytes
Variable Size 293604464 bytes
Database Buffers 297795584 bytes
Redo Buffers 6299648 bytes
Database mounted.
SQL> alter database recover managed standby database disconnect from session ;
Database altered.
---------------DB2
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
SQL> alter database commit to switchover to primary;
Database altered.
SQL> alter database open;
Database altered.
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
--如果你的沒有出什麼錯的話,應該可以看到,就表示已經switchover成功了.
---------------DB2
SQL> select process,thread#,sequence#,status from v$managed_standby;
PROCESS THREAD# SEQUENCE# STATUS
--------- ---------- ---------- ------------
ARCH 1 281 CLOSING
ARCH 1 282 CLOSING
LNS 1 283 WRITING
---------------DB1
SQL> select process,thread#,sequence#,status from v$managed_standby;
PROCESS THREAD# SEQUENCE# STATUS
--------- ---------- ---------- ------------
ARCH 0 0 CONNECTED
ARCH 1 280 CLOSING
MRP0 1 283 WAIT_FOR_LOG
RFS 1 283 IDLE
RFS 0 0 IDLE
順便說一下failover,failover時是不用管DB1了,因為假設或事實DB1已經掛了,
只需在DB2上alter database recover managed standby database finish force;應用日誌,
然後alter database commit to switchover to primary;就行了.
上面的很簡單,但生產環境可能就不只是這樣了.如果我們只是簡單的switchover,客戶端的
tnsnames裡存的可是之前的IP和service_name,此時客戶端就需要修改tnsnames裡對應的IP和
service_name,如果是B/s程式還好,直接的C/S程式每個客戶端都要修,有時甚至已經不現實.
所以常常會在switchover之後,還要修改對應的IP和service_name.最近產生了一個個人覺得比較好
的方案,就是我們只需要修改IP就可以了,不需要修改service_name,而是在建dataguard時就加
一個共有的service_name,客戶端連線都透過這個service_name,而主從之間的傳輸可用原本預設
的service_name(常常就是各自的sid).新加的service_name可以透過靜態註冊或動態註冊都可以.
這樣可以有效避免,常規方式中,客戶端連線的service_name就是primary預設的service_name,
當switchover後,如果在要在新的primary上能讓使用者連線,就要加這個service_name.但如果加了這個
service_name,原有的主從就會因為名稱的衝突無法傳輸.這時的解決辦法可以是重建standby或是修改
sid等,就比較複雜了.
以下測試修改IP:
--假設客戶端連線的IP:123.0.0.52 service_name:rh10g 這裡的service_name已經是兩邊有加的service_name
透過DB1和DB2在 listener.ora中加入:
(SID_DESC =
(SID_NAME = rh10g03)
(ORACLE_HOME = /u01/app/oracle/product/10.2.0/db_1)
(global_dbname = rh10g)
用於靜態註冊.或是透過在DB1和DB2中執行:
SQL> alter system set service_names=rh10g;
用於動態註冊.
--------------------DB1
--需要先把DB1的IP改為一箇中間IP:123.0.0.55,避免修改IP後衝突
--修改裡面IP對應的主機名
vi /etc/hosts
123.0.0.55 srhel10g03
--修改IP為中間IP123.0.0.55
vi /etc/sysconfig/network-scripts/ifcfg-eth0
--修改tnsnames.ora
RH10G02 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 123.0.0.52)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rh10g02)
)
)
RH10G03 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 123.0.0.54)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rh10g03)
)
)
--重啟網路
service network restart
---------------------------DB2
--修改裡面IP對應的主機名
vi /etc/hosts
123.0.0.52 srhel10g02
--修改IP
vi /etc/sysconfig/network-scripts/ifcfg-eth0
--修改tnsnames.ora
RH10G02 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 123.0.0.52)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rh10g02)
)
)
RH10G03 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 123.0.0.54)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rh10g03)
)
)
--重啟網路
service network restart
-------------------------DB1
--修改裡面IP對應的主機名
vi /etc/hosts
123.0.0.54 srhel10g03
----修改正確IP 123.0.0.54
vi /etc/sysconfig/network-scripts/ifcfg-eth0
--重啟網路
service network restart
-------------------------DB2
--網路修改完後,在DB2上切幾次日誌檢測是否正常
上面是switchover的方法,如果是failover那就簡單了,直接透過靜態或動態註冊加入原primary的service_name,
然後修改IP就可以了.
--dataguard的幾個引數:
log_archive_config='DG_CONFIG=(orcl01,orcl02)'
log_archive_dest_1='LOCATION=/u09/archivelog/orcl01 VALID_FOR=(ALL_LOGFILES,ALL_ROLES) DB_UNIQUE_NAME=orcl01'
LOG_ARCHIVE_DEST_2='SERVICE=orcl02 LGWR ASYNC VALID_FOR=(ONLINE_LOGFILES,primary_ROLE) DB_UNIQUE_NAME=orcl02'
LOG_ARCHIVE_DEST_STATE_1=ENABLE
LOG_ARCHIVE_DEST_STATE_2=defer
FAL_SERVER=orcl02
FAL_CLIENT=orcl01
db_file_name_convert='orcl02','orcl01' scope=spfile;
log_file_name_convert='orcl02','orcl01' scope=spfile;
standby_file_management=auto
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28539951/viewspace-1312403/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- DATAGUARD失敗切換
- DATAGUARD強行切換
- Oracle 11.2.0.4 physical dataguard和snapshot dataguard切換Oracle
- oracle11g dataguard切換Oracle
- 【DATAGUARD】Oracle Dataguard物理備庫切換最佳實踐(sqlplus)OracleSQL
- IP地址切換工具
- 基於單機的DataGuard切換文件
- DataGuard---->物理StandBy的角色切換之switchover
- 基於多種場景DataGuard切換方案
- 如何更換動態IP?
- 切換代理IP時如何檢查IP?
- Oracle DataGuard 主備切換 (switchover) oracle11gOracle
- scan ip的手動切換
- ORACLE 12C DATAGUARD環境搭建和主從切換Oracle
- 如何更優雅地切換 Git 分支Git
- 帝國cms更換域名後圖片地址更換的方法
- 物理DataGuard客戶端無縫切換--客戶端TAF 配置客戶端
- 程式切換(上下文切換)
- 爬蟲為什麼要用IP代理更換IP地址爬蟲
- 代理IP常見的三種切換方式
- 網站更換IP,更換空間對影響到關鍵詞的排名嗎?網站
- 帝國cms網站更換域名後圖片地址更換的方法網站
- 伺服器更換IP需要注意哪些伺服器
- 棧切換
- 爬蟲中的TCP請求自動切換ip爬蟲TCP
- db_ha叢集安裝後的自動切換及切換後的判斷步驟說明文件
- App切換到後臺後如何保持持續定位?APP
- iphone 4 攝像頭是前後切換iPhone
- 網站更換IP的四大注意事項網站
- 切換UNDO(zt)
- ubuntu切換源Ubuntu
- Git分支切換Git
- 切換java版本Java
- 切換 PHP 版本PHP
- 蘋果IP:如何換IP?換IP最簡單的方法分享蘋果
- MySQL Orchestrator自動導換+VIP切換MySql
- 蘋果更新iPad mini 6售後政策:只更換電池 不再更換整個裝置蘋果iPad
- Debian更換源
- DG的切換操作