Chinaunix首页 | 论坛 | 博客
  • 博客访问: 960168
  • 博文数量: 584
  • 博客积分: 2293
  • 博客等级: 大尉
  • 技术积分: 3045
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-28 11:15
文章分类

全部博文(584)

文章存档

2012年(532)

2011年(47)

2009年(5)

我的朋友

分类:

2012-03-31 20:51:08

Linux 下Oracle 开机自启动 与 oratab, dbstart 脚本 说明
分类: Oracle 基础知识 69人阅读 评论(0) 举报

 

一./etc/oratab说明

直接使用cat 查看这个文件:

 

  1. gg1:/home/oracle> cat /etc/oratab  
  2. #  
  3.    
  4. # This file is used by ORACLEutilities.  It is created by root.sh  
  5. # and updated by the Database ConfigurationAssistant when creating  
  6. # a database.  
  7.    
  8. # A colon, ':', is used as the fieldterminator.  A new line terminates  
  9. # the entry.  Lines beginning with a pound sign, '#', arecomments.  
  10. #  
  11. # Entries are of the form:  
  12. #  $ORACLE_SID:$ORACLE_HOME::  
  13. #  
  14. # The first and second fields are thesystem identifier and home  
  15. # directory of the databaserespectively.  The third filed indicates  
  16. # to the dbstart utility that the databaseshould , "Y", or should not,  
  17. # "N", be brought up at systemboot time.  
  18. #  
  19. # Multiple entries with the same$ORACLE_SID are not allowed.  
  20. #  
  21. #  
  22. gg1:/u01/app/oracle/product/11.2.0.3/db_1:N  
gg1:/home/oracle> cat /etc/oratab # # This file is used by ORACLEutilities. It is created by root.sh # and updated by the Database ConfigurationAssistant when creating # a database. # A colon, ':', is used as the fieldterminator. A new line terminates # the entry. Lines beginning with a pound sign, '#', arecomments. # # Entries are of the form: # $ORACLE_SID:$ORACLE_HOME:: # # The first and second fields are thesystem identifier and home # directory of the databaserespectively. The third filed indicates # to the dbstart utility that the databaseshould , "Y", or should not, # "N", be brought up at systemboot time. # # Multiple entries with the same$ORACLE_SID are not allowed. # # gg1:/u01/app/oracle/product/11.2.0.3/db_1:N

这里是我测试环境上的文件,在这个注释里面,对这个文件讲的比较清楚。/etc/oratab 由root.sh 脚本创建,在用DBCA 创建实例时也会更新这个文件。

 

当$ORACLE_SID:$ORACLE_HOME: 设置为Y时,允许实例自启动,当设置为N时,则不允许自启动。 这个文件里的配置仅仅起一个开关的作用,其并不会具体的执行启动和关闭,具体的操作由$ORACLE_HOME/bin/dbstart和dbshut 脚本来实现。 这2个脚本在执行时会检查/etc/oratab 文件里的配置,为Y时才能继续执行。

 

所以配置数据库自启动和关闭的步骤如下:

(1)    配置/etc/oratab

(2)    修改$ORACLE_HOME/bin/dbstart和dbshut,并将其添加到/etc/rc(.local) 文件中。

 

这里是使用oracle 自带的dbstart 和dbshut脚本,如果使用自己写的脚本来启动或关闭DB 就不需要关心这个文件的设置了。

 

二.$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. --这里就是我们之前说的,这个仅启动/etc/oratab 文件中标记为Y的实例。  
  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. --如果是ASM 实例,那么只能从rc.local中调用,否则CSS 服务可能不可用。  
  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. --注意这里的W,其表示等待所有的ASM 实例启动完毕后在启动数据库。  
  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. --启动日志存放在$ORACLE_HOME/startup.log里。  
  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::  
  50. #   An example entry:  
  51. #   main:/usr/lib/oracle/emagent_10g:Y  
  52. #  
  53. # Overall algorithm:  
  54. --启动顺序  
  55. # 1) Bring up all ASM instances with 'Y'entry in status field in oratab entry  
  56. --启动状态为Y的所有ASM 实例  
  57. # 2) Bring up all Database instances with'Y' entry in status field in  
  58. #   oratab entry  
  59. --启动所有状态为Y的数据库实例  
  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. --如果数据库的状态为W,则等待ASM 实例启动完毕,再启动  
  66. # 4) Bring up all Database instances with'W' entry in status field in  
  67. #   oratab entry  
  68. --启动所有状态为W的数据库实例  
  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 <
  190. connect internal  
  191. shutdown abort  
  192. EOF  
  193.        ;;  
  194.      *)  $SQLDBA $args <
  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<
  214. connect internal  
  215. startup  
  216. EOF  
  217.          ;;  
  218.        *)  $SQLDBA <
  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>  
