oracle禁止自动启动命令,自动启动和关闭Oracle 脚本
配置完ASM實例后,每次啟動oracle數據庫服務器的時候要先啟動ASM實例,然后啟動數據庫實例;關閉的時候,需要先關閉oracle數據庫實例,然后關閉ASM實例;敲起命來來麻煩的很,因而改進了原來的shell腳本來更好的實現自動化,為了加快啟動和關閉的速度,該腳本不包含dbconsole的啟動和關閉,腳本同樣適用于非ASM環境。
一:總腳本調用/usr/bin/startdb和/usr/bin/stopdb腳本,使用chkconfig命令創建相關的符號鏈接后就可以使用service命令調用
[root@ora10g?~]#?cat?/etc/init.d/oracle
#!/bin/sh
#chkconfig:?35?85?15
#description:oracle
#function:?start?..?stop?the?oracleandasm?instanceon10g?R2?64bit
#author:lw.yang
#version:?V.2.0
#?Sourcefunctionlibrary.
.?/etc/rc.d/init.d/functions
case"$1"in
start)
/usr/bin/startdb
;;
stop)
/usr/bin/stopdb
;;
*)
echo?$"Usage:?$0?{start|stop}"
exit?1
esac
二:/usr/bin/startdb腳本用來啟動ASM實例和ORACLE數據庫實例和監聽器,啟動前會進行判斷是否配置了ASM以及實例是否已經啟動,ASM實例需要ocssd.bin后臺進程啟動才可以運行
[root@ora10g?~]#?cat?/usr/bin/startdb
#!/bin/sh
#define?variables
ASM_PID=$(pidof?ocssd.bin)
ASM_PROC=$(ps?-ef?|grep?asm_?|grep?-v?'grep'?|wc?-l)
D_SID=$(su?-?oracle?-c?"env?|grep?ORACLE_SID|cut?-d?"="?-f?2")
DB_PROC=$(ps?-ef?|grep?ora_?|grep?-E?'smon|pmon|ckpt|lgwr'?|wc?-l)
#startup?asm?instance
if?[?-z?$ASM_PID?];then
echo?"Not?configure?use?ASM"
continue
elif?[?$ASM_PROC?-gt?"7"?];then
echo?"ASM?instance?already?running"
else
su?-?oracle??-c?"exportORACLE_SID=+ASM?&&?sqlplus?/nolog<
conn?/as?sysdba
startup
exit
EOF"
fi
#startup?database?instance
if?[?$DB_PROC?-eq?"4"?];then
echo?"Database?instance?already?running,shutdown?it?firtst"
else
su?-?oracle?-c?"lsnrctl?start"
su?-?oracle?-c?"exportORACLE_SID=$D_SID?&&?sqlplus?/nolog<
conn?/as?sysdba
startup
exit
EOF"
touch?/var/lock/subsys/oracle
fi
三:/usr/bin/stopdb腳本用來關閉監聽器,oracle數據庫實例和ASM實例,關閉之前會先進行判斷是否使用ASM以及相關實例是否已經關閉
#!/bin/sh
#define?variables
ASM_PID=$(pidof?ocssd.bin)
ASM_PROC=$(ps?-ef?|grep?asm_?|grep?-v?'grep'?|wc?-l)
D_SID=$(su?-?oracle?-c?"env?|grep?ORACLE_SID|cut?-d?"="?-f?2")
DB_PROC=$(ps?-ef?|grep?ora_?|grep?-E?'smon|pmon|ckpt|lgwr'?|wc?-l)
#stop?database?instance
if?[?$DB_PROC?-eq?"0"?];then
echo?"Database?instance?already?shutdown"
else
su?-?oracle?-c?"lsnrctl?stop"
su?-?oracle?-c?"exportORACLE_SID=$D_SID?&&?sqlplus?/nolog<
conn?/as?sysdba
shutdown?immediate
exit
EOF"
rm?-f?/var/lock/subsys/oracle
fi
#stop?asm?instance
if?[?-z?$ASM_PID?];then
echo?"Not?configure?use?ASM"
elif?[?$ASM_PROC?-eq?"0"?];then
echo?"ASM?instance?already?shutdown"
exit
else
su?-?oracle??-c?"exportORACLE_SID=+ASM?&&?sqlplus?/nolog<
conn?/as?sysdba
shutdown?immediate
exit
EOF"
fi
四:測試
非ASM環境下,數據庫實例已經啟動下測試:
[root@ora10g?~]#?service?oracle?start
Not?configure?use?ASM
Database?instance?already?running,shutdown?it?firtst
[root@ora10g?~]#?service?oracle?stop
LSNRCTL?for?Linux:?Version?10.2.0.1.0?-?Production?on?02-JUN-2011?09:48:36
Copyright?(c)?1991,?2005,?Oracle.??All?rights?reserved.
Connecting?to?(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=1521)))
The?command?completed?successfully
SQL*Plus:?Release?10.2.0.1.0?-?Production?on?Thu?Jun?2?09:48:40?2011
Copyright?(c)?1982,?2005,?Oracle.??All?rights?reserved.
SQL>Connected.
SQL>Database?closed.
Database?dismounted.
ORACLE?instance?shut?down.
SQL>Disconnected?from?Oracle?Database?10g?Enterprise?Edition?Release?10.2.0.1.0?-?64bit?Production
With?the?Partitioning,?OLAP?and?Data?Mining?options
Not?configure?use?ASM
非ASM環境下,數據庫實例已經關閉下測試:
[root@ora10g?~]#?service?oracle?stop
Database?instance?already?shutdown
Not?configure?use?ASM
[root@ora10g?~]#?service?oracle?start
Not?configure?use?ASM
LSNRCTL?for?Linux:?Version?10.2.0.1.0?-?Production?on?02-JUN-2011?09:50:25
Copyright?(c)?1991,?2005,?Oracle.??All?rights?reserved.
Starting?/u01/app/oracle/bin/tnslsnr:?please?wait...
TNSLSNR?for?Linux:?Version?10.2.0.1.0?-?Production
System?parameter?file?is?/u01/app/oracle/network/admin/listener.ora
Log?messages?written?to?/u01/app/oracle/network/log/listener.log
Listening?on:?(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora10g.766.com)(PORT=1521)))
Listening?on:?(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Connecting?to?(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost.localdomain)(PORT=1521)))
STATUS?of?the?LISTENER
------------------------
Alias?????????????????????LISTENER
Version???????????????????TNSLSNR?for?Linux:?Version?10.2.0.1.0?-?Production
Start?Date????????????????02-JUN-2011?09:50:25
Uptime????????????????????0?days?0?hr.?0?min.?0?sec
Trace?Level???????????????off
Security??????????????????ON:?Local?OS?Authentication
SNMP??????????????????????OFF
Listener?Parameter?File???/u01/app/oracle/network/admin/listener.ora
Listener?Log?File?????????/u01/app/oracle/network/log/listener.log
Listening?Endpoints?Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ora10g.766.com)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
Services?Summary...
Service?"PLSExtProc"?has?1?instance(s).
Instance?"PLSExtProc",?status?UNKNOWN,?has?1?handler(s)?for?this?service...
The?command?completed?successfully
SQL*Plus:?Release?10.2.0.1.0?-?Production?on?Thu?Jun?2?09:50:25?2011
Copyright?(c)?1982,?2005,?Oracle.??All?rights?reserved.
SQL>Connected?to?an?idle?instance.
SQL>ORACLE?instance?started.
Total?System?Global?Area??629145600?bytes
Fixed?Size??????????????????2022824?bytes
Variable?Size?????????????230687320?bytes
Database?Buffers??????????390070272?bytes
Redo?Buffers????????????????6365184?bytes
Database?mounted.
Database?opened.
SQL>Disconnected?from?Oracle?Database?10g?Enterprise?Edition?Release?10.2.0.1.0?-?64bit?Production
With?the?Partitioning,?OLAP?and?Data?Mining?options
五:設置操作系統環境變量
設置NLS_DATE_FORMAT和NLS_LANG環境變量,這兩個變量需要同時設定,否則執行select sysdate from dual的時候,輸出格式DD-MON-YY
SQL> select sysdate from dual;
SYSDATE
---------
02-JUN-11
[oracle@ora10g ~]$ env |grep NLS
NLS_LANG=american_america.UTF8
NLS_DATE_FORMAT=YYYY-MM-DD HH24:MI:SS
SQL> select sysdate from dual;
SYSDATE
-------------------
2011-06-02 10:04:49
設置默認編輯器為vim,若不設置該變量,在sqlplus中將無法使用ed命令
SQL> ed
Wrote file afiedt.buf
27
[oracle@ora10g ~]$ env |grep EDITOR
EDITOR=vim
總結
以上是生活随笔為你收集整理的oracle禁止自动启动命令,自动启动和关闭Oracle 脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 部队休假一批可以休多少人
 - 下一篇: 当兵政审可以就业吗