通過shell指令碼得到資料庫的基本資訊(一)

jeanron100發表於2016-08-12
今天寫了個指令碼,雖然實現的功能不多,但是個人感覺是一個好的開始,架子出來了,後面要補充的細節加進來就逐步完善了。
這個指令碼的執行效果如下:
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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章