gg1:/u01/app/oracle/product/11.2.0.3/db_1/bin>cat dbstart #!/bin/sh # # $Id: dbstart.sh 22-may-2008.05:05:45arogers Exp $ # Copyright (c) 1991, 2008, Oracle. Allrights reserved. # ################################### # # usage: dbstart $ORACLE_HOME # # This script is used tostart ORACLE from /etc/rc(.local). # It should ONLY beexecuted as part of the system boot procedure. # # This script will start all databaseslisted in the oratab file # whose third field is a"Y". If the third field is setto "Y" and # there is no ORACLE_SID for an entry (thefirst field is a *), # then this script will ignore that entry. --这里就是我们之前说的,这个仅启动/etc/oratab 文件中标记为Y的实例。 # # This script requires that ASMORACLE_SID's start with a +, and # that non-ASM instance ORACLE_SID's do notstart with a +. # # 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. --如果是ASM 实例,那么只能从rc.local中调用,否则CSS 服务可能不可用。 # # If you want dbstart to auto-start asingle-instance database that uses # an ASM server that is auto-started by CRS(this is the default behavior # for an ASM cluster), you must change thedatabase's ORATAB entry to use # a third field of "W" and theASM's ORATAB entry to use a third field of "N". # These values specify that dbstartauto-starts the database only after # the ASM instance is up and running. --注意这里的W,其表示等待所有的ASM 实例启动完毕后在启动数据库。 # # Note: # Use ORACLE_TRACE=T for tracing thisscript. # # The progress log for each instancebringup plus Error and Warning message[s] # are logged in file $ORACLE_HOME/startup.log.The error messages related to # instance bringup are also logged tosyslog (system log module). # The Listener log is located at$ORACLE_HOME_LISTNER/listener.log --启动日志存放在$ORACLE_HOME/startup.log里。 # # On all UNIX platforms except SOLARIS # ORATAB=/etc/oratab # # To configure, update ORATAB withInstances that need to be started up # Entries are of the form: # $ORACLE_SID:$ORACLE_HOME:: # An example entry: # main:/usr/lib/oracle/emagent_10g:Y # # Overall algorithm: --启动顺序 # 1) Bring up all ASM instances with 'Y'entry in status field in oratab entry --启动状态为Y的所有ASM 实例 # 2) Bring up all Database instances with'Y' entry in status field in # oratab entry --启动所有状态为Y的数据库实例 # 3) If there are Database instances with'W' entry in status field # then # iterate over all ASM instances (irrespective of 'Y' or 'N') AND # wait for all of them to be started # fi --如果数据库的状态为W,则等待ASM 实例启动完毕,再启动 # 4) Bring up all Database instances with'W' entry in status field in # oratab entry --启动所有状态为W的数据库实例 # ##################################### LOGMSG="logger -puser.alert -s " trap 'exit' 1 2 3 # for script tracing case $ORACLE_TRACE in T)set -x ;; esac # Set path if path not set (if called from/etc/rc) SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ;export PATH SAVE_LLP=$LD_LIBRARY_PATH # First argument is used to bring up OracleNet Listener ORACLE_HOME_LISTNER=$1 if [ ! $ORACLE_HOME_LISTNER ] ; then echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start OracleNet Listener" echo "Usage: $0 ORACLE_HOME" else LOG=$ORACLE_HOME_LISTNER/listener.log #Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to # adifferent ORACLE_HOME for each entry in the oratab. export ORACLE_HOME=$ORACLE_HOME_LISTNER #Start Oracle Net Listener if[ -x $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then echo "$0: Starting Oracle Net Listener" >> $LOG2>&1 $ORACLE_HOME_LISTNER/bin/lsnrctl start >> $LOG 2>&1 & VER10LIST=`$ORACLE_HOME_LISTNER/bin/lsnrctl version | grep "LSNRCTLfor " | cut -d' ' -f5 | cut -d'.' -f1` export VER10LIST else echo "Failed to auto-start Oracle Net Listener using$ORACLE_HOME_LISTNER/bin/tnslsnr" fi fi # Set this in accordance with the platform ORATAB=/etc/oratab if [ ! $ORATAB ] ; then echo "$ORATAB not found" exit 1; fi # Checks Version Mismatch between Listenerand Database Instance. # A version 10 listener is required for anOracle Database 10g database. # Previous versions of the listener are notsupported for use with an Oracle # Database 10g database. However, it ispossible to use a version 10 listener # with previous versions of the Oracledatabase. checkversionmismatch() { if[ $VER10LIST ] ; then VER10INST=`sqlplus -V | grep "Release " | cut -d' ' -f3 | cut-d'.' -f1` if [ $VER10LIST -lt $VER10INST ] ; then $LOGMSG "Listener version $VER10LIST NOT supported with Databaseversion $VER10INST" $LOGMSG "Restart Oracle Net Listener using an alternateORACLE_HOME_LISTNER:" $LOGMSG "lsnrctl start" fi fi } # Starts a DatabaseInstance startinst() { #Called programs use same database ID export ORACLE_SID #Put $ORACLE_HOME/bin into PATH and export. PATH=$ORACLE_HOME/bin:${SAVE_PATH} ; export PATH #add for bug # 652997 LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${SAVE_LLP} ; export LD_LIBRARY_PATH PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora SPFILE=${ORACLE_HOME}/dbs/spfile${ORACLE_SID}.ora SPFILE1=${ORACLE_HOME}/dbs/spfile.ora echo "" echo "$0: Starting up database \"$ORACLE_SID\"" date echo "" checkversionmismatch #See if it is a V6 or V7 database VERSION=undef if[ -f $ORACLE_HOME/bin/sqldba ] ; then SQLDBA=sqldba VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk ' /SQL\*DBA: (Release|Version)/ {split($3, V, ".") ; print V[1]}'` case $VERSION in "6") ;; *) VERSION="internal" ;; esac else if [ -f $ORACLE_HOME/bin/svrmgrl ] ; then SQLDBA=svrmgrl VERSION="internal" else SQLDBA="sqlplus /nolog" fi fi STATUS=1 if[ -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.dbf ] ; then STATUS="-1" fi if[ -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.ora ] ; then STATUS="-1" fi pmon=`ps -ef | grep -w "ora_pmon_$ORACLE_SID" | grep -v grep` if[ "$pmon" != "" ] ; then STATUS="-1" $LOGMSG "Warning: ${INST} \"${ORACLE_SID}\" alreadystarted." fi if[ $STATUS -eq -1 ] ; then $LOGMSG "Warning: ${INST} \"${ORACLE_SID}\" possibly leftrunning when system went down (system crash?)." $LOGMSG "Action: Notify Database Administrator." case $VERSION in "6") sqldba"command=shutdown abort" ;; "internal") $SQLDBA$args < 5 minutes timeout $LOGMSG "Timed out waiting to start ASM instance$ORACLE_SID" $LOGMSG " CSS service is NOTavailable." exit $COUNT fi $LOGMSG "Waiting for Oracle CSS service to be available beforestarting " $LOGMSG " ASM instance $ORACLE_SID. Wait $COUNT." sleep 20 $ORACLE_HOME/bin/crsctl check css RC=$? done fi startinst } # Start of dbstartupscript # # Loop for every entry in oratab file andand try to start # that ORACLE. # # ASM instances need to be started before'Database instances' # ASM instance is identified with '+'prefix in ORACLE_SID # Following loop brings up ASM instance[s] cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if[ "$ORACLE_SID" = '*' ] ; then #same as NULL SID - ignore this entry ORACLE_SID="" continue fi #Proceed only if last field is 'Y'. if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then #If ASM instances if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then INST="ASM instance" ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` # Called scripts use same home directory export ORACLE_HOME # file for logging script's output LOG=$ORACLE_HOME/startup.log touch $LOG chmod a+r $LOG echo "Processing $INST \"$ORACLE_SID\": log file$ORACLE_HOME/startup.log" startasminst >> $LOG 2>&1 fi fi ;; esac done # exit if there was any trouble bringing upASM instance[s] if [ "$?" != "0" ] ;then exit 2 fi # # Following loop brings up 'Database instances' # cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if[ "$ORACLE_SID" = '*' ] ; then #same as NULL SID - ignore this entry ORACLE_SID="" continue fi #Proceed only if last field is 'Y'. if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then #If non-ASM instances if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then INST="Database instance" ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` # Called scripts use same home directory export ORACLE_HOME # file for logging script's output LOG=$ORACLE_HOME/startup.log touch $LOG chmod a+r $LOG echo "Processing $INST \"$ORACLE_SID\": log file$ORACLE_HOME/startup.log" startinst >> $LOG 2>&1 fi fi ;; esac done # # Following loop brings up 'Databaseinstances' that have wait state 'W' # cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if[ "$ORACLE_SID" = '*' ] ; then #same as NULL SID - ignore this entry ORACLE_SID="" continue fi #Proceed only if last field is 'W'. if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then W_ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` #DB instances with 'W' (wait state) have a dependency on ASM instances via CRS. #Wait here for 'all' ASM instances to become available. cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then # same as NULL SID - ignore this entry ORACLE_SID="" continue fi if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then INST="ASM instance" ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` if [ -x $ORACLE_HOME/bin/srvctl ] ; then COUNT=0 NODE=`olsnodes -l` RNODE=`srvctl status asm -n $NODE | grep "$ORACLE_SID isrunning"` RC=$? while [ "$RC" != "0" ]; # wait until this comes up! do COUNT=$((COUNT+1)) if [ $COUNT = 5 ] ; then # 5 tries with 60 sec interval=> 5 minutes timeout $LOGMSG "Error: Timed outwaiting on CRS to start ASM instance $ORACLE_SID" exit $COUNT fi $LOGMSG "Waiting for Oracle CRS service to start ASM instance$ORACLE_SID" $LOGMSG "Wait $COUNT." sleep 60 RNODE=`srvctl status asm -n $NODE | grep "$ORACLE_SID isrunning"` RC=$? done else $LOGMSG "Error: \"${W_ORACLE_SID}\" has dependency on ASMinstance \"${ORACLE_SID}\"" $LOGMSG "Error: Need $ORACLE_HOME/bin/srvctl to check thisdependency" fi fi # asm instance ;; esac done # innner while fi ;; esac done # outer while # by now all the ASM instances have come upand we can proceed to bring up # DB instance with 'W' wait status cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if[ "$ORACLE_SID" = '*' ] ; then #same as NULL SID - ignore this entry ORACLE_SID="" continue fi #Proceed only if last field is 'W'. if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then INST="Database instance" if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOTstarted" $LOGMSG "Error: incorrect usage: 'W' not allowed for ASMinstances" continue fi ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` #Called scripts use same home directory export ORACLE_HOME #file for logging script's output LOG=$ORACLE_HOME/startup.log touch $LOG chmod a+r $LOG echo "Processing $INST \"$ORACLE_SID\": log file$ORACLE_HOME/startup.log" startinst >> $LOG 2>&1 fi ;; esac done gg1:/u01/app/oracle/product/11.2.0.3/db_1/bin> 


