脚本自启动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?oracle?and?asm?instance?on?10g?R2?64bit ?#author:lw.yang ?#version:?V.2.0 ??#?Source?function?library. ?.?/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?"export?ORACLE_SID=+ASM?&&?sqlplus?/nolog<
三:/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?"export?ORACLE_SID=$D_SID?&&?sqlplus?/nolog<
四:測試非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 NLSNLS_LANG=american_america.UTF8NLS_DATE_FORMAT=YYYY-MM-DD HH24:MI:SS
SQL> select sysdate from dual;
SYSDATE-------------------2011-06-02 10:04:49
設置默認編輯器為vim,若不設置該變量,在sqlplus中將無法使用ed命令
SQL> edWrote file afiedt.buf27
[oracle@ora10g ~]$ env |grep EDITOREDITOR=vim
小編推薦:欲學習電腦技術、系統維護、網絡管理、編程開發和安全攻防等高端IT技術,請 點擊這里注冊賬號,公開課頻道價值萬元IT培訓教程免費學,讓您少走彎路、事半功倍,好工作升職加薪!
免責聲明:本站系公益性非盈利IT技術普及網,本文由投稿者轉載自互聯網的公開文章,文末均已注明出處,其內容和圖片版權歸原網站或作者所有,文中所述不代表本站觀點,若有無意侵權或轉載不當之處請從網站右下角聯系我們處理,謝謝合作!
總結
以上是生活随笔為你收集整理的脚本自启动oracle,自动启动和关闭Oracle 脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 水面反光如何拍摄_拍摄水面反射的创意
- 下一篇: 宝塔php安装那个合_使用宝塔面板安装n