一./etc/oratab说明

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

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

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

Linux 下配置Oracle开机自动启动的更多相关文章

  1. linux下配置tomcat开机自启动

    Linux下配置tomcat开机自启动   1.写一个tomcat脚本,内容如下,设置其权限为755,放在/etc/init.d/目录下 #!/bin/bash## /etc/init.d/tomca ...

  2. linux系统下设置oracle开机自动启动

    在Linux系统中,安装好oracle数据库服务后,并不像在Windows系统下一样,oracle服务在默认情况下会随时系统的启动自动启动.Linux系统中,是需要用户去手动进行设置,才能实现orac ...

  3. linux下配置Tomcat开机启动

    我们在linux下安装好tomcat之后:经常是需要配置到开机启动的: 这样的话就不需要我们每次重启linux服务器之后自己在登陆运行startup.sh文件启动tomcat了 本次的演示环境是在ce ...

  4. Linux下的Oracle 11gr2安装完成的的自启动操作。

    Linux下的Oracle在安装结束后是处于运行状态的.重启机器后,Oracle不会像在Windows下那样将Oracle添加到Windows服务,在linux下需要手动启动Orcle服务 以orac ...

  5. Linux下进行Oracle数据库安装

    一般来说我们Windows下进行安装Oracle都很简单,但Linux下却要输入很多命令,以下的安装步骤是本人经过多次安装Linux下的Oracle经验,希望能帮到大家 一.在Linux服务器上创建o ...

  6. Linux下配置Lamp

    linux下配置lamp步骤: 一.快速安装Apache+PHP5+MySql 先更新: # yum update 然后安装LAMP环境:(163的yum源上只有php5.1.6 mysql 5.0. ...

  7. Linux下配置PHP开发环境

    转载于: http://www.uxtribe.com/php/405.html 该站下有系列PHP文章. 在Linux下搭建PHP环境比Windows下要复杂得多.除了安装Apache,PHP等软件 ...

  8. Linux下配置JDK

    下面以CentOS为例,详细说一下Linux下配置JDK的过程 首先按照约定俗成的习惯,将jdk放在/usr/local/java下,首先进入/usr/local然后新建一个目录java 然后我们需要 ...

  9. linux下启动oracle服务命令

    以redflag(redhat /centos)linux下的 oracle 10g 为例: 如果oracle安装和配置都没有问题的话: 依次执行以下代码即可启动oracle服务. #su - ora ...

  10. Ubuntu Linux下安装Oracle JDK

    from://http://blog.csdn.net/gobitan/article/details/24322561 Ubuntu Linux下安装Oracle JDK Dennis Hu 201 ...

随机推荐

  1. 02-MySQL基本操作

    SQL 的一些简单语法规则 结束符 SQL 指令需要语句结束符,默认是英文分号;. 当然,还有另外两个结束符: \g 与英文分号;等效. \G:将查到的结构旋转90度变成纵向. 反引号`` SQL语句 ...

  2. [转帖]Mysql 常用命令行,持续补充

    https://www.cnblogs.com/wzj1223/p/13152446.html 1.常用命令行 # 登录Mysql mysql -uroot -proot # 查看所有数据库 show ...

  3. [转帖]如何提高Linux下块设备IO的整体性能?

    http://www.yunweipai.com/6989.html 运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai领取学习更多免费Linux ...

  4. [转帖]Chrome 109发布,最后一个支持Windows 7/8的版本

    https://www.163.com/dy/article/HQR3QQFD0511CUMI.html 出品 | OSC开源社区(ID:oschina2013) Google 在去年 12 月 1 ...

  5. Oracle 以及 达梦数据库简单查询所有表行数的存储过程

    1. 今天有一个场景需要查询一个数据库实例下面所有的表的行数. 本来想查询 user_tables 视图 但是发现 这个视图里面 达梦数据库 里面存的是null的.. 百度之后发现一个解决方案是 使用 ...

  6. zabbix 6.0 官方文档

    Choose your platform   ZABBIX VERSION 6.0 LTS 5.4 5.0 LTS 4.0 LTS OS DISTRIBUTION Red Hat Enterprise ...

  7. K8S 知识点

    1. K8S集群大小 在 v1.7 版本中,Kubernetes 支持集群节点(node)数可达1000个.更具体地说,我们配置能够支持所有如下条件: 不超过2000个节点 不超过总共6000个 po ...

  8. 记一次 .NET某工控自动化系统 崩溃分析

    一:背景 1. 讲故事 前些天微信上有位朋友找到我,说他的程序偶发崩溃,分析了个把星期也没找到问题,耗费了不少人力物力,让我能不能帮他看一下,给我申请了经费,哈哈,遇到这样的朋友就是爽快,刚好周二晚上 ...

  9. js赋值的两种方式

    第一种 let obj=[ { value:undefined } ] obj[0].value.value='zahngsan' obj[0].value.label='张三' 机智的小伙伴,可能已 ...

  10. Registration Authority 简介

    RA 功能简介 在公共密钥基础设施(PKI)中,CA(Certificate Authority,证书颁发机构)系统的RA(Registration Authority,注册机构)是PKI体系结构的重 ...