2.2 dbshut 脚本

  1. gg1:/u01/app/oracle/product/11.2.0.3/db_1/bin>cat dbshut  
  2. #!/bin/sh  
  3. #  
  4. # $Id: dbshut.sh 22-may-2008.05:19:31arogers Exp $  
  5. # Copyright (c) 1991, 2008, Oracle. Allrights reserved.   
  6. #  
  7.    
  8. ###################################  
  9. #  
  10. # usage: dbshut $ORACLE_HOME  
  11. #  
  12. # This script is used to shutdown ORACLEfrom /etc/rc(.local).  
  13. # It should ONLY be executed as part of thesystem boot procedure.  
  14. #  
  15. # This script will shutdown all databaseslisted in the oratab file  
  16. # whose third field is a "Y" or"W".  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. #  
  20. # This script requires that ASMORACLE_SID's start with a +, and  
  21. # that non-ASM instance ORACLE_SID's do notstart with a +.  
  22. #  
  23. # Note:  
  24. # Use ORACLE_TRACE=T for tracing this script.  
  25. # Oracle Net Listener is also shutdownusing this script.  
  26. #  
  27. # The progress log for each instanceshutdown is logged in file  
  28. # $ORACLE_HOME/shutdown.log.  
  29. #  
  30. # On all UNIX platforms except SOLARIS  
  31. # ORATAB=/etc/oratab  
  32. #  
  33. # To configure, update ORATAB withInstances that need to be shutdown  
  34. #   Entries are of the form:  
  35. #   $ORACLE_SID:$ORACLE_HOME::  
  36. #   An example entry:  
  37. #   main:/usr/lib/oracle/emagent_10g:Y  
  38. #  
  39. #####################################  
  40.    
  41. trap 'exit' 1 2 3  
  42. case $ORACLE_TRACE in  
  43.   T) set-x ;;  
  44. esac  
  45.    
  46. # Set path if path not set (if called from/etc/rc)  
  47. SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ;export PATH  
  48. SAVE_LLP=$LD_LIBRARY_PATH  
  49.    
  50. # The this to bring down Oracle Net Listener  
  51. ORACLE_HOME_LISTNER=$1  
  52. if [ ! $ORACLE_HOME_LISTNER ] ; then  
  53.   echo"ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle NetListener"  
  54.  echo "Usage: $0 ORACLE_HOME"  
  55. else  
  56.  LOG=$ORACLE_HOME_LISTNER/listener.log  
  57.    
  58.   #Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to  
  59.   # adifferent ORACLE_HOME for each entry in the oratab.  
  60.  export ORACLE_HOME=$ORACLE_HOME_LISTNER  
  61.    
  62.   #Stop Oracle Net Listener  
  63.   if[ -f $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then  
  64.    echo "$0: Stoping Oracle Net Listener" >> $LOG2>&1  
  65.    $ORACLE_HOME_LISTNER/bin/lsnrctl stop >> $LOG 2>&1 &  
  66.  else  
  67.    echo "Failed to auto-stop Oracle Net Listener using$ORACLE_HOME_LISTNER/bin/tnslsnr"  
  68.   fi  
  69. fi  
  70.    
  71. # Set this in accordance with the platform  
  72. ORATAB=/etc/oratab  
  73. if [ ! $ORATAB ] ; then  
  74.  echo "$ORATAB not found"  
  75.  exit 1;  
  76. fi  
  77.    
  78. # Stops an instance  
  79. stopinst() {  
  80.  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  81.   if[ "$ORACLE_SID" = '*' ] ; then  
  82.    ORACLE_SID=""  
  83.   fi  
  84. # Called programs use same database ID  
  85.  export ORACLE_SID  
  86.  ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  87. # Called scripts use same home directory  
  88.  export ORACLE_HOME  
  89. # Put $ORACLE_HOME/bin into PATH andexport.  
  90.  PATH=$ORACLE_HOME/bin:${SAVE_PATH} ; export PATH  
  91. # add for bug 652997  
  92.  LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${SAVE_LLP} ; export LD_LIBRARY_PATH  
  93.  PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora  
  94.    
  95. # See if it is a V6 or V7 database  
  96.  VERSION=undef  
  97.   if[ -f $ORACLE_HOME/bin/sqldba ] ; then  
  98.    SQLDBA=sqldba  
  99.    VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk '  
  100.      /SQL\*DBA: (Release|Version)/ {split($3, V, ".") ;  
  101.      print V[1]}'`  
  102.    case $VERSION in  
  103.      "6") ;;  
  104.      *) VERSION="internal" ;;  
  105.    esac  
  106.  else  
  107.    if [ -f $ORACLE_HOME/bin/svrmgrl ] ; then  
  108.      SQLDBA=svrmgrl  
  109.      VERSION="internal"  
  110.    else  
  111.      SQLDBA="sqlplus /nolog"  
  112.     fi  
  113.   fi  
  114.    
  115.  case $VERSION in  
  116.    "6")  sqldbacommand=shutdown ;;  
  117.    "internal")  $SQLDBA<
  118. connect internal  
  119. shutdown immediate  
  120. EOF  
  121.     ;;  
  122.     *)  $SQLDBA <
  123. connect / as sysdba  
  124. shutdown immediate  
  125. quit  
  126. EOF  
  127.     ;;  
  128.  esac  
  129.    
  130.   iftest $? -eq 0 ; then  
  131.    echo "${INST} \"${ORACLE_SID}\" shut down."  
  132.  else  
  133.    echo "${INST} \"${ORACLE_SID}\" not shut down."  
  134.   fi  
  135. }  
  136.    
  137. #  
  138. # Loop for every entry in oratab file andand try to shut down  
  139. # that ORACLE  
  140. #  
  141. # Following loop shuts down 'DatabaseInstance[s]' with 'Y' entry  
  142.    
  143. cat $ORATAB | while read LINE  
  144. do  
  145.  case $LINE in  
  146.  \#*)                ;;        #comment-line in oratab  
  147.   *)  
  148.  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  149.   if[ "$ORACLE_SID" = '*' ] ; then  
  150.      # NULL SID - ignore  
  151.      ORACLE_SID=""  
  152.      continue  
  153.   fi  
  154.   #Proceed only if last field is 'Y' or 'W'  
  155.   if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then  
  156.    if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then  
  157.      INST="Database instance"  
  158.      ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  159.      LOG=$ORACLE_HOME/shutdown.log  
  160.      echo "Processing $INST \"$ORACLE_SID\": log file$LOG"  
  161.      stopinst >> $LOG 2>&1  
  162.    fi  
  163.   fi  
  164.   ;;  
  165.  esac  
  166. done  
  167.    
  168. #  
  169. # Following loop shuts down 'DatabaseInstance[s]' with 'W' entry  
  170. #  
  171. cat $ORATAB | while read LINE  
  172. do  
  173.  case $LINE in  
  174.  \#*)                ;;        #comment-line in oratab  
  175.   *)  
  176.  ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  177.   if[ "$ORACLE_SID" = '*' ] ; then  
  178.      # NULL SID - ignore  
  179.      ORACLE_SID=""  
  180.      continue  
  181.   fi  
  182.   #Proceed only if last field is 'Y' or 'W'  
  183.   if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then  
  184.    if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then  
  185.      INST="Database instance"  
  186.      ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  187.      LOG=$ORACLE_HOME/shutdown.log  
  188.      echo "Processing $INST \"$ORACLE_SID\": log file$LOG"  
  189.      stopinst >> $LOG 2>&1  
  190.    fi  
  191.   fi  
  192.   ;;  
  193.  esac  
  194. done  
  195.    
  196. #  
  197. # Following loop shuts down 'ASMInstance[s]'  
  198. #  
  199.    
  200. cat $ORATAB | while read LINE  
  201. do  
  202.   case$LINE in  
  203.    \#*)                ;;        #comment-line in oratab  
  204.    *)  
  205.    ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -`  
  206.    if [ "$ORACLE_SID" = '*' ] ; then  
  207.      # NULL SID - ignore  
  208.      ORACLE_SID=""  
  209.      continue  
  210.    fi  
  211.     #Proceed only if last field is 'Y'.  
  212.     #Entries whose last field is not Y or N are not DB entry, ignore them.  
  213.    if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y"] ; then  
  214.      if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then  
  215.        INST="ASM instance"  
  216.        ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -`  
  217.        LOG=$ORACLE_HOME/shutdown.log  
  218.        echo "Processing $INST \"$ORACLE_SID\": log file$LOG"  
  219.        stopinst >> $LOG 2>&1  
  220.      fi  
  221.    fi  
  222.   ;;  
  223.  esac  
  224. done  
  225. gg1:/u01/app/oracle/product/11.2.0.3/db_1/bin>  
