通過shell指令碼得到資料庫的基本資訊(一)
今天寫了個指令碼,雖然實現的功能不多,但是個人感覺是一個好的開始,架子出來了,後面要補充的細節加進來就逐步完善了。
這個指令碼的執行效果如下:
OS Version is :[ RHEL_6.3 ]
Oracle Version is :[ 11.2.0.3.0]
Oracle Instance is :[ dgtest ]
dgtest
ORACLE_HOME is :[ /U01/app/oracle/product/11.2.0.2/db_1 ]
Oracle status is :[ 11g PRIMARY ]
Oracle SPFILE is :[ ENABLED ]
Oralce DGBroker is :[ DISABLED ]
FORCE LOGGING is :[ DISABLED ]
HugePage Status is :[ DISABLED ]
這個指令碼會對大部分的資訊進行一個概覽,我想在這些內容的基礎上新增更多的經驗所得。
執行這個指令碼,好與不好一目瞭然,當然現在的功能還是有距離,慢慢改進吧。
值得說道的是“Oracle status”的地方,會判斷主備庫,區分了10g,11g的不同特點。
當然後面的大篇幅指令碼是關於HugePage的,這個地方想補充出建議的值來,所以暫且這樣。
指令碼內容如下:
. /home/oracle/.bash_profile
# Get OS Version
echo 'OS Version is :[' `cat /etc/issue|sed -e 's/Red Hat Enterprise Linux Server release/RHEL/g' -e 's/Red Hat Enterprise Linux AS release/RHEL/g' -e 's/ /_/g' -e 's/_(Tikanga)//g' -e 's/_(Santiago)//g' -e 's/_release//g' -e 's/_(Final)//g' -e 's/Nahant_Update_//g'|head -1` ]
# Get Oracle Version
echo 'Oracle Version is :[ '`sqlplus -v|sed '/^$/d'|awk '{print $3}'`]
# Get Oracle Instance List
echo 'Oracle Instance is :[ '`ps -ef|grep smon|grep -v grep|awk '{gsub("ora_smon_","",$8)}{print $8}'|grep -v awk` ]
for tmp_db in `ps -ef|grep smon|grep -v grep|awk '{gsub("ora_smon_","",$8)}{print $8}'|grep -v awk`
do
echo $tmp_db
#Get Oracle Home
echo 'ORACLE_HOME is :[' $ORACLE_HOME ' ]'
# Get database role
su -l oracle <<EOS
export ORACLE_SID=${tmp_db}
$ORACLE_HOME/bin/sqlplus -s / as sysdba <<EOF
set pages 0
set feedback off
select 'Oracle status is :[ '||decode(substr(version,1,2),11,
(select decode(database_role,'PHYSICAL STANDBY',(decode(open_mode,'READ ONLY WITH APPLY','11g ADG','11g DG NEED_CHECK')),'PRIMARY','11g PRIMARY') from v\\\$database),
10,
(select decode(database_role,'PHYSICAL STANDBY',(decode(open_mode,'MOUNTED','10g DG NORMAL','10g DG NEED_CHECK')),'PRIMARY','10g PRIMARY') from v\\\$database)
)||' ]' DG_MODE
from v\\\$instance;
select decode(value,null,'Oralce SPFILE is :[ DISABLED ]','Oracle SPFILE is :[ ENABLED ]') from v\\\$parameter where name='spfile';
select decode(upper(value),'FALSE','Oralce DGBroker is :[ DISABLED ]','Oracle DGBroker is :[ ENABLED ]') from v\\\$parameter where name='dg_broker_start';
select decode(force_logging,'NO','FORCE LOGGING is :[ DISABLED ]','FORCE LOGGING is :[ ENABLED ]') from v\\\$database;
EOF
EOS
done
# Check HugePage enabled
# Check for the kernel version
KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`
# Find out the HugePage size
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {'print $2'}`
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage
NUM_PG=1
# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | awk {'print $5'} | grep "[0-9][0-9]*"`
do
MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`
if [ $MIN_PG -gt 0 ]; then
NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`
fi
done
case $KERN in
'2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;
grep vm.hugetlb_pool /etc/sysctl.conf|awk '{print $0==""?"HugePage Status :[ DISABLED ]":"HugePage Status is :[ ENABLED ]"}';;
'2.6') grep vm.nr_hugepages /etc/sysctl.conf|xargs echo $1|awk '{print $0==""?"HugePage Status is :[ DISABLED ]":"HugePage Status is :[ ENABLED ]"}';;
*) echo "Unrecognized kernel version $KERN. Exiting." ;;
esac
這個指令碼的執行效果如下:
OS Version is :[ RHEL_6.3 ]
Oracle Version is :[ 11.2.0.3.0]
Oracle Instance is :[ dgtest ]
dgtest
ORACLE_HOME is :[ /U01/app/oracle/product/11.2.0.2/db_1 ]
Oracle status is :[ 11g PRIMARY ]
Oracle SPFILE is :[ ENABLED ]
Oralce DGBroker is :[ DISABLED ]
FORCE LOGGING is :[ DISABLED ]
HugePage Status is :[ DISABLED ]
這個指令碼會對大部分的資訊進行一個概覽,我想在這些內容的基礎上新增更多的經驗所得。
執行這個指令碼,好與不好一目瞭然,當然現在的功能還是有距離,慢慢改進吧。
值得說道的是“Oracle status”的地方,會判斷主備庫,區分了10g,11g的不同特點。
當然後面的大篇幅指令碼是關於HugePage的,這個地方想補充出建議的值來,所以暫且這樣。
指令碼內容如下:
. /home/oracle/.bash_profile
# Get OS Version
echo 'OS Version is :[' `cat /etc/issue|sed -e 's/Red Hat Enterprise Linux Server release/RHEL/g' -e 's/Red Hat Enterprise Linux AS release/RHEL/g' -e 's/ /_/g' -e 's/_(Tikanga)//g' -e 's/_(Santiago)//g' -e 's/_release//g' -e 's/_(Final)//g' -e 's/Nahant_Update_//g'|head -1` ]
# Get Oracle Version
echo 'Oracle Version is :[ '`sqlplus -v|sed '/^$/d'|awk '{print $3}'`]
# Get Oracle Instance List
echo 'Oracle Instance is :[ '`ps -ef|grep smon|grep -v grep|awk '{gsub("ora_smon_","",$8)}{print $8}'|grep -v awk` ]
for tmp_db in `ps -ef|grep smon|grep -v grep|awk '{gsub("ora_smon_","",$8)}{print $8}'|grep -v awk`
do
echo $tmp_db
#Get Oracle Home
echo 'ORACLE_HOME is :[' $ORACLE_HOME ' ]'
# Get database role
su -l oracle <<EOS
export ORACLE_SID=${tmp_db}
$ORACLE_HOME/bin/sqlplus -s / as sysdba <<EOF
set pages 0
set feedback off
select 'Oracle status is :[ '||decode(substr(version,1,2),11,
(select decode(database_role,'PHYSICAL STANDBY',(decode(open_mode,'READ ONLY WITH APPLY','11g ADG','11g DG NEED_CHECK')),'PRIMARY','11g PRIMARY') from v\\\$database),
10,
(select decode(database_role,'PHYSICAL STANDBY',(decode(open_mode,'MOUNTED','10g DG NORMAL','10g DG NEED_CHECK')),'PRIMARY','10g PRIMARY') from v\\\$database)
)||' ]' DG_MODE
from v\\\$instance;
select decode(value,null,'Oralce SPFILE is :[ DISABLED ]','Oracle SPFILE is :[ ENABLED ]') from v\\\$parameter where name='spfile';
select decode(upper(value),'FALSE','Oralce DGBroker is :[ DISABLED ]','Oracle DGBroker is :[ ENABLED ]') from v\\\$parameter where name='dg_broker_start';
select decode(force_logging,'NO','FORCE LOGGING is :[ DISABLED ]','FORCE LOGGING is :[ ENABLED ]') from v\\\$database;
EOF
EOS
done
# Check HugePage enabled
# Check for the kernel version
KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`
# Find out the HugePage size
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk {'print $2'}`
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage
NUM_PG=1
# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | awk {'print $5'} | grep "[0-9][0-9]*"`
do
MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`
if [ $MIN_PG -gt 0 ]; then
NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`
fi
done
case $KERN in
'2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;
grep vm.hugetlb_pool /etc/sysctl.conf|awk '{print $0==""?"HugePage Status :[ DISABLED ]":"HugePage Status is :[ ENABLED ]"}';;
'2.6') grep vm.nr_hugepages /etc/sysctl.conf|xargs echo $1|awk '{print $0==""?"HugePage Status is :[ DISABLED ]":"HugePage Status is :[ ENABLED ]"}';;
*) echo "Unrecognized kernel version $KERN. Exiting." ;;
esac
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23718752/viewspace-2123419/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 通過shell指令碼得到資料字典的資訊指令碼
- 透過shell指令碼得到資料字典的資訊指令碼
- 通過shell得到資料庫中許可權的指令碼資料庫指令碼
- 透過shell得到資料庫中許可權的指令碼資料庫指令碼
- 通過shell指令碼批量操作mysql資料庫指令碼MySql資料庫
- 通過shell指令碼生成資料統計資訊的報表指令碼
- 通過shell指令碼檢視procedure的資訊指令碼
- 通過shell指令碼檢視package的資訊指令碼Package
- 通過shell指令碼檢視鎖資訊指令碼
- 通過shell指令碼來得到不穩定的執行計劃指令碼
- 【SCRIPT】Oracle資料庫基本資訊收集指令碼Oracle資料庫指令碼
- 通過shell指令碼檢測MySQL服務資訊指令碼MySql
- 通過shell指令碼生成查詢表資料的sql指令碼SQL
- 通過shell指令碼新增備庫日誌指令碼
- 通過shell指令碼同時監控多個資料庫負載指令碼資料庫負載
- 通過shell指令碼檢視資料庫表空間使用情況指令碼資料庫
- 透過shell指令碼生成資料統計資訊的報表指令碼
- 通過shell指令碼分析足彩指令碼
- 【轉】通過sql語句獲取資料庫的基本資訊SQL資料庫
- 通過shell定製ash指令碼指令碼
- MySQL資料庫備份的shell指令碼MySql資料庫指令碼
- 建立管理MySQL資料庫的shell指令碼MySql資料庫指令碼
- 透過shell指令碼檢視procedure的資訊指令碼
- 透過shell指令碼檢視package的資訊指令碼Package
- [ Shell ] 通過 Shell 指令碼匯出 CDL 網表指令碼
- 如何通過指令碼匯入master 庫中的user資訊指令碼AST
- 案例:通過shell指令碼實現mysql資料備份與清理指令碼MySql
- 透過shell指令碼檢視鎖資訊指令碼
- 通過shell指令碼防止埠掃描指令碼
- 通過shell指令碼監控oracle session指令碼OracleSession
- Liunx備份mysql資料庫的shell指令碼MySql資料庫指令碼
- 監控Oracle資料庫的常用shell指令碼Oracle資料庫指令碼
- [ Shell ] 通過 Shell 指令碼匯出 GDSII/OASIS 檔案指令碼
- 透過shell指令碼來得到不穩定的執行計劃指令碼
- 如何通過簡單的shell指令碼操作MongoDB指令碼MongoDB
- 巧用shell生成資料庫檢查指令碼資料庫指令碼
- 通過shell指令碼 批量新增使用者指令碼
- 通過shell指令碼來統計段大小指令碼