编写Oracle自动启动脚本的方法
Oracle 自动启动脚本的编写
在Linux RedHat AS 3.0 Update5上安装完Oracle 9i后,发现当主机重新启动后,Oralce不能自动重新启动,而且监听程序和Oracle Web Server都不能自动启动,按照下面的方法进行了设置,能够达到自动启动Oracle数据库以及监听程序和Web Server的效果。
1. 在文件/etc/oratab中添加# 添加如下内容到/etc/oratab文件中,
# $ORACLE_SID是你的Oracle数据库的sid # $ORACLE_HOME是你的Oracle数据库的Oracle_home # Y表示要求在系统启动的时候启动Oracle数据库.N表示不要在系统启动的时候启动Oracle $ORACLE_SID:$ORACLE_HOME:Y
2. 修改文件/etc/rc.local添加一下两行
## 关于su的具体命令参看linux的manual文档 ## dbstart: 启动Oracle数据库 ## lsnrctl: 启动Oracle数据库监听程序 ## $ORACLE_HOME/Apache/Apache/bin/startJServ.sh: 启动Oracle Web Server 7777端口 su - oracle -c 'dbstart' su - oracle -c 'lsnrctl start' su - oracle -c '$ORACLE_HOME/Apache/Apache/bin/startJServ.sh'
3. 在本机使用dbstart,和dbshut测试设置是否准确.
[oracle@tzcenter oracle]$ dbshut SQL*Plus: Release 9.2.0.4.0 - Production on Thu Nov 11 21:02:35 2004 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. SQL> Connected. SQL> Database closed. Database dismounted. ORACLE instance shut down. SQL> Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 Production With the Partitioning, OLAP and Oracle Data Mining options JServer Release 9.2.0.4.0 - Production Database "webora9" shut down. [oracle@tzcenter oracle]$ dbstart SQL*Plus: Release 9.2.0.4.0 - Production on Thu Nov 11 21:02:43 2004 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. SQL> Connected to an idle instance. SQL> ORACLE instance started. Total System Global Area 437327188 bytes Fixed Size 451924 bytes Variable Size 134217728 bytes Database Buffers 301989888 bytes Redo Buffers 667648 bytes Database mounted. Database opened. SQL> Disconnected from Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production With the Partitioning, OLAP and Oracle Data Mining options JServer Release 9.2.0.4.0 - Production Database "webora9" warm started. [oracle@tzcenter oracle]$
注意:dbstart 脚本里面用的是 pfile 来启动数据库的,所以需要连接到数据库产生pfile文件,才能直接使用dbstart命令启动并连接数据库,具体方法:
[oracle@tzcenter oracle]$ sqlplus '/ as sysdba' SQL*Plus: Release 9.2.0.4.0 - Production on Thu Nov 11 21:02:43 2004 Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved. SQL>connect internal/oracle SQL>create pfile from spfile [oracle@tzcenter oracle]$