dataguard switchover的自動化指令碼實現
data guard的主要功能就是作為備庫來同步主庫的資料變化,一般使用中物理standby使用的比較多。data guard顯示威力的一個場景就是swithover了,即主備切換。這種切換方式執行時間很短,能夠在一些災難場景中極大的提高系統的可用性和穩定性。
自己在本地的環境中搭建了一套data guard的環境,開始比較生疏,切換中碰到了不少的問題,最後搭建完成,把切換中的一些細節資訊都總結起來,整理成了一個初步的指令碼。能夠很方便的實現swith over
這個指令碼適用於物理standby,在本地環境中反覆測試,切換了十多次,還算是比較穩定的。
在指令碼中也對需要切換的例項進行了基本的校驗,保證不會出現低階錯誤。比如主庫切為主庫,備庫切為備庫等等。
當然對於一些更加細節的資訊沒有做過濾,比如對於歸檔gap的判定等。
PRI_DB=`sqlplus -s sys/oracle@$1 as sysdba <
set feedback off
set pages 0
select database_role from v\\$database;
EOF`
echo $PRI_DB
if [[ $PRI_DB = 'PHYSICAL STANDBY' ]]
then echo 'PRIMARY DB INSTANCE IS NOT '$1 ',PLEASE CHECK AGAIN'
exit
fi
PRI_DB=$1
#echo $PRI_DB
STD_DB=`sqlplus -s sys/oracle@$2 as sysdba <
set feedback off
set pages 0
select database_role from v\\$database;
EOF`
if [[ $STD_DB = 'PRIMARY' ]]
then echo 'STANDBY DB INSTANCE IS NOT '$2 ',PLEASE CHECK AGAIN'
exit
fi
STD_DB=$2
#export ORACLE_SID=$STD_DB
sqlplus -s sys/oracle@$PRI_DB as sysdba <
break on db_name
set pages 50
set linesize 100
prompt
prompt Primary Instance
prompt ~~~~~~~~~~~~~~~~
select d.dbid dbid
, d.name db_name
, i.instance_number inst_num
, i.instance_name inst_name
, d.database_role
from v\$database d,
v\$instance i;
EOF
#export ORACLE_SID=$STD_DB
sqlplus -s sys/oracle@$STD_DB as sysdba <
break on db_name
set pages 50
set linesize 100
prompt
prompt Standby Instance
prompt ~~~~~~~~~~~~~~~~
select d.dbid dbid
, d.name db_name
, i.instance_number inst_num
, i.instance_name inst_name
, d.database_role
from v\$database d,
v\$instance i;
EOF
sqlplus sys/oracle@$STD_DB as sysdba <
prompt recover managed standby database cancel;
recover managed standby database cancel;
EOF
#export ORACLE_SID=$PRI_DB
sqlplus sys/oracle@$PRI_DB as sysdba <
prompt Alter database commit to switchover to physical standby with session shutdown;
Alter database commit to switchover to physical standby with session shutdown;
EOF
sqlplus sys/oracle@$PRI_DB as sysdba <
prompt shutdown immediate;
shutdown immediate;
EOF
sqlplus sys/oracle@$PRI_DB as sysdba <
prompt startup mount
startup mount
prompt recover managed standby database disconnect from session;
recover managed standby database disconnect from session;
EOF
#export ORACLE_SID=$STD_DB
sqlplus sys/oracle@$STD_DB as sysdba <
Select name,switchover_status from v\$database;
prompt alter database recover managed standby database finish force;
alter database recover managed standby database finish force;
select name,switchover_status from v\$database;
prompt alter database commit to switchover to primary;
alter database commit to switchover to primary;
select name,database_role from v\$database;
select instance_name,status from v\$instance;
prompt alter database open;
alter database open;
EOF
切換的日誌如下,限於篇幅,適當做了整理。
Primary Instance
~~~~~~~~~~~~~~~~
DBID DB_NAME INST_NUM INST_NAME DATABASE_ROLE
---------- --------- ---------- ---------------- ----------------
1028247664 TEST11G 1 TEST11G PRIMARY
Standby Instance
~~~~~~~~~~~~~~~~
DBID DB_NAME INST_NUM INST_NAME DATABASE_ROLE
---------- --------- ---------- ---------------- ----------------
1028247664 TEST11G 1 DG11G PHYSICAL STANDBY
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
idle> recover managed standby database cancel
idle> Media recovery complete.
idle>
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
sys@TEST11G> Alter database commit to switchover to physical standby with session shutdown
sys@TEST11G>
Database altered.
sys@TEST11G>
idle> shutdown immediate
idle> ORA-01507: database not mounted
ORACLE instance shut down.
Connected to an idle instance.
idle> startup mount
idle> ORACLE instance started.
Total System Global Area 435224576 bytes
Fixed Size 1337044 bytes
Variable Size 272632108 bytes
Database Buffers 155189248 bytes
Redo Buffers 6066176 bytes
Database mounted.
idle> recover managed standby database disconnect from session
idle> Media recovery complete.
NAME SWITCHOVER_STATUS
--------- --------------------
TEST11G SWITCHOVER LATENT
idle> alter database recover managed standby database finish force
idle>
Database altered.
NAME SWITCHOVER_STATUS
--------- --------------------
TEST11G TO PRIMARY
idle> alter database commit to switchover to primary
idle>
Database altered.
NAME DATABASE_ROLE
--------- ----------------
TEST11G PRIMARY
idle>
INSTANCE_NAME STATUS
---------------- ------------
DG11G MOUNTED
idle> alter database open
idle>
Database altered.
自己在本地的環境中搭建了一套data guard的環境,開始比較生疏,切換中碰到了不少的問題,最後搭建完成,把切換中的一些細節資訊都總結起來,整理成了一個初步的指令碼。能夠很方便的實現swith over
這個指令碼適用於物理standby,在本地環境中反覆測試,切換了十多次,還算是比較穩定的。
在指令碼中也對需要切換的例項進行了基本的校驗,保證不會出現低階錯誤。比如主庫切為主庫,備庫切為備庫等等。
當然對於一些更加細節的資訊沒有做過濾,比如對於歸檔gap的判定等。
PRI_DB=`sqlplus -s sys/oracle@$1 as sysdba <
set pages 0
select database_role from v\\$database;
EOF`
echo $PRI_DB
if [[ $PRI_DB = 'PHYSICAL STANDBY' ]]
then echo 'PRIMARY DB INSTANCE IS NOT '$1 ',PLEASE CHECK AGAIN'
exit
fi
PRI_DB=$1
#echo $PRI_DB
STD_DB=`sqlplus -s sys/oracle@$2 as sysdba <
set pages 0
select database_role from v\\$database;
EOF`
if [[ $STD_DB = 'PRIMARY' ]]
then echo 'STANDBY DB INSTANCE IS NOT '$2 ',PLEASE CHECK AGAIN'
exit
fi
STD_DB=$2
#export ORACLE_SID=$STD_DB
sqlplus -s sys/oracle@$PRI_DB as sysdba <
set pages 50
set linesize 100
prompt
prompt Primary Instance
prompt ~~~~~~~~~~~~~~~~
select d.dbid dbid
, d.name db_name
, i.instance_number inst_num
, i.instance_name inst_name
, d.database_role
from v\$database d,
v\$instance i;
EOF
#export ORACLE_SID=$STD_DB
sqlplus -s sys/oracle@$STD_DB as sysdba <
set pages 50
set linesize 100
prompt
prompt Standby Instance
prompt ~~~~~~~~~~~~~~~~
select d.dbid dbid
, d.name db_name
, i.instance_number inst_num
, i.instance_name inst_name
, d.database_role
from v\$database d,
v\$instance i;
EOF
sqlplus sys/oracle@$STD_DB as sysdba <
recover managed standby database cancel;
EOF
#export ORACLE_SID=$PRI_DB
sqlplus sys/oracle@$PRI_DB as sysdba <
Alter database commit to switchover to physical standby with session shutdown;
EOF
sqlplus sys/oracle@$PRI_DB as sysdba <
shutdown immediate;
EOF
sqlplus sys/oracle@$PRI_DB as sysdba <
startup mount
prompt recover managed standby database disconnect from session;
recover managed standby database disconnect from session;
EOF
#export ORACLE_SID=$STD_DB
sqlplus sys/oracle@$STD_DB as sysdba <
prompt alter database recover managed standby database finish force;
alter database recover managed standby database finish force;
select name,switchover_status from v\$database;
prompt alter database commit to switchover to primary;
alter database commit to switchover to primary;
select name,database_role from v\$database;
select instance_name,status from v\$instance;
prompt alter database open;
alter database open;
EOF
切換的日誌如下,限於篇幅,適當做了整理。
Primary Instance
~~~~~~~~~~~~~~~~
DBID DB_NAME INST_NUM INST_NAME DATABASE_ROLE
---------- --------- ---------- ---------------- ----------------
1028247664 TEST11G 1 TEST11G PRIMARY
Standby Instance
~~~~~~~~~~~~~~~~
DBID DB_NAME INST_NUM INST_NAME DATABASE_ROLE
---------- --------- ---------- ---------------- ----------------
1028247664 TEST11G 1 DG11G PHYSICAL STANDBY
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
idle> recover managed standby database cancel
idle> Media recovery complete.
idle>
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
sys@TEST11G> Alter database commit to switchover to physical standby with session shutdown
sys@TEST11G>
Database altered.
sys@TEST11G>
idle> shutdown immediate
idle> ORA-01507: database not mounted
ORACLE instance shut down.
Connected to an idle instance.
idle> startup mount
idle> ORACLE instance started.
Total System Global Area 435224576 bytes
Fixed Size 1337044 bytes
Variable Size 272632108 bytes
Database Buffers 155189248 bytes
Redo Buffers 6066176 bytes
Database mounted.
idle> recover managed standby database disconnect from session
idle> Media recovery complete.
NAME SWITCHOVER_STATUS
--------- --------------------
TEST11G SWITCHOVER LATENT
idle> alter database recover managed standby database finish force
idle>
Database altered.
NAME SWITCHOVER_STATUS
--------- --------------------
TEST11G TO PRIMARY
idle> alter database commit to switchover to primary
idle>
Database altered.
NAME DATABASE_ROLE
--------- ----------------
TEST11G PRIMARY
idle>
INSTANCE_NAME STATUS
---------------- ------------
DG11G MOUNTED
idle> alter database open
idle>
Database altered.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23718752/viewspace-1673015/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 實現指令碼自動部署docker指令碼Docker
- python實現自動搶課指令碼Python指令碼
- linux透過shell指令碼實現ssh互動式自動化Linux指令碼
- specjvm自動化指令碼JVM指令碼
- 《轉載》Jenkins持續整合-自動化部署指令碼的實現《python》Jenkins指令碼Python
- 如何實現工具無關化?關於自動化測試指令碼的設計指令碼
- GithubCI+webhook實現push自動化部署(更靈活的指令碼模式)GithubWebHook指令碼模式
- DataGuard---->物理StandBy的角色切換之switchover
- Dockerfile---指令碼自動化Docker指令碼
- vue自動化部署指令碼Vue指令碼
- 利用Python實現自動掃雷小指令碼Python指令碼
- flyway實現java 自動升級SQL指令碼JavaSQL指令碼
- mydumper自動化安裝指令碼指令碼
- JMeter 介面自動化測試(手工轉自動化指令碼)JMeter指令碼
- 使用 Fastlane 實現 iOS 跟 Android 自動打包指令碼ASTiOSAndroid指令碼
- 實現MySQL表結構自動分割槽指令碼MySql指令碼
- 自動化指令碼安裝mysql shell指令碼範例指令碼MySql
- 高複用性自動化指令碼設計實踐指令碼
- 介面未全部提測,怎麼實現介面指令碼之間的自動化關聯?指令碼
- Oracle DataGuard 主備切換 (switchover) oracle11gOracle
- Selenium自動化實現web自動化-1Web
- 介面自動化指令碼設計規範指令碼
- 自動批次實現linux機器ssh免密shell指令碼Linux指令碼
- web自動化測試框架-06 如何快速編寫自動化指令碼Web框架指令碼
- Jenkins + Gitee 實現程式碼自動化構建JenkinsGitee
- 自動化驗證碼登入如何實現?
- [python] request 介面測試自動化指令碼轉化為 [locust] 效能測試指令碼Python指令碼
- 解密prompt系列5. APE+SELF=自動化指令集構建程式碼實現解密
- [shell]shell指令碼實現每天自動抽取資料插入hive表指令碼Hive
- 利用 JS 指令碼實現網頁全自動秒殺搶購JS指令碼網頁
- 自動化瓦力多渠道打包python指令碼Python指令碼
- 案例八:Shell自動化管理賬號指令碼指令碼
- pyautogui模組,PC自動化指令碼,控制滑鼠GUI指令碼
- ETL指令碼的實現指令碼
- 自動備份指令碼指令碼
- 請問大家,自動化測試可以實現一個指令碼測試全部平臺嗎?指令碼
- IT 自動化:如何去實現
- 基於DotNetty實現自動釋出 - 自動檢測程式碼變化Netty
- 10個Python指令碼來自動化你的日常任務Python指令碼