Linux 下Oracle 開機自啟動 與 oratab, dbstart 指令碼 說明
一./etc/oratab說明
直接使用cat 檢視這個檔案:
- 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:
所以配置資料庫自啟動和關閉的步驟如下:
(1) 配置/etc/oratab
(2) 修改$ORACLE_HOME/bin/dbstart和dbshut,並將其新增到/etc/rc(.local) 檔案中。
這裡是使用oracle 自帶的dbstart 和dbshut指令碼,如果使用自己寫的指令碼來啟動或關閉DB 就不需要關心這個檔案的設定了。
二.$ORACLE_HOME/bin/dbstart,dbshut 說明
2.1 dbstart 指令碼
- 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 <
- connect internal
- shutdown abort
- EOF
- ;;
- *) $SQLDBA $args <
- connect / as sysdba
- shutdown abort
- quit
- EOF
- ;;
- esac
- if [ $? -eq 0 ] ; then
- STATUS=1
- else
- $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOTstarted."
- fi
- fi
- if[ $STATUS -eq 1 ] ; then
- if [ -e $SPFILE -o -e $SPFILE1 -o -e $PFILE ] ; then
- case $VERSION in
- "6") sqldbacommand=startup ;;
- "internal") $SQLDBA<
- connect internal
- startup
- EOF
- ;;
- *) $SQLDBA <
- connect / as sysdba
- startup
- quit
- EOF
- ;;
- esac
- if [ $? -eq 0 ] ; then
- echo ""
- echo "$0: ${INST}\"${ORACLE_SID}\" warm started."
- else
- $LOGMSG ""
- $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOTstarted."
- fi
- else
- $LOGMSG ""
- $LOGMSG "No init file found for ${INST}\"${ORACLE_SID}\"."
- $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOTstarted."
- fi
- fi
- }
- # Starts an ASM Instance
- startasminst() {
- #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
- #For ASM instances, we have a dependency on the CSS service.
- #Wait here for it to become available before instance startup.
- #Is the 10g install intact? Are all necessary binaries present?
- if[ ! -x $ORACLE_HOME/bin/crsctl ]; then
- $LOGMSG "$ORACLE_HOME/bin/crsctl not found when attempting tostart"
- $LOGMSG " ASM instance$ORACLE_SID."
- else
- COUNT=0
- $ORACLE_HOME/bin/crsctl check css
- RC=$?
- while [ "$RC" != "0" ];
- do
- COUNT=`expr $COUNT + 1`
- if [ $COUNT = 15 ] ; then
- # 15 tries with 20 sec interval => 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 指令碼
- 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<
- connect internal
- shutdown immediate
- EOF
- ;;
- *) $SQLDBA <
- connect / as sysdba
- shutdown immediate
- quit
- EOF
- ;;
- esac
- iftest $? -eq 0 ; then
- echo "${INST} \"${ORACLE_SID}\" shut down."
- else
- echo "${INST} \"${ORACLE_SID}\" not shut down."
- fi
- }
- #
- # Loop for every entry in oratab file andand try to shut down
- # that ORACLE
- #
- # Following loop shuts down 'DatabaseInstance[s]' with 'Y' 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}' -`" = "Y" ] ; 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 '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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15880878/viewspace-715444/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- RedHat Linux下Oracle啟動指令碼的建立 dbstart oracle8.1.6 (轉)RedhatLinuxOracle指令碼
- Linux 下oracle自啟動指令碼LinuxOracle指令碼
- Linux 下 自動啟動oracle資料配置說明LinuxOracle
- Linux下Oracle隨機自動啟動指令碼設定LinuxOracle隨機指令碼
- linux開機自動啟動指令碼Linux指令碼
- linux下新增oracle自啟動指令碼LinuxOracle指令碼
- linux下開機使用dbstart和dbshut自動啟動和關閉db!Linux
- LINUX下開機使用dbstart和dbshut自動啟動和關閉dbLinux
- Linux 新增指令碼開機自啟動Linux指令碼
- Linux下開機自動啟動OracleLinuxOracle
- windows下oracle自動啟動指令碼WindowsOracle指令碼
- linux下開機自動開啟單機oracleLinuxOracle
- 手寫linux下oracle的dbstart和dbshut指令碼LinuxOracle指令碼
- Oracle之 服務啟動&停止指令碼與開機自啟動(單例項)Oracle指令碼單例
- 開機自啟動Powershell指令碼指令碼
- LINUX開機自動啟動ORACLE資料庫和監聽指令碼LinuxOracle資料庫指令碼
- linux下dbstart,dbshut無法執行和自動啟動Oracle的辦法LinuxOracle
- Oracle Restart環境下的開機啟動指令碼OracleREST指令碼
- 開機自動啟動ORACLE ON LinuxOracleLinux
- Linux自啟動指令碼Linux指令碼
- linux設定開機自啟動指令碼的最佳方式Linux指令碼
- AIX 開機自啟動指令碼設定AI指令碼
- Ubuntu 設定開機自啟動指令碼Ubuntu指令碼
- 如何讓oracle DB、監聽和oem開機啟動(dbstart)Oracle
- 利用dbstart和dbshut指令碼自動啟動和停止資料庫的問題指令碼資料庫
- Linux配置開機自啟動執行指令碼方法有哪些?Linux指令碼
- Linux下新增自定義指令碼到開機自啟動,標準rpm,舉例:設定Apache自啟動Linux指令碼Apache
- UNIX下oracle啟動指令碼Oracle指令碼
- Oracle在linux下的開機自啟動(詳細)轉OracleLinux
- Linux 下軟體開機自啟動Linux
- linux7 開機自啟動oracleLinuxOracle
- linux下Oracle自動啟動與停止總結LinuxOracle
- SHELL指令碼實現Oracle自啟動與關閉指令碼Oracle
- solaris 10下的oracle 10g 自動啟動指令碼Oracle 10g指令碼
- 設定msyqlphp-fpm開機自動啟動指令碼PHP指令碼
- RedHat Linux下Oracle啟動指令碼的建立(轉)RedhatLinuxOracle指令碼
- oracle開機自啟動Oracle
- 再談用指令碼自動啟動關閉LINUX下的ORACLE資料庫指令碼LinuxOracle資料庫