gg1:/u01/app/oracle/product/11.2.0.3/db_1/bin>cat dbshut #!/bin/sh # # $Id: dbshut.sh 22-may-2008.05:19:31arogers Exp $ # Copyright (c) 1991, 2008, Oracle. Allrights reserved. # ################################### # # usage: dbshut $ORACLE_HOME # # This script is used to shutdown ORACLEfrom /etc/rc(.local). # It should ONLY be executed as part of thesystem boot procedure. # # This script will shutdown all databaseslisted in the oratab file # whose third field is a "Y" or"W". If the third field is setto "Y" and # there is no ORACLE_SID for an entry (thefirst field is a *), # then this script will ignore that entry. # # This script requires that ASMORACLE_SID's start with a +, and # that non-ASM instance ORACLE_SID's do notstart with a +. # # Note: # Use ORACLE_TRACE=T for tracing this script. # Oracle Net Listener is also shutdownusing this script. # # The progress log for each instanceshutdown is logged in file # $ORACLE_HOME/shutdown.log. # # On all UNIX platforms except SOLARIS # ORATAB=/etc/oratab # # To configure, update ORATAB withInstances that need to be shutdown # Entries are of the form: # $ORACLE_SID:$ORACLE_HOME:: # An example entry: # main:/usr/lib/oracle/emagent_10g:Y # ##################################### trap 'exit' 1 2 3 case $ORACLE_TRACE in T) set-x ;; esac # Set path if path not set (if called from/etc/rc) SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ;export PATH SAVE_LLP=$LD_LIBRARY_PATH # The this to bring down Oracle Net Listener ORACLE_HOME_LISTNER=$1 if [ ! $ORACLE_HOME_LISTNER ] ; then echo"ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle NetListener" echo "Usage: $0 ORACLE_HOME" else LOG=$ORACLE_HOME_LISTNER/listener.log #Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to # adifferent ORACLE_HOME for each entry in the oratab. export ORACLE_HOME=$ORACLE_HOME_LISTNER #Stop Oracle Net Listener if[ -f $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then echo "$0: Stoping Oracle Net Listener" >> $LOG2>&1 $ORACLE_HOME_LISTNER/bin/lsnrctl stop >> $LOG 2>&1 & else echo "Failed to auto-stop Oracle Net Listener using$ORACLE_HOME_LISTNER/bin/tnslsnr" fi fi # Set this in accordance with the platform ORATAB=/etc/oratab if [ ! $ORATAB ] ; then echo "$ORATAB not found" exit 1; fi # Stops an instance stopinst() { ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if[ "$ORACLE_SID" = '*' ] ; then ORACLE_SID="" fi # Called programs use same database ID export ORACLE_SID ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` # Called scripts use same home directory export ORACLE_HOME # Put $ORACLE_HOME/bin into PATH andexport. PATH=$ORACLE_HOME/bin:${SAVE_PATH} ; export PATH # add for bug 652997 LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${SAVE_LLP} ; export LD_LIBRARY_PATH PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora # See if it is a V6 or V7 database VERSION=undef if[ -f $ORACLE_HOME/bin/sqldba ] ; then SQLDBA=sqldba VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk ' /SQL\*DBA: (Release|Version)/ {split($3, V, ".") ; print V[1]}'` case $VERSION in "6") ;; *) VERSION="internal" ;; esac else if [ -f $ORACLE_HOME/bin/svrmgrl ] ; then SQLDBA=svrmgrl VERSION="internal" else SQLDBA="sqlplus /nolog" fi fi case $VERSION in "6") sqldbacommand=shutdown ;; "internal") $SQLDBA<> $LOG 2>&1 fi fi ;; esac done # # Following loop shuts down 'DatabaseInstance[s]' with 'W' entry # cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if[ "$ORACLE_SID" = '*' ] ; then # NULL SID - ignore ORACLE_SID="" continue fi #Proceed only if last field is 'Y' or 'W' if[ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then INST="Database instance" ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` LOG=$ORACLE_HOME/shutdown.log echo "Processing $INST \"$ORACLE_SID\": log file$LOG" stopinst >> $LOG 2>&1 fi fi ;; esac done # # Following loop shuts down 'ASMInstance[s]' # cat $ORATAB | while read LINE do case$LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then # NULL SID - ignore ORACLE_SID="" continue fi #Proceed only if last field is 'Y'. #Entries whose last field is not Y or N are not DB entry, ignore them. if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y"] ; then if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then INST="ASM instance" ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` LOG=$ORACLE_HOME/shutdown.log echo "Processing $INST \"$ORACLE_SID\": log file$LOG" stopinst >> $LOG 2>&1 fi fi ;; esac done gg1:/u01/app/oracle/product/11.2.0.3/db_1/bin>

