Utilities for Starting and
Stopping Databases
Oracle provides two UNIX scripts that assist DBAs
with starting and stopping the database: dbstart and dbshut. For Windows
platforms, the oradim utility is provided for starting and stopping the Oracle
instance.
The dbstart utility reads the oratab file, shown
in the example below. The oratab file will reside in either /etc or /var/opt/oracle,
depending on the UNIX version. It contains three data items separated by colons:
ASG920xr:/usr/oracle/9.2.0:Y
ASG817xr:/usr/oracle/8.1.7:Y
TEST920xr:/usr/oracle/9.2.0:N
PROD920xr:/usr/oracle/9.2.0:N
The first field is the Oracle SID. The second
field is the home directory for that Oracle SID. The Y or N instructs Oracle
whether to start or stop the particular database when either the dbstart or
dbshut command is issued. The dbstart command simply parses the oratab file and
starts those databases that have a Y in the third field. It also uses the
ORACLE_HOME specified in the file to connect internally to the database and
issue the startup command.
The dbstart command can be added to the UNIX
servers’ initialization or run level scripts. This enables dbstart to be
executed each time the machine is booted or when it changes run levels. The
method for implementing this is platform-specific, as we see below.
Auto Start on HP-UX and Solaris
For HP-UX version 10 and above, the system
initialization scripts are contained in /etc/rc<n>.d directories, where
“n” is the operating system run-level. These directories contain scripts
that begin with K or S, followed by a number, and then a file name (S75cron).
All scripts that begin with “S” are executed at system startup in ascending
order of their number. Scripts beginning with “K” (Kill) are called at
system shutdown time.
As a general rule of thumb, the Oracle startup
script should have a high sequence number (S99dbstart), which will ensure that
other system processes have been started prior to Oracle. Likewise, the kill
scripts should have a low sequence number in order to shut down Oracle early in
the process (K01dbshut).
Auto Start on AIX
For AIX servers, the system initialization file
is /etc/inittab and the initialization script is /etc/rc. A utility (/usr/sbin/mkitab)
can be used to make an entry in the inittab file. The shutdown script for AIX is
/usr/sbin/shutdown, although it should not be modified to support
dbshut.
To add the dbstart utility to the AIX
initialization process, the following steps can be performed:
1. Create
the script /etc/rc.oracle. The script should contain the following:
su oracle <<EOF
<$ORACLE_HOME>/bin/dbstart
EOF
-
Add the script to the inittab using the mkitab utility.
$ /usr/sbin/mkitab “rcoracle:2:wait:/etc.rc.oracle >/dev/console 2>&1”
All references to <$ORACLE_HOME> should be
replaced with the actual Oracle Home directory. Now upon system startup, the
dbstart utility is invoked at run level 2.
Starting and Stopping on Windows
The dbstart and dbstop shell scripts do not exist
on Windows platforms. Consequently Oracle database startup and shutdown is
implemented completely differently. The oradim utility is used on the Windows
platform to perform these tasks.
C:\oracle9i\bin\oradim -startup -sid ORCL92 –usrpwd manager
-starttype SRVC,INST -pfile C:\oracle9i\admin\ORCL92\pfile\init.ora
- startup —
Indicates that the specified instance should be started.
- sid — The SID
of the database to start.
- usrpwd — The
password for the database user.
- starttype —
Specifies whether to start the instance, the service, or both (SRVC,
INST).
The following command can be used to shutdown the
instance with oradim:
C:\oracle9i\bin\oradim -shutdown -sid ORCL92 -shutttype SRVC,INST
–shutmode A
Notice that no password is needed to perform this
task.
The shuttype parameter specifies what is to be
stopped – the service (SRVC), the instance (INST), or both (SRVC, INST). The
shutmode specifies the method that should perform the shutdown – (A)bort, (I)mmediate,
or (N)ormal.
Each operation, regardless of success, is logged
in the oradim log file (ORACLE_HOME\database\OraDim.Log). This file should be
checked for errors after each oradim command is executed.
The oradim utility provides more than just the
ability to start and stop Windows databases. oradim can create and edit
databases. It also allows DBAs to configure script-based installation
mechanisms, bypassing the Oracle Database Configuration Assistant’s graphical
user interface (GUI).
For a reference of all oradim commands, use the
oradim–help command.
oraenv and coraenv Utilities
The oraenv and coraenv utilities both aid in
setting the Oracle environment on UNIX systems (other utilities exist on Windows
platform that enable the Oracle Home to be set.) The coraenv utility is
appropriate for the UNIX C Shell; oraenv should be used with either the Bourne
or Korn shells.
Database operations require the ORACLE_HOME to be
set before the user may access the database. If ORACLE_HOME is not set, commands
such as sqlplus, exp, or any other utility for that matter, will not be found.
Both utilities are shell scripts that do the same
thing in the different UNIX shells. They will prompt for a SID of the database
unless ORAENV_ASK is set to N. The utility will also append the ORACLE_HOME
value to the path, marking the location of the utility.
The oraenv command will prompt for the SID of the
database that you wish $ORACLE_HOME to access.
$ . oraenv
ORACLE_SID = [] ? ASG920
The dbhome utility can now be used to verify that
$ORACLE_HOME is correct.
$ dbhome
/usr/oracle/9.2.0
The “dot space” part of the command is
required to make the environment change with the parent shell, as opposed to
entering a command without it which would only affect the subshell running that
process.
These commands can be used to avoid specifying
the network service name when issuing commands. For instance, without using
oraenv, an sqlplus command would look like:
$ sqlplus system/manager@nameofservice as sysdba
whereas after oraenv has been executed, the
following command would work:
$ sqlplus system/manager as sysdba
|