Todos nos hemos encontrado en un escenario donde no tengamos configurado Oracle Restart o Clusterware, donde tenemos que automatiozar el arranque de las bases de datos mediante scripts.
Hablando claro, caso de Single Instance sobre filesystem o Single Instance no configurada como recurso.
Oracle nos ofrece los scripts dbstart y dbshut para facilitar dicha tarea, que se basa en la configuración que tengamos en /etc/oratab para arrancarlas (/var/opt/oracle/oratab en el caso de Solaris), pudiendo definir cuales queremos que arranquen en el caso de tener varias en el mismo servidor.
Es script dbstart iniciará las bases de datos en modo OPEN, pero y si queremos que abran en modo mount? Por ejemplo teniendo configurada una standby (si no queremos pasar por caja).
Pues fácil, modificando el script propio de Oracle 🙂
Para ello buscaremos en el script $ORACLE_HOME/bin/dbstart el siguiente apartado y moficamos las líneas señaladas por startup mount.
# Starts a Database Instance
startinst() {
# Called programs use same database ID
export ORACLE_SID
# Put $ORACLE_HOME/bin into PATH and export.
PATH=$ORACLE_HOME/bin:${SAVE_PATH} ; export PATH
# add for bug # 652997
LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${SAVE_LLP} ; export LD_LIBRARY_PATH
PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora
SPFILE=${ORACLE_HOME}/dbs/spfile${ORACLE_SID}.ora
SPFILE1=${ORACLE_HOME}/dbs/spfile.ora
echo ""
echo "$0: Starting up database \\"$ORACLE_SID\\""
date
echo ""
checkversionmismatch
# See if it is a V6 or V7 database
VERSION=undef
if [ -f $ORACLE_HOME/bin/sqldba ] ; then
SQLDBA=sqldba
VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk '
/SQL\\*DBA: (Release|Version)/ {split($3, V, ".") ;
print V[1]}'`
case $VERSION in
"6") ;;
*) VERSION="internal" ;;
esac
else
if [ -f $ORACLE_HOME/bin/svrmgrl ] ; then
SQLDBA=svrmgrl
VERSION="internal"
else
SQLDBA="sqlplus /nolog"
fi
fi
STATUS=1
if [ -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.dbf ] ; then
STATUS="-1"
fi
if [ -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.ora ] ; then
STATUS="-1"
fi
pmon=`ps -ef | grep -w "ora_pmon_$ORACLE_SID" | grep -v grep`
if [ "$pmon" != "" ] ; then
STATUS="-1"
$LOGMSG "Warning: ${INST} \\"${ORACLE_SID}\\" already started."
fi
if [ $STATUS -eq -1 ] ; then
$LOGMSG "Warning: ${INST} \\"${ORACLE_SID}\\" possibly left running when system went down (system crash?)."
$LOGMSG "Action: Notify Database Administrator."
case $VERSION in
"6") sqldba "command=shutdown abort" ;;
"internal") $SQLDBA $args <<EOF
connect internal
shutdown abort
EOF
;;
*) $SQLDBA $args <<EOF
connect / as sysdba
shutdown abort
quit
EOF
;;
esac
if [ $? -eq 0 ] ; then
STATUS=1
else
$LOGMSG "Error: ${INST} \\"${ORACLE_SID}\\" NOT started."
fi
fi
if [ $STATUS -eq 1 ] ; then
if [ -e $SPFILE -o -e $SPFILE1 -o -e $PFILE ] ; then
case $VERSION in
"6") sqldba command=startup ;;
"internal") $SQLDBA <<EOF
connect internal
startup mount <<<<<<<<<<<<<<<<<<<<<---------------------------------
EOF
;;
*) $SQLDBA <<EOF
connect / as sysdba
startup mount <<<<<<<<<<<<<<<<<<<<<---------------------------------
quit
EOF
;;
esac
Ahora la parte fácil, creación de un script para integrar con la parada y arranque del servidor
cat /etc/init.d/dbora19c #! /bin/sh # description: Oracle auto start-stop script. # # Set ORACLE_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 ORACLE_HOME. #chkconfig: 345 99 03 # description: Start/Stop the Databases... ORA_HOME=/u01/app/oracle/product/19.5.0/dbhome_pro 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 "$ORA_HOME/bin/dbstart $ORA_HOME" & 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 "$ORA_HOME/bin/dbshut $ORA_HOME" & rm -f /var/lock/subsys/dbora ;; esac
Otorgamos los permisos adecuados chgrp dba /etc/init.d/dbora19c chmod 750 /etc/init.d/dbora19c
Creamos enlaces simbólicos ln -s /etc/init.d/dbora19c /etc/rc.d/rc0.d/K01dbora19c ln -s /etc/init.d/dbora19c /etc/rc.d/rc3.d/S99dbora19c ln -s /etc/init.d/dbora19c /etc/rc.d/rc5.d/S99dbora19c
Y finalmente integramos el script con el arranque/parada del servidor a nivel de SO
[root@servidor ~]# chkconfig --add dbora19c [root@servidor ~]# chkconfig --level 345 dbora19c on [root@servidor ~]# chkconfig --list |grep dbora19c Nota: Esta salida muestra sólo servicios SysV y no incluye servicios nativos de systemd. Los datos de configuración SysV pueden verse invalidados por la configuración nativa de systemd. Si desea una lista de servicios systemd use 'systemctl list-unit-files'. Para ver los servicios que se activan para un objetivo concreto use 'systemctl list-dependencies [objetivo]'. dbora19c 0:desactivado 1:desactivado 2:desactivado 3:activo 4:activo 5:activo 6:desactivado
Ahora solo queda editar el oratab indicando Y, reiniciar el servidor y ver la mágia del autoarranque en modo mount 🙂
