记录日常工作关于系统运维,虚拟化云计算,数据库,网络安全等各方面问题。

Oracle Automating Database Startup/Shutdown on Linux



 Stopping and Starting Oracle Software

This chapter describes how to identify Oracle Database processes, and provides basic information about how to stop and restart them. It also describes how to set up automatic startup and shutdown of the Oracle Database. It contains the following sections:

2.1 Stopping and Starting Oracle Processes

This section describes how to stop and start Oracle processes. It contains the following topics:

2.1.1 Stopping and Starting Oracle Database and Automatic Storage Management Instances

This section describes how to stop and start Oracle Database and Automatic Storage Management instances.

Stopping an Oracle Database or Automatic Storage Management Instance

Caution:

Do not stop an Automatic Storage Management instance until you have stopped all Oracle Database instances that use that Automatic Storage Management instance to manage their storage.

To stop an Oracle Database or Automatic Storage Management instance:

  1. To identify the SID and Oracle home directory for the instance that you want to shut down, run the following command:

    On Solaris:

    $ cat /var/opt/oracle/oratab
    

    On other operating systems:

    $ cat /etc/oratab
    

    The oratab file contains lines similar to the following, which identify the SID and corresponding Oracle home directory for each database or Automatic Storage Management instance on the system:

    sid:oracle_home_directory:[Y|N]
    

    Note:

    Oracle recommends that you use the plus sign (+) as the first character in the SID of Automatic Storage Management instances.
  2. Depending on the default shell, run the oraenv or coraenv script to set the environment variables for the instance that you want to shut down:

    • Bourne, Bash, or Korn shell:

      $ . /usr/local/bin/oraenv
      
    • C shell:

      % source /usr/local/bin/coraenv
      

    When prompted, specify the SID for the instance.

  3. Run the following commands to shut down the instance:

    $ sqlplus
    SQL> CONNECT SYS as SYSDBA
    Enter password: sys_password
    SQL> SHUTDOWN NORMAL
    

    After the instance shuts down, you can quit SQL*Plus.

Restarting an Oracle Database or Automatic Storage Management Instance

Caution:

If the database instance uses Automatic Storage Management for storage management, then you must start the Automatic Storage Management instance before you start the database instance.

To restart an Oracle Database or Automatic Storage Management instance:

  1. If required, repeat Steps 1 and 2 of the preceding procedure to set the ORACLE_SID and ORACLE_HOME environment variables to identify the SID and Oracle home directory for the instance that you want to start.

  2. Run the following commands to start the instance:

    $ sqlplus
    SQL> CONNECT SYS as SYSDBA
    Enter password: sys_password
    SQL> STARTUP
    

    After the instance starts, you can exit from SQL*Plus.

2.1.2 Stopping and Starting Oracle Cluster Services Synchronization Daemon

To stop the Oracle Cluster Services Synchronization daemon, run the following command:

On AIX:

/etc/init.cssd stop

On HP-UX:

/sbin/init.d/init.cssd stop

On other platforms:

/etc/init.d/init.cssd stop

To start the Cluster Services Synchronization daemon, run the following command:

$ORACLE_HOME/bin/localconfig reset

This command stops the Oracle Cluster Services Synchronization daemon and then restarts it.

2.1.3 Stopping and Starting an Oracle Net Listener

This section describes how to stop and start an Oracle Net listener.

Stopping Oracle Net Listener

To stop an Oracle Net listener:

  1. Run the following command to determine the listener name and Oracle home directory for the Oracle Net listener that you want to stop:

    $ ps -ef | grep tnslsnr
    

    This command displays a list of the Oracle Net listeners running on the system. The output of this command is similar to the following:

    94248 ?? I 0:00.18 oracle_home1/bin/tnslsnr listenername1 -inherit
    94248 ?? I 0:00.18 oracle_home2/bin/tnslsnr listenername2 -inherit
    

    In this sample output, listenername1 and listenername2 are the names of the listeners.

  2. If required, set the ORACLE_HOME environment variable to specify the appropriate Oracle home directory for the listener that you want to stop:

    • Bourne, Bash, or Korn shell:

      $ ORACLE_HOME=oracle_home1
      $ export ORACLE_HOME
      
    • C shell:

      % setenv ORACLE_HOME oracle_home1
      
  3. Run the following command to stop the Oracle Net listener:

    $ $ORACLE_HOME/bin/lsnrctl stop listenername
    

    Note:

    If the name of the listener is the default name, LISTENER, then you do not have to specify the name in this command.

Restarting Oracle Net Listener

To start an Oracle Net listener:

  1. If required, set the ORACLE_HOME environment variable to specify the appropriate Oracle home directory for the listener that you want to start:

    • Bourne, Bash, or Korn shell:

      $ ORACLE_HOME=oracle_home1
      $ export ORACLE_HOME
      
    • C shell:

      % setenv ORACLE_HOME oracle_home1
      
  2. Run the following command to restart the Oracle Net listener:

    $ $ORACLE_HOME/bin/lsnrctl start [listenername]
    

    You must specify the listener name only if it is different from the default listener name, LISTENER. The listener name is mentioned in the listener.ora file. To display the contents of this file, run the following command:

    $ more $ORACLE_HOME/network/admin/listener.ora
    

2.1.4 Stopping and Starting Oracle Ultra Search

This section describes how to stop and start Oracle Ultra Search.

Stopping Oracle Ultra Search

To stop Oracle Ultra Search:

  1. If required, set the ORACLE_HOME environment variable to specify the appropriate Oracle home directory for Oracle Ultra Search:

    • Bourne, Bash, or Korn shell:

      $ ORACLE_HOME=oracle_home
      $ export ORACLE_HOME
      
    • C shell:

      % setenv ORACLE_HOME oracle_home
      
  2. Run the following command to stop Oracle Ultra Search:

    $ $ORACLE_HOME/bin/searchctl stop
    

Starting Oracle Ultra Search

To start Oracle Ultra Search:

  1. If required, set the ORACLE_HOME environment variable to specify the appropriate Oracle home directory for Oracle Ultra Search:

    • Bourne, Bash, or Korn shell:

      $ ORACLE_HOME=oracle_home
      $ export ORACLE_HOME
      
    • C shell:

      % setenv ORACLE_HOME oracle_home
      
  2. Run the following command to start Oracle Ultra Search:

    $ $ORACLE_HOME/bin/searchctl start
    

2.1.5 Stopping and Starting Oracle Enterprise Manager Database Control

This section describes how to stop and start Oracle Enterprise Manager Database Control.

Stopping Oracle Enterprise Manager Database Control

To stop Oracle Enterprise Manager Database Control:

  1. Depending on the default shell, run the oraenv or coraenv script to set the environment for the database managed by the Database Control that you want to stop:

    • coraenv script:

      % source /usr/local/bin/coraenv
      
    • oraenv script:

      $ . /usr/local/bin/oraenv
      
  2. Run the following command to stop the Database Control:

    $ $ORACLE_HOME/bin/emctl stop dbconsole
    

Starting Oracle Enterprise Manager Database Control

To start Database Control:

  1. Set the ORACLE_SID and ORACLE_HOME environment variables to identify the SID and Oracle home directory for the database control that you want to start:

    • Bourne, Bash, or Korn shell:

      $ ORACLE_HOME=oracle_home
      $ ORACLE_SID=sid
      $ export ORACLE_HOME ORACLE_SID
      
    • C shell:

      % setenv ORACLE_HOME oracle_home
      % setenv ORACLE_SID sid
      
  2. Run the following command to start the Database Control:

    $ $ORACLE_HOME/bin/emctl start dbconsole
    

2.1.6 Stopping and Starting Oracle Management Agent

If you are using Oracle Enterprise Manager Grid Control to manage multiple Oracle products from a central location, then you must have an Oracle Management Agent installed on each host system. Typically, the Oracle Management Agent is installed in its own Oracle home directory.

This section describes how to stop and start Oracle Management Agent.

Stopping Oracle Management Agent