通过以上信息,我们可以看出,我们只需要修改/etc/oratab脚本就可以了,dbstart 和dbshut命令可以从/etc/oratab里获取需要的参数值。

 

三.DB 开机自启动示例 3.1 修改/etc/oratab的值为Y

gg1:/u01/app/oracle/product/11.2.0.3/db_1/bin>ll /etc/oratab

-rw-rw-r-- 1 oracle oinstall 722 Jan 3020:36 /etc/oratab

gg1:/u01/app/oracle/product/11.2.0.3/db_1/bin>cat /etc/oratab

#

gg1:/u01/app/oracle/product/11.2.0.3/db_1:Y

 

3.2 修改dbstart的ORACLE_HOME_LISTNER,使其指向$ORACLE_HOME:

# First argument is used to bring up OracleNet Listener

ORACLE_HOME_LISTNER=$ORACLE_HOME

 

3.3  用root用户在rc.local里添加如下内容:

 

[root@gg1 ~]# cat /etc/rc.local  

#!/bin/sh

#

# This script will be executed *after* allthe other init scripts.

# You can put your own initialization stuffin here if you don't

# want to do the full Sys V style initstuff.

 

touch /var/lock/subsys/local

su - oracle -c"/u01/app/oracle/product/11.2.0.3/db_1/bin/dbstart"

