search
HomeDatabaseMysql TutorialLINUX下ORACLE自动启动

LINUX下ORACLE自动启动

Jun 07, 2016 pm 03:24 PM
linuxoraclepyusestart upautomaticpass

本文通过使用python脚本来启动oracle数据库,实现oracle数据库的开机启动(主要启动监听和数据库,不包含dbconsole): STEP1:关闭数据库,关闭监听 /prepre name=code class=sql[oracle@REDHAT6 ~]$ lsnrctl stopSQL shutdown immediate STEP2:查看是否有

本文通过使用python脚本来启动oracle数据库,实现oracle数据库的开机启动(主要启动监听和数据库,不包含dbconsole):

STEP1:关闭数据库,关闭监听


[oracle@REDHAT6 ~]$ lsnrctl stop

SQL> shutdown immediate
LINUX下ORACLE自动启动

STEP2:查看是否有python相关的包是否已经安装(若没有安装,就需要安装相关的包)

[root@REDHAT6 ~]# which python
/usr/bin/python

STEP3:编写启动相关服务的 python 脚本
-- 先新建两个文件,一个是python脚本,一个是记录日志
[oracle@REDHAT6 ~]$ touch oracle.py
[oracle@REDHAT6 ~]$ touch oracle.log
[oracle@REDHAT6 ~]$ chmod -R 755 oracle.py

python脚本
import commands;
import sys;
import time;

dtime=time.strftime('%Y-%m-%d %H:%I:%M:%S',time.localtime(time.time()));

file_append=open('/home/oracle/oracle.log','a+')

print>>file_append,dtime,'\n'
print>>file_append,'============START LISTENER================\n'
(status,output)=commands.getstatusoutput("su - oracle -c '/u01/app/oracle/bin/lsnrctl start' ")
print>>file_append,output+'\n'
if(status==0):
	print>>file_append,'============OK: LISTENER START OK=============\n'
else:
	print>>file_append,'============ERROR: LISTENER START ERROR=============\n'

print>>file_append,'============START DATABASE================\n'
(status,output)=commands.getstatusoutput("su - oracle -c '/u01/app/oracle/bin/dbstart' ")
print>>file_append,output,'\n'

if(status==0):
	print>>file_append,'============OK: DATABASE START OK=============\n'
else:
	print>>file_append,'============ERROR: DATABASE START ERROR=======\n'


print>>file_append,'\n','\n'
file_append.close()

脚本先启动lsnrctl, 再启动 dbstart,  在dbstart启动时,会自动启动lsnrctl,由于本人在环境变量中没有配置,所以在启动dbstart时,监听无法启动,所以就在python中先启动了监听


STEP4:将脚本执行命令添加到开机启动中

[oracle@REDHAT6 ~]$ vi /etc/rc.d/rc.local
在该文件中增加一行:su - root -c "python /home/oracle/oracle.py"    有的人说是将 su - root 要改成 oracle用户,这里没有必要改,因为我在python脚本中已经指定了oracle用户
LINUX下ORACLE自动启动


下次启动机器,就会发现监听程序和数据库程序已经启动


最后,我们看看日志文件

[oracle@REDHAT6 ~]$ tail -200 /home/oracle/oracle.log
LINUX下ORACLE自动启动
下面是启动数据库的日志,里面会报监听错误,但是监听我们先已经启动了,所以可以不必理会。也可以通过配置环境变量来启动

LINUX下ORACLE自动启动


参考网址:

http://blog.csdn.net/my2010sam/article/details/18315785

http://biancheng.dnbcw.info/python/242105.html

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How Do I Drop or Modify an Existing View in MySQL?How Do I Drop or Modify an Existing View in MySQL?May 16, 2025 am 12:11 AM

TodropaviewinMySQL,use"DROPVIEWIFEXISTSview_name;"andtomodifyaview,use"CREATEORREPLACEVIEWview_nameASSELECT...".Whendroppingaview,considerdependenciesanduse"SHOWCREATEVIEWview_name;"tounderstanditsstructure.Whenmodifying

MySQL Views: Which design patterns can I use with it?MySQL Views: Which design patterns can I use with it?May 16, 2025 am 12:10 AM

MySQLViewscaneffectivelyutilizedesignpatternslikeAdapter,Decorator,Factory,andObserver.1)AdapterPatternadaptsdatafromdifferenttablesintoaunifiedview.2)DecoratorPatternenhancesdatawithcalculatedfields.3)FactoryPatterncreatesviewsthatproducedifferentda

What Are the Advantages of Using Views in MySQL?What Are the Advantages of Using Views in MySQL?May 16, 2025 am 12:09 AM

ViewsinMySQLarebeneficialforsimplifyingcomplexqueries,enhancingsecurity,ensuringdataconsistency,andoptimizingperformance.1)Theysimplifycomplexqueriesbyencapsulatingthemintoreusableviews.2)Viewsenhancesecuritybycontrollingdataaccess.3)Theyensuredataco

How Can I Create a Simple View in MySQL?How Can I Create a Simple View in MySQL?May 16, 2025 am 12:08 AM

TocreateasimpleviewinMySQL,usetheCREATEVIEWstatement.1)DefinetheviewwithCREATEVIEWview_nameAS.2)SpecifytheSELECTstatementtoretrievedesireddata.3)Usetheviewlikeatableforqueries.Viewssimplifydataaccessandenhancesecurity,butconsiderperformance,updatabil

MySQL Create User Statement: Examples and Common ErrorsMySQL Create User Statement: Examples and Common ErrorsMay 16, 2025 am 12:04 AM

TocreateusersinMySQL,usetheCREATEUSERstatement.1)Foralocaluser:CREATEUSER'localuser'@'localhost'IDENTIFIEDBY'securepassword';2)Foraremoteuser:CREATEUSER'remoteuser'@'%'IDENTIFIEDBY'strongpassword';3)Forauserwithaspecifichost:CREATEUSER'specificuser'@

What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment