Oracle Service Start & Stop script and auto start

Source: Internet
Author: User
Tags stop script
After Oracle10gR2 is installed in CentOS6.3 and you reactivate 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 and log on to CentOS. switch to oracle User permissions # su? Oracle

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

2. create the file oracle under/etc/init. d/. the content 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 the# 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

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 2012Copyright (c) 1982, 2005, Oracle.  All rights reserved.Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith the Partitioning, OLAP and Data Mining optionsSQL> set linesize 300;SQL> set pagesize 30;SQL> select * from scott.emp;     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO---------- ---------- --------- ---------- --------- ---------- ---------- ----------      7369 SMITH      CLERK           7902 17-DEC-80        800                    20      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30      7566 JONES      MANAGER         7839 02-APR-81       2975                    20      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10      7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20      7839 KING       PRESIDENT            17-NOV-81       5000                    10      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30      7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20      7900 JAMES      CLERK           7698 03-DEC-81        950                    30      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20      7934 MILLER     CLERK           7782 23-JAN-82       1300                    1014 rows selected.SQL> 

B. service oracle stop

SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProductionWith the Partitioning, OLAP and Data Mining options[oracle@ORS ~]$ logout[root@ORS ~]# service oracle stopStoping 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 2012Copyright (c) 1982, 2005, 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:ORA-01034: ORACLE not availableSQL> 

C. service oracle start

SQL> Disconnected[oracle@ORS ~]$ logout[root@ORS ~]# service oracle startStarting Oracle Databases ... DoneStarting Oracle Listeners ... Done.[root@ORS ~]# 

D. service oracle restart

[root@ORS ~]# service oracle restartStoping Oracle Listeners ... Done.Stoping Oracle Databases ... Done.Starting Oracle Databases ... DoneStarting 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.