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)

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

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.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

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 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

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

How to run sublime after writing the code How to run sublime after writing the code Apr 16, 2025 am 08:51 AM

There are six ways to run code in Sublime: through hotkeys, menus, build systems, command lines, set default build systems, and custom build commands, and run individual files/projects by right-clicking on projects/files. The build system availability depends on the installation of Sublime Text.

See all articles