su - oracle -c"/u01/app/oracle/product/11.2.0.3/db_1/bin/emctl start dbconsole"

 

这里注意必须用oracle 用户来启动脚本。

 

3.4 reboot 系统,Oracle就自动启动了。

 

在我们的配置中,启动的包括监听,实例和OEM。

 

启动日志如下:

gg1:/u01/app/oracle/product/11.2.0.3/db_1>cat startup.log

 

/u01/app/oracle/product/11.2.0.3/db_1/bin/dbstart:Starting up database "gg1"

Mon Jan 30 20:48:26 CST 2012

 

 

SQL*Plus: Release 11.2.0.3.0 Production onMon Jan 30 20:48:31 2012

 

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

 

SQL> Connected to an idle instance.

SQL> ORACLE instance started.

 

Total System Global Area  939495424 bytes

Fixed Size                  2233960 bytes

Variable Size             675285400 bytes

Database Buffers          255852544 bytes

Redo Buffers                6123520 bytes

Database mounted.

Database opened.

SQL> Disconnected from Oracle Database11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production

With the Partitioning, OLAP, Data Mining andReal Application Testing options

 

/u01/app/oracle/product/11.2.0.3/db_1/bin/dbstart:Database instance "gg1" warm started.

 

 

gg1:/u01/app/oracle/product/11.2.0.3/db_1>cat listener.log

