系统信息:
beiora01:/home/oracle> uname -a
Linux beiora01a.bskyb.com 2.6.18-348.6.1.el5 #1 SMP Tue May 21 15:29:55 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux
数据库信息:
SQL> select * from v$version;
BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production PL/SQL Release 11.2.0.3.0 - Production CORE 11.2.0.3.0 Production TNS for Linux: Version 11.2.0.3.0 - Production NLSRTL Version 11.2.0.3.0 - Production
1. 使用root用户编辑如下文件
vi /etc/init.d/dbora
#!/bin/sh # chkconfig: 345 99 10 # description: Oracle auto start-stop script. # # Set ORA_OWNER to the user id of the owner of the # Oracle database software. ORA_OWNER=oracle case "$1" in 'start') # Start the Oracle databases: # The following command assumes that the oracle login # will not prompt the user for any values # Remove "&" if you don't want startup as a background process. su $ORA_OWNER -c "/home/oracle/scripts/startup.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1" & touch /var/lock/subsys/dbora ;; '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 "/home/oracle/scripts/shutdown.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1" rm -f /var/lock/subsys/dbora ;; esac
修改权限
chmod 750 /etc/init.d/dbora chkconfig --add dbora
2. 创建自动启动和关闭数据库的脚本
# mkdir -p /home/oracle/scripts # chown oracle.oinstall /home/oracle/scripts
vi /home/oracle/scripts/startup.sh
注意修改红体自变量
#!/bin/bash
export TMP=/tmp
export TMPDIR=$TMP
export PATH=/usr/sbin:/usr/local/bin:$PATH export ORACLE_HOSTNAME=localhost.localdomain
export ORACLE_UNQNAME=phyprimary
export ORACLE_SID=phyprimary ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES
# Start Listener
lsnrctl start
# Start Database
sqlplus / as sysdba << EOF
STARTUP;
EXIT;
EOF
vi /home/oracle/scripts/shutdown.sh
注意修改红体字变量
#!/bin/bash
export TMP=/tmp
export TMPDIR=$TMP
export PATH=/usr/sbin:/usr/local/bin:$PATH export ORACLE_HOSTNAME=localhost.localdomain
export ORACLE_UNQNAME=phyprimary
export ORACLE_SID=phyprimary ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES
# Stop Database
sqlplus / as sysdba << EOF
SHUTDOWN IMMEDIATE;
EXIT;
EOF
# Stop Listener
lsnrctl stop
3. 确认脚本权限
[root@localhost ~]# chmod u+x /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh
[root@localhost ~]# chown oracle.oinstall /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh
4. 测试实验结果
# service dbora start # service dbora stop |