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

2014-11-24 12:36:51 · 作者: · 浏览: 3
_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/p