From Oracle 11gR2 onward the use of the
Both
Create a file called "/etc/init.d/dbora" as the root user, containing the following.
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database software.
ORA_OWNER=oracle
case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
# Remove "&" if you don't want startup as a background process.
su $ORA_OWNER -c "/home/oracle/scripts/startup.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1" &
touch /var/lock/subsys/dbora
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su $ORA_OWNER -c "/home/oracle/scripts/shutdown.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1"
rm -f /var/lock/subsys/dbora
;;
esac
Use the
dbstart
and dbshut
scripts is deprecated. In Oracle 11gR2 the preferred replacement is Oracle Restart. Oracle Restart is itself deprecated in Oracle 12c, with no nominated replacement at the time of writing.Both
dbstart
and dbshut
are still present
in Oracle 11gR2 and Oracle 12cR1, so you can continue to use them for
now (I still use them). In order to use Oracle Restart you must install
Grid Infrastructure (GI), which you will already have if you are using
RAC or ASM for a standalone instance. In these cases, Oracle Restart
will already be present and running. For single instance databases that
don't use ASM, I think it is unreasonable to expect people to install
GI, so the following describes a method for those cases, while avoiding dbstart
and dbshut
.Create a file called "/etc/init.d/dbora" as the root user, containing the following.
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database software.
ORA_OWNER=oracle
case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
# Remove "&" if you don't want startup as a background process.
su $ORA_OWNER -c "/home/oracle/scripts/startup.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1" &
touch /var/lock/subsys/dbora
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su $ORA_OWNER -c "/home/oracle/scripts/shutdown.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1"
rm -f /var/lock/subsys/dbora
;;
esac
Use the
chmod
command to set the privileges to 750. chmod 750 /etc/init.d/dbora
Associate the dbora service with the appropriate run levels and set it to auto-start using
the following command.
chkconfig --add dbora
Next, we must create the "startup.sh" and "shutdown.sh" scripts in the "/home/oracle/scripts". First create the directory.
# mkdir -p /home/oracle/scripts
# chown oracle.oinstall /home/oracle/scripts
#!/bin/bash
export TMP=/tmp
export TMPDIR=$TMP
export PATH=/usr/sbin:/usr/local/bin:$PATH
export ORACLE_HOSTNAME=ol6-121.localdomain
export ORACLE_UNQNAME=db12c
export ORACLE_SID=db12c
ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES
# Start Listener
lsnrctl start
# Start Database
sqlplus / as sysdba << EOF
STARTUP;
EXIT;
EOF
The "/home/oracle/scripts/shutdown.sh" script is similar.
#!/bin/bash
export TMP=/tmp
export TMPDIR=$TMP
export PATH=/usr/sbin:/usr/local/bin:$PATH
export ORACLE_HOSTNAME=ol6-121.localdomain
export ORACLE_UNQNAME=db12c
export ORACLE_SID=db12c
ORAENV_ASK=NO
. oraenv
ORAENV_ASK=YES
# Stop Database
sqlplus / as sysdba << EOF
SHUTDOWN IMMEDIATE;
EXIT;
EOF
# Stop Listener
lsnrctl stop
Make sure the permissions and ownership of the files is correct.
# chmod u+x /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh
# chown oracle.oinstall /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh
The listener and database will now start and stop automatically with the
machine. You can test them using the following command as the "root"
user.
# service dbora start
# service dbora stop
For more help visit
http://www.oracle-base.com/articles/linux/automating-database-startup-and-shutdown-on-linux.php#known_issues
No comments:
Post a Comment