How to Set auto-start for oracle in linux

Source: Internet
Author: User
Tags stop script

After installing Oracle 10g R2 in CentOS 6.3 and restarting it, you will find that Oracle is not started on your own. This is normal because Oracle Installation in Linux does not start on your own, you must set relevant parameters. First, we will introduce how to start oracle.

1. Start Oracle in Linux

Log on to CentOS and switch to oracle user permissions.

# Su-oracle

Enter:

$ Sqlplus "/as sysdba"

The original image will become
SQL>

Enter
SQL> startup

You can start the database normally.

In addition, the command to stop the database is as follows:
SQL> shutdown immediate

2. Check whether the Oracle DB listener is normal

Return to Terminal Mode and enter:

$ Lsnrctl status

Check to see if the listener is started

If it is not started, enter:

$ Lsnrctl start

Start listener

SQL> conn sys @ orcl as sysdba

Then enter the password and sys will log on to the database as sysdba.

Iii. Start emctl

In addition, we can also find that http://localhost.localdomain: 1158/em is currently no response, here to start another, the startup command is as follows:

$ Emctl start dbconsole

The command runs for a long time. The execution result is as follows:

After you manually start the Oracle database, create a script for the system to start Oracle.

4. Oracle startup and stop scripts

1. Modify the Oracle system configuration file:/etc/oratab. Only in this way can dbstart and dbshut of Oracle be used.

# Vi/etc/oratab
Orcl:/opt/oracle/102: Y

# Entries are of the form:
# $ ORACLE_SID: $ ORACLE_HOME: <N | Y>:

2. Create the file oracle under/etc/init. d/. The content is as follows:
Copy codeThe Code is as follows:
#! /Bin/sh
# Chkconfig: 35 80 10
# Description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ ORACLE_HOME
# From which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of
# Oracle database in ORA_HOME.
ORA_HOME =/opt/oracle/102
ORA_OWNER = oracle
If [! -F $ ORA_HOME/bin/dbstart]
Then
Echo "Oracle startup: cannot start"
Exit
Fi
Case "$1" in
'Start ')
# Start the Oracle databases:
Echo "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_OWNER-c "$ ORA_HOME/bin/dbstart">/var/log/oracle
Echo "Done"
# Start the Listener:
Echo "Starting Oracle Listeners ..."
Echo "-----------------------------------------------">/var/log/oracle
Date + "% T % a % D: Starting Oracle Listeners as part of system up.">/var/log/oracle
Echo "-----------------------------------------------">/var/log/oracle
Su-$ ORA_OWNER-c "$ ORA_HOME/bin/lsnrctl start">/var/log/oracle
Echo "Done ."
Echo "-----------------------------------------------">/var/log/oracle
Date + "% T % a % D: Finished.">/var/log/oracle
Echo "-----------------------------------------------">/var/log/oracle
Touch/var/lock/subsys/oracle

'Stop ')
# Stop the Oracle Listener:
Echo "Stoping Oracle Listeners ..."
Echo "-----------------------------------------------">/var/log/oracle
Date + "% T % a % D: Stoping Oracle Listener as part of system down.">/var/log/oracle
Echo "-----------------------------------------------">/var/log/oracle
Su-$ ORA_OWNER-c "$ ORA_HOME/bin/lsnrctl stop">/var/log/oracle
Echo "Done ."
Rm-f/var/lock/subsys/oracle
# Stop the Oracle Database:
Echo "Stoping Oracle Databases ..."
Echo "-----------------------------------------------">/var/log/oracle
Date + "% T % a % D: Stoping Oracle Databases as part of system down.">/var/log/oracle
Echo "-----------------------------------------------">/var/log/oracle
Su-$ ORA_OWNER-c "$ ORA_HOME/bin/dbshut">/var/log/oracle
Echo "Done ."
Echo ""
Echo "-----------------------------------------------">/var/log/oracle
Date + "% T % a % D: Finished.">/var/log/oracle
Echo "-----------------------------------------------">/var/log/oracle

'Restart ')
$0 stop
$0 start

Esac

3. Change File Permissions
# Chmod 755/etc/init. d/oracle

4. Add a service
# Chkconfig -- level 35 oracle on

5. You need to stop the database before shutting down or restarting the machine.
# Ln-s/etc/init. d/oracle/etc/rc0.d/K01oracle // Shutdown
# Ln-s/etc/init. d/oracle/etc/rc6.d/K01oracle // restart

6. Usage
# Service oracle start // start oracle
# Service oracle stop // close oracle
# Service oracle restart // restart oracle

7. Test

A. Auto Start

Copy codeThe Code is as follows:
Last login: Mon Nov 26 19:57:06 2012 from 10.0.0.145
[Root @ ORS ~] # Su-oracle
[Oracle @ ORS ~] $ Sqlplus "/as sysdba"

SQL * Plus: Release 10.2.0.1.0-Production on Mon Nov 26 20:07:33 2012

Copyright (c) 1982,200 5, Oracle. All rights reserved.


Connected:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Production
With the Partitioning, OLAP and Data Mining options

SQL> set linesize 300;
SQL> set pagesize 30;
SQL> select * from scott. emp;

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
------------------------------------------------------------------------------
Smith clerk 7902 17-DEC-80 800 20
Allen salesman 7698 20-FEB-81 1600 300 30
Ward salesman 7698 22-FEB-81 1250 500 30
Jones manager 7839 02-APR-81 2975 20
Martin salesman 7698 28-SEP-81 1250 1400 30
Blake manager 7839 01-MAY-81 2850 30
Clark manager 7839 09-JUN-81 2450 10
Scott analyst 7566 19-APR-87 3000 20
King president 17-NOV-81 5000 10
Turner salesman 7698 08-SEP-81 1500 0 30
Adams clerk 7788 23-MAY-87 1100 20
James clerk 7698 03-DEC-81 950 30
Ford analyst 7566 03-DEC-81 3000 20
Miller clerk 7782 23-JAN-82 1300 10
Rows selected.

SQL>

B. service oracle stop

Copy codeThe Code is as follows:
SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Production
With the Partitioning, OLAP and Data Mining options
[Oracle @ ORS ~] $ Logout
[Root @ ORS ~] # Service oracle stop
Stoping Oracle Listeners...
Done.
Stoping Oracle Databases...
Done.
[Root @ ORS ~] # Su-oracle
[Oracle @ ORS ~] $ Sqlplus "/as sysdba"
SQL * Plus: Release 10.2.0.1.0-Production on Mon Nov 26 20:17:20 2012
Copyright (c) 1982,200 5, Oracle. All rights reserved.
Connected to an idle instance.
SQL> set linesize 300;
SQL> set pagesize 30;
SQL> select * from scott. emp;
Select * from scott. emp
*
ERROR at line 1:
A ORA-01034: ORACLE not available
SQL>

C. service oracle start

Copy codeThe Code is as follows:
SQL> Disconnected
[Oracle @ ORS ~] $ Logout
[Root @ ORS ~] # Service oracle start
Starting Oracle Databases...
Done
Starting Oracle Listeners...
Done.
[Root @ ORS ~] #

D. service oracle restart

Copy codeThe Code is as follows:
[Root @ ORS ~] # Service oracle restart
Stoping Oracle Listeners...
Done.
Stoping Oracle Databases...
Done.

Starting Oracle Databases...
Done
Starting Oracle Listeners...
Done.
[Root @ ORS ~] #

Now, the script for starting and stopping the Oracle service and the auto-starting setting for starting the Oracle service are complete.

Related Article

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.