/u01/app/oracle/product/11.2.0.3/db_1/bin/dbstart:Starting Oracle Net Listener

 

LSNRCTL for Linux: Version 11.2.0.3.0 -Production on 30-JAN-2012 21:24:37

 

Copyright (c) 1991, 2011, Oracle.  All rights reserved.

 

Starting /u01/app/oracle/product/11.2.0.3/db_1/bin/tnslsnr:please wait...

 

TNSLSNR for Linux: Version 11.2.0.3.0 -Production

System parameter file is/u01/app/oracle/product/11.2.0.3/db_1/network/admin/listener.ora

Log messages written to/u01/app/oracle/diag/tnslsnr/gg1/listener/alert/log.xml

Listening on:(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=gg1)(PORT=1521)))

Listening on:(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

 

Connecting to(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=gg1)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version11.2.0.3.0 - Production

Start Date                30-JAN-2012 21:24:40

Uptime                    0 days 0 hr. 0 min. 1 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File  /u01/app/oracle/product/11.2.0.3/db_1/network/admin/listener.ora

Listener Log File         /u01/app/oracle/diag/tnslsnr/gg1/listener/alert/log.xml

Listening Endpoints Summary...

 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=gg1)(PORT=1521)))

 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

The listener supports no services

The command completed successfully

 

 

阅读(1590) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~