Oracle automatic start and stop in Linux (1)

Source: Internet
Author: User
  1. Modify the Oracle system configuration file/etc/oratab
    /Etc/oratab format: Sid: ORACLE_HOME: Auto
    Set the auto domain to Y (uppercase). Only in this way can dbstart and dbshut of Oracle be used. Mine is:
    $ Oracle_sid: $ ORACLE_HOME: Y
    Here, oracle_sid and ORACLE_HOME are environment variables of oracle users, which have different values on different computers. When you open/etc/oratab, you just need to modify it.
  2. Write service scripts
    Create an oracle file in the/etc/rc. d/init. d directory as the startup script. The content is as follows:
    #! /Bin/sh
    #
    #/Etc/rc. d/init. d/Oracle
    # Explanation: Start and Stop Oracle databases and listeners
    # Check how script files are executed
    Case "$1" in
    Start)
    Echo-n "Starting Oracle databases :"
    Echo "----------------------------------------------------">/var/log/Oracle
    Date + "! % T % A % d: Starting Oracle databases as part of system up. ">/var/log/Oracle
    Echo "----------------------------------------------------">/var/log/Oracle
    Su-Ora-C dbstart>/var/log/Oracle
    Echo "done ."
    Echo-n "Starting Oracle listeners :"
    Su-Ora-c "LSNRCTL start">/var/log/Oracle
    # Su-Oracle "sqlplus/nolog" <
    # Connect/As sysdba
    # Startup
    # Exit
    Echo "done ."
    Echo ""
    Echo "----------------------------------------------------">/var/log/Oracle
    Date + "! % T % A % d: Finished. ">/var/log/Oracle
    Echo "----------------------------------------------------">/var/log/Oracle
    Touch/var/lock/subsys/Oracle
    ;;
    Stop)
    Echo-n "shutting down Oracle listeners :"
    Echo "----------------------------------------------------">/var/log/Oracle
    Date + "! % T % A % d: Shutting Down Oracle databases as part of system down. ">/var/log/Oracle
    Echo "----------------------------------------------------">/var/log/Oracle
    Su-Ora-c "LSNRCTL stop">/var/log/Oracle
    Echo "done ."
    Rm-F/var/lock/subsys/Oracle
    Echo-n "shutting down Oracle databases :"
    Su-Ora-C dbshut>/var/log/Oracle
    Echo "done ."
    Echo ""
    Echo "----------------------------------------------------">/var/log/Oracle
    Date + "! % T % A % d: Finished. ">/var/log/Oracle
    Echo "----------------------------------------------------">/var/log/Oracle
    ;;
    Restart)
    Echo-n "Restarting Oracle databases :"
    Echo "----------------------------------------------------">/var/log/Oracle
    Date + "! % T % A % d: restarting Oracle databases as part of system up. ">/var/log/Oracle
    Echo "----------------------------------------------------">/var/log/Oracle
    Su-Ora-C dbstop>/var/log/Oracle
    Su-Ora-C dbstart>/var/log/Oracle
    Echo "done ."
    Echo-n "Restarting Oracle listeners :"
    Su-Ora-c "LSNRCTL stop">/var/log/Oracle
    Su-Ora-c "LSNRCTL start">/var/log/Oracle
    Echo "done ."
    Echo ""
    Echo "----------------------------------------------------">/var/log/Oracle
    Date + "! % T % A % d: Finished. ">/var/log/Oracle
    Echo "----------------------------------------------------">/var/log/Oracle
    Touch/var/lock/subsys/Oracle
    ;;
    *)
    Echo "Usage: Oracle {START | stop | restart }"
    Exit 1
    Esac
    Input the preceding content under the Oracle user, and save and exit. Because it is a STARTUP script, the execution permission is required. Execute the command chmod A + x oracle to grant the Oracle execution permission.
  3. Establish a service connection
    Ln-S/etc/rc. d/init. d/Oracle/etc/rc. d/rc2.d/s99oracle
    Ln-S/etc/rc. d/init. d/Oracle/etc/rc. d/rc3.d/s99oracle
    Ln-S/etc/rc. d/init. d/Oracle/etc/rc. d/rc5.d/s99oracle
    Ln-S/etc/rc. d/init. d/Oracle/etc/rc. d/rc0.d/k01oracle
    Ln-S/etc/rc. d/init. d/Oracle/etc/rc. d/rc6.d/k01oracle
  4. Test
    Run the./Oracle start command to check whether the database can be started. If not, view the log and find the cause.
    I encountered the following error message during execution.
    Can't find init file for Database "linuxdb ".
    Database "linuxdb" not started.
    View the script in $ {ORACLE_HOME}/bin/dbstart and find the statement based on the error message.
    $ {ORACLE_HOME}/dbs/init $ {oracle_sid}. ora configuration file
    Solution
    Sqlplus "/As sysdba"
    Create pfile from spfile;
    Then the execution succeeds.

    Restart the Linux host to check whether the database is automatically started.
    In addition, you can also start it in other ways. The system will traverse the/etc/profile. d directory during startup and execute all. Sh files.
    You can also modify the/etc/rc. d/rc. Local or/etc/rc. d/RC file to start the program. However, the user cannot be specified to start the program.
    If it is in UNIX, the startup script should be created in/sbin/init. d, and then in/sbin/RC0 ~ 6. Establish a connection under D;

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.