To stop Oracle Management Agent:

  1. Run the following command to determine the Oracle home directory for Oracle Management Agent:

    $ ps -ef | grep emagent
    

    This command displays information about the Oracle Management Agent processes. The output of this command is similar to the following:

    94248 ?? I 0:00.18 oracle_home/agent/bin/emagent ...
    
  2. If required, set the ORACLE_HOME environment variable to specify the appropriate Oracle home directory for the Oracle Management Agent:

    • Bourne, Bash, or Korn shell:

      $ ORACLE_HOME=oracle_home
      $ export ORACLE_HOME
      
    • C shell:

      % setenv ORACLE_HOME oracle_home
      
  3. Run the following command to stop Oracle Management Agent:

    $ $ORACLE_HOME/agent/bin/emctl stop agent
    

Starting Oracle Management Agent

To start Oracle Management Agent:

  1. If required, set the ORACLE_HOME environment variable to specify the appropriate Oracle home directory for Oracle Management Agent:

    • Bourne, Bash, or Korn shell:

      $ ORACLE_HOME=oracle_home
      $ export ORACLE_HOME
      
    • C shell:

      % setenv ORACLE_HOME oracle_home
      
  2. Run the following command to start Oracle Management Agent:

    $ $ORACLE_HOME/agent/bin/emctl start agent
    

2.2 Automating Shutdown and Startup

Oracle recommends that you configure the system to automatically start Oracle Database when the system starts, and to automatically shut it down when the system shuts down. Automating database startup and shutdown guards against incorrect database shutdown.

To automate database startup and shutdown, use the dbstart and dbshut scripts, which are located in the $ORACLE_HOME/bin directory. The scripts refer to the same entries in the oratab file, which are applied on the same set of databases. You cannot, for example, have the dbstart script automatically start sid1sid2, and sid3, and have the dbshut script shut down only sid1. However, you can specify that the dbshut script shuts down a set of databases while the dbstart script is not used at all. To do this, include a dbshut entry in the system shutdown file, but do not include the dbstart entry from the system startup files.

See Also:

The init command in the operating system documentation for more information about system startup and shutdown procedures

2.2.1 Automating Database Startup and Shutdown on Other Operating Systems

