【Oracle】将数据库设为开机自启

时间:2020-11-28 08:19:02

由于某些特殊条件,需要将oracle数据库设置为开机自己,其实很简单

环境:oracle10gR2

1.修改/etc/oratab



# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.


# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
test:/u01/app/oracle/product/10.2.0/dbhome_1:Y      --这里是由N改成的Y   
zhang:/u01/app/oracle/product/10.2.0/dbhome_1:Y   --这里的两行是代表的两个实例


修改好后保存。


2.在/etc/rc.local/下添加开机启动

oracle的ORACLE_HOME/bin下有一个命令,是dbstart,这个是oracle写好的自动开启启动脚本

只需要将其写入到/etc/rc.local/中即可


vi /etc/rc.local/


su - oracle -lc "/u01/app/oracle/product/10.2.0/dbhome_1/bin/lsnrctl start"    --开启监听
su - oracle -lc /u01/app/oracle/product/10.2.0/dbhome_1/bin/dbstart     --开启数据库

这里写的都是绝对路径,如果path变量配置的好的话,直接可以这么写

su - oracle -c 'lsnrctl start' 
su - oracle -c 'dbstart' 


保存退出,重启启动看下是否启动成功