指尖世界

分享的乐趣

oracle数据库自动启动关闭

类别: 观点 更新时间: 2016-03-10

[摘要:正在OS启动时,能够设置oracle战os一路启动或封闭。oracle自带dbstart战dbshut敕令。它们会读与oratab文件 [oracle@prod1 bin]$ cd $ORACLE_HOME/bin #检察启动战封闭剧本是]

在OS启动时,可以设置oracle和os一起启动或关闭。oracle自带dbstart和dbshut命令。它们会读取oratab文件

[oracle@prod1 bin]$ cd $ORACLE_HOME/bin
#查看启动和关闭脚本是否存在
[oracle@prod1 bin]$ ls dbstart 
dbstart
[oracle@prod1 bin]$ ls dbshut 
dbshut

修改dbstart、dbshut命令

[oracle@prod1 bin]$ vi dbstart 
ORACLE_HOME_LISTNER=$ORACLE_HOME
[oracle@prod1 bin]$ vi dbshut 
ORACLE_HOME_LISTNER=$ORACLE_HOME

修改oratab文件
PROD为ORACLE_SID
/u01/app/oracle/product/11.2.0/db_1为ORACLE_HOME
Y表示允许数据库自动启动或关闭

[oracle@prod1 bin]$ vi /etc/oratab 
PROD:/u01/app/oracle/product/11.2.0/db_1:Y

验证

[oracle@prod1 admin]$ dbstart
Processing Database instance "PROD": log file /u01/app/oracle/product/11.2.0/db_1/startup.log
[oracle@prod1 admin]$ more /u01/app/oracle/product/11.2.0/db_1/startup.log
SQL*Plus: Release 11.2.0.1.0 Production on Sun Feb 22 11:56:14 2015

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

idle> Connected to an idle instance.
idle> ORACLE instance started.

Total System Global Area  891383808 bytes
Fixed Size                  1340104 bytes
Variable Size             658509112 bytes
Database Buffers          226492416 bytes
Redo Buffers                5042176 bytes
Database mounted.
Database opened.
idle> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

/u01/app/oracle/product/11.2.0/db_1/bin/dbstart: Database instance "PROD" warm started.

创建脚本

#注意用户
[root@prod1 ~]# cd /etc/rc.d/init.d/
[root@prod1 init.d]# vi oracle
#!/bin/sh
#chkconfig: 35 80 10
#description: oracle auto start-stop script
export ORACLE_SID=PROD
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export ORACLE_HOME_LISTNER=$ORACLE_HOME
export PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/jdk/bin

case "$1" in 
'start') 
# Start the Oracle databases: 
echo "Starting Oracle Databases ... " 
echo "-------------------------------------------------" >> /var/log/oracle 
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle 
echo "-------------------------------------------------" >> /var/log/oracle 
su - oracle -c "$ORACLE_HOME/bin/dbstart" >>/var/log/oracle 
echo "Done" 
# Start the Listener: 
echo "Starting Oracle Listeners ... " 
echo "-------------------------------------------------" >> /var/log/oracle 
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle 
echo "-------------------------------------------------" >> /var/log/oracle 
su - oracle -c "$ORACLE_HOME/bin/lsnrctl start" >>/var/log/oracle 
echo "Done." 
echo "-------------------------------------------------" >> /var/log/oracle 
date +" %T %a %D : Finished." >> /var/log/oracle 
echo "-------------------------------------------------" >> /var/log/oracle 
touch /var/lock/subsys/oracle 
;;

'stop') 
# Stop the Oracle Listener: 
echo "Stoping Oracle Listeners ... " 
echo "-------------------------------------------------" >> /var/log/oracle 
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle 
echo "-------------------------------------------------" >> /var/log/oracle 
su - oracle -c "$ORACLE_HOME/bin/lsnrctl stop" >>/var/log/oracle 
echo "Done." 
rm -f /var/lock/subsys/oracle 
# Stop the Oracle Database: 
echo "Stoping Oracle Databases ... " 
echo "-------------------------------------------------" >> /var/log/oracle 
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle 
echo "-------------------------------------------------" >> /var/log/oracle 
su - oracle -c "$ORACLE_HOME/bin/dbshut" >>/var/log/oracle 
echo "Done." 
echo "" 
echo "-------------------------------------------------" >> /var/log/oracle 
date +" %T %a %D : Finished." >> /var/log/oracle 
echo "-------------------------------------------------" >> /var/log/oracle 
;;

'restart') 
$0 stop 
$0 start 

esac 

修改文件权限

[root@prod1 init.d]# chmod 755 oracle

添加服务

[root@prod1 init.d]# chkconfig --level 35 oracle on

关机或重启自动关闭


[root@prod1 rc0.d]# ln -s /etc/rc.d/init.d/oracle /etc/rc0.d/K01oracle
[root@prod1 rc0.d]# ln -s /etc/rc.d/init.d/oracle /etc/rc6.d/K01oracle

使用

service oracle start service oracle stop service oracle restart


感谢关注 V8指尖世界Oracle频道,v8en.com是专门为互联网人打造的学习交流平台,全面满足互联网人工作与学习需求,更多互联网资讯尽在 V8指尖世界!