To automate database startup and shutdown by using the dbstart and dbshut scripts:

  1. Log in as the root user.

  2. Edit the oratab file for the platform.

    To open the file, use one of the following commands:

    • On Solaris:

      # vi /var/opt/oracle/oratab
      
    • On AIX, HP-UX, and Linux:

      # vi /etc/oratab
      

    Database entries in the oratab file are displayed in the following format:

    SID:ORACLE_HOME:{Y|N|W}
    

    In this example, the values Y and N specify whether you want the scripts to start or shut down the database, respectively. For each database for which you want to automate shutdown and startup, first determine the instance identifier (SID) for that database, which is identified by the SID in the first field. Then, change the last field for each to Y.

    You can set dbstart to autostart a single-instance database that uses an Automatic Storage Management installation that is auto-started by Oracle Clusterware. This is the default behavior for an Automatic Storage Management cluster. If you want to do this, then you must change the oratab entry of the database and the Automatic Storage Management installation to use a third field with the value W and N, respectively. These values specify that dbstart auto-starts the database only after the Automatic Storage Management instance is started.

    Note:

    If you add new database instances to the system and automate startup for them, then you must edit the entries for those instances in the oratab file.
  3. Change directory to one of the following depending on the operating system:

    PlatformInitialization File Directory
    AIX/etc
    Linux and Solaris/etc/init.d
    HP-UX/sbin/init.d

  4. Create a file called dbora, and copy the following lines into this file:

    Note:

    Change the value of the ORACLE_HOME environment variable to an Oracle home directory for the installation. Change the value of the ORACLE environment variable to the user name of the owner of the database installed in the Oracle home directory (typically, oracle).
    #! /bin/sh  -x
    #
    # Change the value of ORACLE_HOME to specify the correct Oracle home
    # directory for your installation.
    
    ORACLE_HOME=/u01/app/oracle/product/11.1.0/db_1
    #
    # Change the value of ORACLE to the login name of the
    # oracle owner at your site.
    #
    ORACLE=oracle
    
    PATH=${PATH}:$ORACLE_HOME/bin
    HOST=`hostname`
    PLATFORM=`uname`
    export ORACLE_HOME PATH
    #
    if [ ! "$2" = "ORA_DB" ] ; then
       if [ "$PLATFORM" = "HP-UX" ] ; then
          remsh $HOST -l $ORACLE -n "$0 $1 ORA_DB"
          exit
       else
          rsh $HOST -l $ORACLE  $0 $1 ORA_DB
          if [ "$PLATFORM" = "Linux" ] ; then
              touch /var/lock/subsys/dbora
          fi
          exit
       fi
    fi
    #
    case $1 in
    'start')
            $ORACLE_HOME/bin/dbstart $ORACLE_HOME &
            ;;
    'stop')
            $ORACLE_HOME/bin/dbshut $ORACLE_HOME &
            ;;
    *)
            echo "usage: $0 {start|stop}"
            exit
            ;;
    esac
    #
    exit
    

    Note:

    This script can only stop Oracle Net listener for which a password has not been set. In addition, if the listener name is not the default name, LISTENER, then you must specify the listener name in the stop and start commands:
    $ORACLE_HOME/bin/lsnrctl {start|stop} listener_name
    
  5. Change the group of the dbora file to the OSDBA group (typically dba), and set the permissions to 750:

    # chgrp dba dbora
    # chmod 750 dbora
    
  6. Create symbolic links to the dbora script in the appropriate run-level script directories as follows.

    PlatformSymbolic Links Commands
    AIX
    # ln -s /etc/dbora /etc/rc.d/rc2.d/S99dbora
    # ln -s /etc/dbora /etc/rc.d/rc2.d/K01dbora
    
    HP-UX
    # ln -s /sbin/init.d/dbora /sbin/rc3.d/S990dbora
    # ln -s /sbin/init.d/dbora /sbin/rc0.d/K001dbora
    
    Linux
    # ln -s /etc/init.d/dbora /etc/rc.d/rc0.d/K01dbora
    # ln -s /etc/init.d/dbora /etc/rc.d/rc3.d/S99dbora
    # ln -s /etc/init.d/dbora /etc/rc.d/rc5.d/S99dbora
    
    Solaris
    # ln -s /etc/init.d/dbora /etc/rc0.d/K01dbora
    # ln -s /etc/init.d/dbora /etc/rc3.d/S99dbora
    





Oracle provides the and scripts that can be used to start the the databases when the Operating System boots and to stop the databases when shutting down the Operating System.

Both the and scripts read the file to determine which databases to start and stop. All databases started with will be stopped by . Starting with Oracle 10gR2, the and scripts will start and stop the listener provided the listener has the default name and that the listener is not password protected.
ORACLE_HOME/bin/dbstartORACLE_HOME/bin/dbshutdbstart dbshut /etc/oratabdbstart dbshutdbstart dbshut

The needs to be edited to set the startup flag to Y to allow to start the instance. Entries in the file have the following format./etc/oratabdbstart /etc/oratab

ORACLE_SID:ORACLE_HOME:{Y|N|W}

ORACLE_SID – Database System Identifier
– Complete path to the Oracle Home
– Flags used by to determine if the instance should be started. Y – Yes, N – No. W is used with ASM to direct dbstart to only start the instance after ASM is started.
ORACLE_HOME{Y|N|W}dbstart

For an of test with an you would use an entry like the following.ORACLE_SIDORACLE_HOME of /u01/app/oracle/product/11.2.0/dbhome_1

test:/u01/app/oracle/product/11.2.0/dbhome_1:Y

With the settings made in the you should be able to at this time test the start up and shutdown scripts as the Oracle software owner./etc/oratab

The path to the needs to be passed in order for and to startup and shutdown the Listener along with the database. 

If the path is not provided a message will be given that the is not set.ORACLE_HOMEdbstart dbshut ORACLE_HOME_LISTENER

[oracle@odreccat etc]$ dbstart
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart ORACLE_HOME
Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log
[oracle@odreccat etc]$ 

