配置Oracle單例項隨機啟動(11gR2)

dbasdk發表於2014-08-26
系統資訊:
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




來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29734436/viewspace-1257948/,如需轉載,請註明出處,否則將追究法律責任。

相關文章