oracle自动启动脚本
/etc/oratab介绍
系统版本:CentOS release 6.8 (Final)
数据库版本:Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
核心文件:/etc/oratab
注:如果相应目录下没有该文件,可以使用find命令进行查找复制
关于该文件的说明:
文件内容格式:
$ORACLE_SID:$ORACLE_HOME:[Y/N]
第一和第二字段分别是数据库的系统标识符和主目录。 第三个字段指示dbstart实用程序,数据库应该“Y”或不应该“N”在系统引导时启动。
根据文件格式可以为不同的数据库设置不同的选项
文件内容如下:(root执行)
[root@server1 etc]# ls oratab
oratab
[root@server1 etc]# pwd
/etc
[root@server1 etc]# vim oratab
# This file is used by ORACLE utilities. It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.
# 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.
#
#
proe:/u01/app/oracle/product/11.2.0/db_home1:Y -->如果想使用Oracle自启动这个选项修改为Y
创建Oracle服务启动脚本
[root@server1 etc]# cd /etc/init.d/
[root@server1 init.d]# vim oracle
#!/bin/sh
# chkconfig: 345 61 61
# description: Oracle 11g R2 AutoRun Servimces
# /etc/init.d/oracle
# Run-level Startup script for the Oracle Instance, Listener and Web Interface
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_home1/
export ORACLE_SID=proe
export PATH=$PATH:$ORACLE_HOME/bin
ORA_OWNR="oracle"
# if the executables do not exist -- display error
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display
case "$1" in
start)
# Oracle listener and instance startup
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbstart
echo "Oracle Start Succesful!OK."
;;
stop)
# Oracle listener and instance shutdown
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbshut
echo "Oracle Stop Succesful!OK."
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo $"Usage: `basename $0` {start|stop|reload|reload}"
exit 1
esac
exit 0
执行启动脚本
[root@server1 ~]# cd /etc/init.d/
[root@server1 init.d]# chmod +x oracle
[root@server1 init.d]# ll oracle
-rwxr-xr-x 1 root root 1030 Dec 15 22:59 oracle
[root@server1 init.d]# ./oracle start
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/app/oracle/product/11.2.0/db_home1//bin/dbstart ORACLE_HOME
Processing Database instance "proe": log file /u01/app/oracle/product/11.2.0/db_home1/startup.log
Oracle Start Succesful!OK.
[root@server1 ~]# su - oracle
[oracle@server1 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Tue Dec 15 23:18:05 2020
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SYS@proe>select instance_name,status from v$instance;
INSTANCE_NAME STATUS
---------------- ------------
proe OPEN
监听报错处理
上述脚本执行数据库正常启动,但是存在监听问题,报错信息为Oracle监听未配置,监听未启动。
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
配置监听自启动服务
[root@server1 init.d]# cd /u01/app/oracle/product/11.2.0/db_home1/bin/
[root@server1 bin]# pwd
/u01/app/oracle/product/11.2.0/db_home1/bin
--修改dbstart文件
[root@server1 bin]# vim dbstart
ORACLE_HOME_LISTNER=$1 这个文件把$1替换为$ORACLE_HOME(写完全路径)
...
# First argument is used to bring up Oracle Net Listener
ORACLE_HOME_LISTNER=/u01/app/oracle/product/11.2.0/db_home1
...
--修改dbshut文件
[root@server1 bin]# vim dbshut
ORACLE_HOME_LISTNER=$1 这个文件把$1替换为$ORACLE_HOME(写完全路径)
...
# The this to bring down Oracle Net Listener
ORACLE_HOME_LISTNER=/u01/app/oracle/product/11.2.0/db_home1
...
最终测试
[root@server1 init.d]# /etc/init.d/oracle stop
Processing Database instance "proe": log file /u01/app/oracle/product/11.2.0/db_home1/shutdown.log
Oracle Stop Succesful!OK.
[root@server1 init.d]# ps -ef | grep ora_
root 4741 3472 0 23:37 pts/4 00:00:00 grep ora_
[root@server1 init.d]# ./oracle start
Processing Database instance "proe": log file /u01/app/oracle/product/11.2.0/db_home1/startup.log
Oracle Start Succesful!OK.
[root@server1 init.d]# ps -ef | grep ora_
oracle 4861 1 0 23:37 ? 00:00:00 ora_pmon_proe
oracle 4863 1 0 23:37 ? 00:00:00 ora_psp0_proe
oracle 4865 1 0 23:37 ? 00:00:00 ora_vktm_proe
...
附:
需进入脚本目录执行脚本
./oracle start 启动数据库
./oracle stop 关闭数据库
./oracle reload/restart 数据库重启
使用自动关闭相当于进库手动执行shutdown immediate
--关闭过程警告日志如下
Wed Dec 16 11:40:30 2020
Shutting down instance (immediate)
Shutting down instance: further logons disabled
Wed Dec 16 11:40:30 2020
Stopping background process QMNC
Stopping background process CJQ0
Stopping background process MMNL
Stopping background process MMON
License high water mark = 9
All dispatchers and shared servers shutdown
ALTER DATABASE CLOSE NORMAL
Wed Dec 16 11:40:36 2020
....