Both and are scripts located in . A quick look at dbstart and we see that the first argument is used to set . dbstart dbshut ORACLE_HOME/binORACLE_HOME_LISTENER

# First argument is used to bring up Oracle Net Listener
ORACLE_HOME_LISTNER=$1
if [ ! $ORACLE_HOME_LISTNER ] ; then
  echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener"
  echo "Usage: $0 ORACLE_HOME"
else
  LOG=$ORACLE_HOME_LISTNER/listener.log

  # Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to
  # a different ORACLE_HOME for each entry in the oratab.
  export ORACLE_HOME=$ORACLE_HOME_LISTNER

  # Start Oracle Net Listener
  if [ -x $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then
    echo "$0: Starting Oracle Net Listener" >> $LOG 2>&1
    $ORACLE_HOME_LISTNER/bin/lsnrctl start >> $LOG 2>&1 &
    VER10LIST=`$ORACLE_HOME_LISTNER/bin/lsnrctl version | grep "LSNRCTL for " | cut -d' ' -f5 | cut -d'.' -f1`
    export VER10LIST
  else
    echo "Failed to auto-start Oracle Net Listener using $ORACLE_HOME_LISTNER/bin/tnslsnr"
  fi
fi

You can either provide the complete path of the Oracle Home or the environment variable if set. When the Oracle Home is set the message about the is not present.ORACLE_HOME_LISTENER

[oracle@odreccat etc]$ dbstart $ORACLE_HOME
Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log
[oracle@odreccat etc]$ 

Next a script needs to be prepared to handle the starting and stopping of the service. Oracle provides a script to handle this requirement. 

The script is commonly called but can be given any name. As the root user create the file using the script below.dbora /etc/init.d/dbora

#!/bin/sh
# chkconfig: 345 99 10
# description: Service to start and stop Oracle Database and Listener
#
# processname: oracle
# config: /etc/oratab
# pidfile: /var/run/oracle.pid

# Source function library.
. /etc/init.d/functions

RETVAL=0
ORA_OWNER="oracle"
ORA_HOME="/u01/app/oracle/product/11.2.0/dbhome_1"

# See how we were called.

prog="oracle"

start() {
echo -n $"Starting $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/dbora

return $RETVAL
}

stop() {
echo -n $"Stopping $prog: "
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -r /var/lock/subsys/dbora

return $RETVAL
}

restart() {
stop
start
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac

exit $?

The only changes you need to make to this script are to provide values for ORA_OWNER and ORA_HOME that match your system. 

Change the group of to (dba) and set the permissions to 750.dbora OSDBA

[root@odreccat ~]# chgrp  dba /etc/init.d/dbora 
[root@odreccat ~]# chmod 750 /etc/init.d/dbora 
[root@odreccat ~]# ls -al /etc/init.d/dbora 
-rwxr-x--- 1 root dba 877 Sep  6 12:16 /etc/init.d/dbora
[root@odreccat ~]# 

While still logged in as the root user execute the script with both the start and stop arguments.dbora

[root@odreccat init.d]# ./dbora start
Starting oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log

[root@odreccat init.d]# ./dbora stop
Stopping oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/shutdown.log

[root@odreccat init.d]# 

The results should be no different than when executing dbstart or dbshut. 

Next register the service at run-levels 3,4, and 5 and set it to auto start using .chkconfig

[root@odreccat ~]# chkconfig --level 345 dbora on

With the service registered starting and stopping the oracle services can be done with the service command.

[root@odreccat init.d]# service dbora start
Starting oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log

[root@odreccat init.d]# service dbora stop
Stopping oracle: Processing Database instance "reccat": log file /u01/app/oracle/product/11.2.0/dbhome_1/shutdown.log

[root@odreccat init.d]# 

The service can also be started using the GUI tool Service Configuration found under System | Administration | Services.

The database and listener are now configured to startup and shutdown along with the server.




转载请标明出处【Automating Database Startup/Shutdown on Linux】。

《www.micoder.cc》 虚拟化云计算,系统运维,安全技术服务.

网站已经关闭评论