Chinaunix首页 | 论坛 | 博客
  • 博客访问: 154139
  • 博文数量: 40
  • 博客积分: 1746
  • 博客等级: 上尉
  • 技术积分: 340
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-29 15:57
文章分类

全部博文(40)

文章存档

2011年(23)

2010年(17)

我的朋友

分类: Oracle

2010-11-15 12:07:04

Oracle 10gR2或更高版本下使用RAC或ASM时,Oracle Clusterware会自动启动和停止Oracle数据库实例,因此下面的过程不是必要的,对于其他情况,你就可以使用下面描述的方法了。

◆su命令

下面的描述是Oracle建议采用的自动启动和关闭Oracle 9i实例的方法。

一旦实例创建好后,标记/etc/oratab文件设置每个实例的重启标志为“Y”:

TSH1:/u01/app/oracle/product/9.2.0:Y 


接下来,作为root用户登陆创建一个叫做/etc/init.d/dbora的文件,包括下面的内容:

#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the 
# Oracle database in ORA_HOME.

ORA_HOME=/u01/app/oracle/product/9.2.0
ORA_OWNER=oracle

if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi

case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login 
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
su - $ORA_OWNER -c $ORA_HOME/bin/dbstart
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login 
# will not prompt the user for any values
su - $ORA_OWNER -c $ORA_HOME/bin/dbshut
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop"
;;
esac

使用chmod命令设置权限为750:

chmod 750 /etc/init.d/dbora 


使用下面的命令配合适当的运行级别设置dbora服务自动启动:

chkconfig --level 345 dbora on 


这样有关的实例就会随系统的启动而启动了。

这个方法仍然适用于Oracle10g和11g,使用正确的路径对ORA_HOME变量做一下改动,并将其添加到dbstart和dbshut末尾的行,在Oracle10gR2下可以移除启动和停止监听器的行了,因此dbstart命令包括启动监听器。

#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the 
# Oracle database in ORA_HOME.

ORA_HOME=/u01/app/oracle/product/10.2.0/db_1
#ORA_HOME=/u01/app/oracle/product/11.1.0/db_1
ORA_OWNER=oracle

if [ ! -f $ORA_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi

case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login 
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login 
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
;;
esac

◆rsh命令

在Oracle10g中,Oracle推荐使用rsh命令而不是以前推荐的su命令了,在Oracle10gR2中,dbstart命令可以自动启动监听器,因此在这两个版本之间有些不同之处,下面的说明更适合Oracle10g。

一旦实例创建完毕,编辑/etc/oratab文件设置每个实例的重启标志为“Y”:

TSH1:/u01/app/oracle/product/9.2.0:Y 


接下来,作为root用户创建一个叫做/etc/init.d/dbora的文件,包括下面的内容:

#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Change the value of ORACLE_HOME to specify the correct Oracle home
# directory for your installation.

ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
#
# Change the value of ORACLE to the login name of the
# oracle owner at your site.
#
ORACLE=oracle

PATH=${PATH}:$ORACLE_HOME/bin
HOST=`hostname`
PLATFORM=`uname`
export ORACLE_HOME PATH
#
if [ ! "$2" = "ORA_DB" ] ; then
if [ "$PLATFORM" = "HP-UX" ] ; then
remsh $HOST -l $ORACLE -n "$0 $1 ORA_DB"
exit
else
rsh $HOST -l $ORACLE  $0 $1 ORA_DB
exit
fi
fi
#
case $1 in
'start')
$ORACLE_HOME/bin/dbstart $ORACLE_HOME
;;
'stop')
$ORACLE_HOME/bin/dbshut $ORACLE_HOME
;;
*)
echo "usage: $0 {start|stop}"
exit
;;
esac
#
exit

使用chmodml设置权限为750:

chmod 750 /etc/init.d/dbora 


使用下面的命令配合适当的运行级别设置dbora服务自动启动:

chkconfig --level 345 dbora on 


现在相关的实例应该随系统的启动而自动启动了。

这个方法依赖于RSH服务器,它需要额外的软件包和配置:

# Install the rhs and rsh-server packages from the OS CD/DVD.
rpm -Uvh --force rsh-*

# Enable rsh and rlogin.
chkconfig rsh on
chkconfig rlogin on
service xinetd reload
在FC5和FC6下尝试这个方法时有问题,rsh是不被支持的,结果,我宁愿使用su命令。

这个方法也可以用于没有使用ASM或RAC的11g数据库。

◆已知问题的解决

在Oracle10gR2中使用时,调用dbstart可能会产生下面的错误消息:

Failed to auto-start Oracle Net Listener using /ade/vikrkuma_new/oracle/bin/tnslsnr 


这是由于在dbstart脚本中使用了硬编码路径,要解决这个问题,编辑$ORACLE_HOME/bin/dbstart脚本,用

ORACLE_HOME_LISTNER=$ORACLE_HOME 


替换

ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle  //(大概在78行附近) 


现在dbstart在启动监听器时应该就没有问题了。

V.Z.注:在9i下也存在如下已知问题

  1. dbstart会去检测pfile文件,而oracle默认使用spfile启动,因此,必须在缺省路径下创建pfile文件。而且,即使创建了pfile文件,dbstart依旧会使用spfile文件启动数据库。
  2. dbshut使用的“shutdown”命令关闭数据库,为了避免等待,可以去修改dbshut中的内容,将“shutdown”改为“shutdown immediate”。

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

chinaunix网友2010-11-15 15:19:19

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com