Home Database Mysql Tutorial LINUX下ORACLE自动启动

LINUX下ORACLE自动启动

Jun 07, 2016 pm 03:24 PM
linux oracle py use start up automatic pass

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

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

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

Copy after login
[oracle@REDHAT6 ~]$ lsnrctl stop

SQL> shutdown immediate
Copy after login
LINUX下ORACLE自动启动

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

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

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

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()
Copy after login

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


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

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


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


最后,我们看看日志文件

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

LINUX下ORACLE自动启动


参考网址:

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

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

Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

What is the main purpose of Linux? What is the main purpose of Linux? Apr 16, 2025 am 12:19 AM

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

How to use VSCode How to use VSCode Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) is a cross-platform, open source and free code editor developed by Microsoft. It is known for its lightweight, scalability and support for a wide range of programming languages. To install VSCode, please visit the official website to download and run the installer. When using VSCode, you can create new projects, edit code, debug code, navigate projects, expand VSCode, and manage settings. VSCode is available for Windows, macOS, and Linux, supports multiple programming languages ​​and provides various extensions through Marketplace. Its advantages include lightweight, scalability, extensive language support, rich features and version

How to switch Chinese mode with vscode How to switch Chinese mode with vscode Apr 15, 2025 pm 11:39 PM

VS Code To switch Chinese mode: Open the settings interface (Windows/Linux: Ctrl, macOS: Cmd,) Search for "Editor: Language" settings Select "Chinese" in the drop-down menu Save settings and restart VS Code

MongoDB vs. Oracle: Understanding Key Differences MongoDB vs. Oracle: Understanding Key Differences Apr 16, 2025 am 12:01 AM

MongoDB is suitable for handling large-scale unstructured data, and Oracle is suitable for enterprise-level applications that require transaction consistency. 1.MongoDB provides flexibility and high performance, suitable for processing user behavior data. 2. Oracle is known for its stability and powerful functions and is suitable for financial systems. 3.MongoDB uses document models, and Oracle uses relational models. 4.MongoDB is suitable for social media applications, while Oracle is suitable for enterprise-level applications.

See all articles