Oracle automatic start and stop in Linux (2)

Source: Internet
Author: User
  1. Overview
    Enabling the database to automatically start when the operating system starts makes database maintenance easier and more convenient.
    I have written an article "Oracle Auto Start and Stop in Linux (I)" http://blog.csdn.net/chenxiao#/archive/2008/02/26/2121878.aspx. The methods in this article require/etc/oratab, $ ORACLE_HOME/bin/dbstart, and $ ORACLE_HOME/bin/dbshut, which are not flexible enough. The following describes how to automatically start multiple Oracle instances and listeners.
    The article "Create and start an Oracle database" describes how to create multiple databases and instances and start these instances. Now we will explain how to automatically start these databases when the system starts.
  2. Write scripts
    Use the root user to enter the/etc/rc. d/init. d directory and create the oracle_linuxdb file. The script is used to start the linuxdb instance. The content is as follows:
    #! /Bin/sh <br/> # chkconfig: 2345 80 <br/> # Description: oracle_linuxdb <br/> #/etc/rc. d/init. d/oracle_linuxdb <br/> # auto start database linuxdb instance </P> <p> # Set Oracle env <br/> export oracle_base =/home/ora/ora9 <br/> export ORACLE_HOME = $ oracle_base/Oracle <br/> export Path = $ path: $ ORACLE_HOME/bin <br/> oracle_user = ora </P> <p> # start or stop script <br/> case $1 in <br/> start) <br/> Su-"$ oracle_user" <EOO <br/> export oracle_sid = linuxdb <br/> LSNRCTL start listener_linuxdb <br/> sqlplus/nolog <EOS <br /> connect/As sysdba <br/> startup <br/> EOS <br/> EOO <br/> ;; </P> <p> stop) <br/> Su-"$ oracle_user" <EOO <br/> export oracle_sid = linuxdb <br/> LSNRCTL stop listener_linuxdb <br/> sqlplus/nolog <EOS <br /> connect/As sysdba <br/> shutdown immediate <br/> EOS <br/> EOO <br/> ;; </P> <p> *) <br/> echo "Usage: $0 {START | stop}" <br/>; <br/> esac
    The code above is a shell script. First, set Oracle-related environment variables. Note that oracle_sid specifies the name of the started instance.
    Then grant oracle_linuxdb the execution permission and execute the command: chmod + x oracle_linuxdb
    Run the script for testing.
    Start, Run the command:./oracle_linuxdb start
    Close and execute the command:./oracle_linuxdb stop
    You can use sqlplus user/pass @ tnsname to test whether the database is successfully started or shut down.

    Create the oracle_wldev file to start the database instance wldev. The content is as follows:
    #! /Bin/sh <br/> # chkconfig: 2345 80 <br/> # Description: oracle_wldev <br/> #/etc/rc. d/init. d/oracle_wldev <br/> # auto start database wldev instance </P> <p> # Set Oracle env <br/> export oracle_base =/home/ora/ora9 <br/> export ORACLE_HOME = $ oracle_base/Oracle <br/> export Path = $ path: $ ORACLE_HOME/bin <br/> oracle_user = ora </P> <p> # start or stop script <br/> case $1 in <br/> start) <br/> Su-"$ oracle_user" <EOO <br/> export oracle_sid = wldev <br/> LSNRCTL start listener_wldev <br/> sqlplus/nolog <EOS <br /> connect/As sysdba <br/> startup <br/> EOS <br/> EOO <br/> ;; </P> <p> stop) <br/> Su-"$ oracle_user" <EOO <br/> export oracle_sid = wldev <br/> LSNRCTL stop listener_wldev <br/> sqlplus/nolog <EOS <br /> connect/As sysdba <br/> shutdown immediate <br/> EOS <br/> EOO <br/> ;; </P> <p> *) <br/> echo "Usage: $0 {START | stop}" <br/>; <br/> esac
    Then grant oracle_wldev the execution permission and run the command: chmod + x oracle_wldev.
    Run the script for testing.
    Start, Run the command:./oracle_wldev start
    Close and execute the command:./oracle_wldev stop
    You can use sqlplus user/pass @ tnsname to test whether the database is successfully started or shut down.

    Now you have the script to start and close oracle. You only need to set these scripts so that the system can automatically execute them when it starts and closes.

  3. Release
    Run the following command:
    Chkconfig -- add oracle_linuxdb
    Chkconfig -- add oracle_wldev
    After the chkconfig command is run successfully, Two Connection Files, s80oracle_linuxdb and s80oracle_wldev, are created under rc2.d, rc3.d, rc4.d, and rc5.d. You can run a script to start the database when the system starts. The k80oracle_linuxdb and k80oracle_wldev files are created under the rc0.d, rc1.d, and rc6.d directories. They are used to automatically run scripts to close the database when the system is disabled.

    You can use man chkconfig to view the usage of chkconfig.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.