你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux 下Oracle 开机自启动 与 oratab, dbstart 脚本 说明

[日期:2012-04-14] 来源:Linux社区  作者:tianlesoftware [字体:大 中 小]

二.$Oracle_HOME/bin/dbstart,dbshut 说明

2.1 dbstart 脚本

  1. gg1:/u01/app/oracle/product/11.2.0.3/db_1/bin>cat dbstart  
  2. #!/bin/sh  
  3. #  
  4. # $Id: dbstart.sh 22-may-2008.05:05:45arogers Exp $  
  5. # Copyright (c) 1991, 2008, Oracle. Allrights reserved.   
  6. #  
  7.    
  8. ###################################  
  9. #  
  10. # usage: dbstart $ORACLE_HOME  
  11. #  
  12. # This script is used tostart ORACLE from /etc/rc(.local).  
  13. # It should ONLY beexecuted as part of the system boot procedure.  
  14. #  
  15. # This script will start all databaseslisted in the oratab file  
  16. # whose third field is a"Y".  If the third field is setto "Y" and  
  17. # there is no ORACLE_SID for an entry (thefirst field is a *),  
  18. # then this script will ignore that entry.  
  19. <span style="color: rgb(255, 0, 0); ">--这里就是我们之前说的,这个仅启动/etc/oratab 文件中标记为Y的实例。</span>  
  20. #  
  21. # This script requires that ASMORACLE_SID's start with a +, and  
  22. # that non-ASM instance ORACLE_SID's do notstart with a +.  
  23. #  
  24. # If ASM instances are to be started withthis script, it cannot be used inside an rc*.d directory, and should be invokedfrom rc.local only. Otherwise, the CSS service may not be available yet, andthis script will block init from completing the boot cycle.  
  25. <span style="color: rgb(255, 0, 0); ">--如果是ASM 实例,那么只能从rc.local中调用,否则CSS 服务可能不可用。</span>  
  26. #  
  27. # If you want dbstart to auto-start asingle-instance database that uses  
  28. # an ASM server that is auto-started by CRS(this is the default behavior  
  29. # for an ASM cluster), you must change thedatabase's ORATAB entry to use  
  30. # a third field of "W" and theASM's ORATAB entry to use a third field of "N".  
  31. # These values specify that dbstartauto-starts the database only after  
  32. # the ASM instance is up and running.  
  33. <span style="color: rgb(255, 0, 0); ">--注意这里的W,其表示等待所有的ASM 实例启动完毕后在启动数据库。</span>  
  34. #  
  35. # Note:  
  36. # Use ORACLE_TRACE=T for tracing thisscript.  
  37. #  
  38. # The progress log for each instancebringup plus Error and Warning message[s]  
  39. # are logged in file $ORACLE_HOME/startup.log.The error messages related to  
  40. # instance bringup are also logged tosyslog (system log module).  
  41. # The Listener log is located at$ORACLE_HOME_LISTNER/listener.log  
  42. <span style="color: rgb(255, 0, 0); ">--启动日志存放在$ORACLE_HOME/startup.log里。</span>  
  43. #  
  44. # On all UNIX platforms except SOLARIS  
  45. # ORATAB=/etc/oratab  
  46. #  
  47. # To configure, update ORATAB withInstances that need to be started up  
  48. #   Entries are of the form:  
  49. #   $ORACLE_SID:$ORACLE_HOME:<N|Y|W>:  
  50. #   An example entry:  
  51. #   main:/usr/lib/oracle/emagent_10g:Y  
  52. #  
  53. # Overall algorithm:  
  54. <span style="color: rgb(255, 0, 0); ">--启动顺序</span>  
  55. # 1) Bring up all ASM instances with 'Y'entry in status field in oratab entry  
  56. <span style="color: rgb(255, 0, 0); ">--启动状态为Y的所有ASM 实例</span>  
  57. # 2) Bring up all Database instances with'Y' entry in status field in  
  58. #   oratab entry  
  59. <span style="color: rgb(255, 0, 0); ">--启动所有状态为Y的数据库实例</span>  
  60. # 3) If there are Database instances with'W' entry in status field  
  61. #   then  
  62. #     iterate over all ASM instances (irrespective of 'Y' or 'N') AND  
  63. #     wait for all of them to be started  
  64. #   fi  
  65. <span style="color: rgb(255, 0, 0); ">--如果数据库的状态为W,则等待ASM 实例启动完毕,再启动</span>  
  66. # 4) Bring up all Database instances with'W' entry in status field in  
  67. #   oratab entry  
  68. <span style="color: rgb(255, 0, 0); ">--启动所有状态为W的数据库实例</span>  
  69. #  
  70. #####################################  
  71.    
  72. LOGMSG="logger -puser.alert -s "  
  73.    
  74. trap 'exit' 1 2 3  
  75.    
  76. # for script tracing  
  77. case $ORACLE_TRACE in  
  78.   T)set -x ;;  
  79. esac  
  80.      
  81. # Set path if path not set (if called from/etc/rc)  
  82. SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ;export PATH  
  83. SAVE_LLP=$LD_LIBRARY_PATH  
  84.    
  85. # First argument is used to bring up OracleNet Listener  
  86. ORACLE_HOME_LISTNER=$1  
  87. if [ ! $ORACLE_HOME_LISTNER ] ; then  
  88.  echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start OracleNet Listener"  
  89.  echo "Usage: $0 ORACLE_HOME"  
  90. else  
  91.  LOG=$ORACLE_HOME_LISTNER/listener.log  
  92.    
  93.   #Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to  
  94.   # adifferent ORACLE_HOME for each entry in the oratab.  
  95.  export ORACLE_HOME=$ORACLE_HOME_LISTNER  
  96.    
  97.   #Start Oracle Net Listener  
  98.   if[ -x $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then  
  99.    echo "$0: Starting Oracle Net Listener" >> $LOG2>&1  
  100.    $ORACLE_HOME_LISTNER/bin/lsnrctl start >> $LOG 2>&1 &  
  101.    VER10LIST=`$ORACLE_HOME_LISTNER/bin/lsnrctl version | grep "LSNRCTLfor " | cut -d' ' -f5 | cut -d'.' -f1`  
  102.    export VER10LIST  
  103.  else  
  104.    echo "Failed to auto-start Oracle Net Listener using$ORACLE_HOME_LISTNER/bin/tnslsnr"  
  105.   fi  
  106. fi  
  107.    
  108. # Set this in accordance with the platform  
  109. ORATAB=/etc/oratab  
  110. if [ ! $ORATAB ] ; then  
  111.  echo "$ORATAB not found"  
  112.  exit 1;  
  113. fi  
  114.    
  115. # Checks Version Mismatch between Listenerand Database Instance.  
  116. # A version 10 listener is required for anOracle Database 10g database.  
  117. # Previous versions of the listener are notsupported for use with an Oracle  
  118. # Database 10g database. However, it ispossible to use a version 10 listener  
  119. # with previous versions of the Oracledatabase.  
  120. checkversionmismatch() {  
  121.   if[ $VER10LIST ] ; then  
  122.    VER10INST=`sqlplus -V | grep "Release " | cut -d' ' -f3 | cut-d'.' -f1`  
  123.    if [ $VER10LIST -lt $VER10INST ] ; then  
  124.      $LOGMSG "Listener version $VER10LIST NOT supported with Databaseversion $VER10INST"  
  125.      $LOGMSG "Restart Oracle Net Listener using an alternateORACLE_HOME_LISTNER:"  
  126.      $LOGMSG "lsnrctl start"  
  127.    fi  
  128.   fi  
  129. }  
  130.    
  131. # Starts a DatabaseInstance  
  132. startinst() {  
  133.   #Called programs use same database ID  
  134.  export ORACLE_SID  
  135.    
  136.   #Put $ORACLE_HOME/bin into PATH and export.  
  137.  PATH=$ORACLE_HOME/bin:${SAVE_PATH} ; export PATH  
  138.   #add for bug # 652997  
  139.  LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${SAVE_LLP} ; export LD_LIBRARY_PATH  
  140.  PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora  
  141.  SPFILE=${ORACLE_HOME}/dbs/spfile${ORACLE_SID}.ora  
  142.  SPFILE1=${ORACLE_HOME}/dbs/spfile.ora  
  143.    
  144.  echo ""  
  145.  echo "$0: Starting up database \"$ORACLE_SID\""  
  146.  date  
  147.  echo ""  
  148.    
  149.  checkversionmismatch  
  150.    
  151.   #See if it is a V6 or V7 database  
  152.  VERSION=undef  
  153.   if[ -f $ORACLE_HOME/bin/sqldba ] ; then  
  154.    SQLDBA=sqldba  
  155.    VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk '  
  156.      /SQL\*DBA: (Release|Version)/ {split($3, V, ".") ;  
  157.      print V[1]}'`  
  158.    case $VERSION in  
  159.      "6") ;;  
  160.      *) VERSION="internal" ;;  
  161.    esac  
  162.  else  
  163.    if [ -f $ORACLE_HOME/bin/svrmgrl ] ; then  
  164.      SQLDBA=svrmgrl  
  165.      VERSION="internal"  
  166.    else  
  167.      SQLDBA="sqlplus /nolog"  
  168.    fi  
  169.   fi  
  170.    
  171.  STATUS=1  
  172.   if[ -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.dbf ] ; then  
  173.    STATUS="-1"  
  174.   fi  
  175.   if[ -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.ora ] ; then  
  176.    STATUS="-1"  
  177.   fi  
  178.  pmon=`ps -ef | grep -w "ora_pmon_$ORACLE_SID"  | grep -v grep`  
  179.   if[ "$pmon" != "" ] ; then  
  180.    STATUS="-1"  
  181.    $LOGMSG "Warning: ${INST} \"${ORACLE_SID}\" alreadystarted."  
  182.   fi  
  183.    
  184.   if[ $STATUS -eq -1 ] ; then  
  185.    $LOGMSG "Warning: ${INST} \"${ORACLE_SID}\" possibly leftrunning when system went down (system crash?)."  
  186.    $LOGMSG "Action: Notify Database Administrator."  
  187.    case $VERSION in  
  188.      "6")  sqldba"command=shutdown abort" ;;  
  189.      "internal")  $SQLDBA$args <<EOF  
  190. connect internal  
  191. shutdown abort  
  192. EOF  
  193.        ;;  
  194.      *)  $SQLDBA $args <<EOF  
  195. connect / as sysdba  
  196. shutdown abort  
  197. quit  
  198. EOF  
  199.        ;;  
  200.    esac  
  201.    
  202.    if [ $? -eq 0 ] ; then  
  203.      STATUS=1  
  204.    else  
  205.      $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOTstarted."  
  206.    fi  
  207.   fi  
  208.    
  209.   if[ $STATUS -eq 1 ] ; then  
  210.    if [ -e $SPFILE -o -e $SPFILE1 -o -e $PFILE ] ; then  
  211.      case $VERSION in  
  212.        "6")  sqldbacommand=startup ;;  
  213.        "internal")  $SQLDBA<<EOF  
  214. connect internal  
  215. startup  
  216. EOF  
  217.          ;;  
  218.        *)  $SQLDBA <<EOF  
  219. connect / as sysdba  
  220. startup  
  221. quit  
  222. EOF  
  223.          ;;  
  224.      esac  
  225.    
  226.      if [ $? -eq 0 ] ; then  
  227.        echo ""  
  228.         echo "$0: ${INST}\"${ORACLE_SID}\" warm started."  
  229.      else  
  230.        $LOGMSG ""  
  231.        $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOTstarted."  
  232.      fi  
  233.    else  
  234.      $LOGMSG ""  
  235.      $LOGMSG "No init file found for ${INST}\"${ORACLE_SID}\"."  
  236.      $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOTstarted."  
  237.    fi  
  238.   fi  
  239. }  
  240.    
  241. # Starts an ASM Instance  
  242. startasminst() {  
  243.   #Called programs use same database ID  
  244.  export ORACLE_SID  
  245.  ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  246.   #Called scripts use same home directory  
  247.  export ORACLE_HOME  
  248.    
  249.   #For ASM instances, we have a dependency on the CSS service.  
  250.   #Wait here for it to become available before instance startup.  
  251.    
  252.   #Is the 10g install intact? Are all necessary binaries present?  
  253.   if[ ! -x $ORACLE_HOME/bin/crsctl ]; then  
  254.    $LOGMSG "$ORACLE_HOME/bin/crsctl not found when attempting tostart"  
  255.    $LOGMSG "  ASM instance$ORACLE_SID."  
  256.    
  257.  else  
  258.    COUNT=0  
  259.    $ORACLE_HOME/bin/crsctl check css  
  260.    RC=$?  
  261.    while [ "$RC" != "0" ];  
  262.      do  
  263.      COUNT=`expr $COUNT + 1`  
  264.      if [ $COUNT = 15 ] ; then  
  265.        # 15 tries with 20 sec interval => 5 minutes timeout  
  266.        $LOGMSG "Timed out waiting to start ASM instance$ORACLE_SID"          
  267.        $LOGMSG "  CSS service is NOTavailable."  
  268.         exit $COUNT  
  269.      fi  
  270.      $LOGMSG "Waiting for Oracle CSS service to be available beforestarting "  
  271.      $LOGMSG " ASM instance $ORACLE_SID. Wait $COUNT."  
  272.      sleep 20  
  273.      $ORACLE_HOME/bin/crsctl check css  
  274.      RC=$?  
  275.    done  
  276.   fi  
  277.  startinst  
  278. }  
  279.    
  280. # Start of dbstartupscript  
  281. #  
  282. # Loop for every entry in oratab file andand try to start  
  283. # that ORACLE.  
  284. #  
  285. # ASM instances need to be started before'Database instances'  
  286. # ASM instance is identified with '+'prefix in ORACLE_SID  
  287. # Following loop brings up ASM instance[s]  
  288.    
  289. cat $ORATAB | while read LINE  
  290. do  
  291. case $LINE in  
  292.  \#*)                ;;        #comment-line in oratab  
  293.   *)  
  294.  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  295.   if[ "$ORACLE_SID" = '*' ] ; then  
  296.     #same as NULL SID - ignore this entry  
  297.    ORACLE_SID=""  
  298.    continue  
  299.   fi  
  300.   #Proceed only if last field is 'Y'.  
  301.   if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then  
  302.     #If ASM instances  
  303.    if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then  
  304.      INST="ASM instance"  
  305.      ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  306.      # Called scripts use same home directory  
  307.      export ORACLE_HOME  
  308.      # file for logging script's output  
  309.      LOG=$ORACLE_HOME/startup.log  
  310.      touch $LOG  
  311.      chmod a+r $LOG  
  312.      echo "Processing $INST \"$ORACLE_SID\": log file$ORACLE_HOME/startup.log"  
  313.      startasminst >> $LOG 2>&1  
  314.    fi  
  315.   fi  
  316.   ;;  
  317. esac  
  318. done  
  319.    
  320. # exit if there was any trouble bringing upASM instance[s]  
  321. if [ "$?" != "0" ] ;then  
  322.  exit 2  
  323. fi  
  324.    
  325. #  
  326. # Following loop brings up 'Database instances'  
  327. #  
  328. cat $ORATAB | while read LINE  
  329. do  
  330. case $LINE in  
  331.  \#*)                ;;        #comment-line in oratab  
  332.   *)  
  333.  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  334.   if[ "$ORACLE_SID" = '*' ] ; then  
  335.     #same as NULL SID - ignore this entry  
  336.     ORACLE_SID=""  
  337.    continue  
  338.   fi  
  339.   #Proceed only if last field is 'Y'.  
  340.   if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then  
  341.     #If non-ASM instances  
  342.    if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then  
  343.      INST="Database instance"  
  344.      ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  345.      # Called scripts use same home directory  
  346.      export ORACLE_HOME  
  347.      # file for logging script's output  
  348.      LOG=$ORACLE_HOME/startup.log  
  349.      touch $LOG  
  350.      chmod a+r $LOG  
  351.      echo "Processing $INST \"$ORACLE_SID\": log file$ORACLE_HOME/startup.log"  
  352.      startinst >> $LOG 2>&1  
  353.    fi  
  354.   fi  
  355.   ;;  
  356. esac  
  357. done  
  358.    
  359. #  
  360. # Following loop brings up 'Databaseinstances' that have wait state 'W'  
  361. #  
  362. cat $ORATAB | while read LINE  
  363. do  
  364. case $LINE in  
  365.  \#*)                ;;        #comment-line in oratab  
  366.   *)  
  367.  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  368.   if[ "$ORACLE_SID" = '*' ] ; then  
  369.     #same as NULL SID - ignore this entry  
  370.    ORACLE_SID=""  
  371.    continue  
  372.   fi  
  373.   #Proceed only if last field is 'W'.  
  374.   if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then  
  375.    W_ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  376.     #DB instances with 'W' (wait state) have a dependency on ASM instances via CRS.  
  377.     #Wait here for 'all' ASM instances to become available.  
  378.    cat $ORATAB | while read LINE  
  379.    do  
  380.    case $LINE in  
  381.      \#*)                ;;        #comment-line in oratab  
  382.      *)  
  383.      ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  384.      if [ "$ORACLE_SID" = '*' ] ; then  
  385.        # same as NULL SID - ignore this entry  
  386.        ORACLE_SID=""  
  387.        continue  
  388.      fi  
  389.      if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then  
  390.        INST="ASM instance"  
  391.        ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  392.        if [ -x $ORACLE_HOME/bin/srvctl ] ; then  
  393.          COUNT=0  
  394.          NODE=`olsnodes -l`  
  395.          RNODE=`srvctl status asm -n $NODE | grep "$ORACLE_SID isrunning"`  
  396.          RC=$?  
  397.          while [ "$RC" != "0" ]; # wait until this comes up!  
  398.          do  
  399.            COUNT=$((COUNT+1))  
  400.            if [ $COUNT = 5 ] ; then  
  401.               # 5 tries with 60 sec interval=> 5 minutes timeout  
  402.               $LOGMSG "Error: Timed outwaiting on CRS to start ASM instance $ORACLE_SID"          
  403.               exit $COUNT  
  404.            fi  
  405.            $LOGMSG "Waiting for Oracle CRS service to start ASM instance$ORACLE_SID"  
  406.            $LOGMSG "Wait $COUNT."  
  407.            sleep 60  
  408.            RNODE=`srvctl status asm -n $NODE | grep "$ORACLE_SID isrunning"`  
  409.            RC=$?  
  410.          done  
  411.        else  
  412.          $LOGMSG "Error: \"${W_ORACLE_SID}\" has dependency on ASMinstance \"${ORACLE_SID}\""  
  413.          $LOGMSG "Error: Need $ORACLE_HOME/bin/srvctl to check thisdependency"  
  414.        fi  
  415.      fi     # asm instance  
  416.      ;;  
  417.     esac  
  418.    done # innner while  
  419.   fi  
  420.   ;;  
  421. esac  
  422. done # outer while  
  423.    
  424. # by now all the ASM instances have come upand we can proceed to bring up  
  425. # DB instance with 'W' wait status  
  426.    
  427. cat $ORATAB | while read LINE  
  428. do  
  429. case $LINE in  
  430.  \#*)                ;;        #comment-line in oratab  
  431.   *)  
  432.  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  433.   if[ "$ORACLE_SID" = '*' ] ; then  
  434.     #same as NULL SID - ignore this entry  
  435.    ORACLE_SID=""  
  436.    continue  
  437.   fi  
  438.   #Proceed only if last field is 'W'.  
  439.   if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then  
  440.    INST="Database instance"  
  441.    if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then  
  442.      $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOTstarted"  
  443.      $LOGMSG "Error: incorrect usage: 'W' not allowed for ASMinstances"  
  444.      continue  
  445.    fi  
  446.    ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  447.     #Called scripts use same home directory  
  448.    export ORACLE_HOME  
  449.     #file for logging script's output  
  450.    LOG=$ORACLE_HOME/startup.log  
  451.    touch $LOG  
  452.     chmod a+r $LOG  
  453.    echo "Processing $INST \"$ORACLE_SID\": log file$ORACLE_HOME/startup.log"  
  454.    startinst >> $LOG 2>&1  
  455.   fi  
  456.   ;;  
  457. esac  
  458. done  
  459. gg1:/u01/app/oracle/product/11.2.0.3/db_1/bin>  
linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款