在 Linux 系统下安装完数据库之后,会在$ORACLE_HOME/bin 下生成 dbstart 和 dbshut 脚本,这两个脚本可以简便地实现启动和关闭数据库。
这两个脚本运行时会读取/etc/oratab 文件,在这个文件里指定了需要启动和关闭的 SID(相应 SID 那行的最后一个字符是 Y 而不是 N)
DBSHUT 的问题:
默认是执行 shutdown 而不是 shutdown immediate,这样当有别的 client 连着的时候,数
据库不会 shutdown,可以把该脚本执行 shutdown 的部分改成 shutdown immediate,当
然是不是需要这样强行切断用户连接,rollback 所有未 commit 的 transaction,还需要看自
己的需求了。
DBSTART 问题:
执行时会检查在$ORACLE_HOME/dbs 中有没有 initSID.ora 文件,如果没有则报错退出。但
是安装 9i 的时候通常会使用 spfile,所以在此目录下是不会存在 initSID.ora 文件的。修改的
方法有两个:
一是改脚本,在 else 后面加判是否存在 spfile,如果有继续,没有再报错,但是此方法比较麻
烦
二是创建一个 pfile,用 create pfile=pfilepath from spfile=spfilepath 就可以了,此命令
在数据库 instance 没有启动的情况下也可以执行。
感觉这是 Oracle 的一个遗留问题,因为可以看到即使是检查了 pfile,Oracle 的启动仍然使用
了 spfile
# This file is used by ORACLE utilities. It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.
# A colon, ':', is used as the field terminator. A new line terminates
# the entry. Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively. The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
DEVRWA:/u01/orcl/product/10.2.0/db:N
###################################
#
# usage: dbshut $ORACLE_HOME
#
# This script is used to shutdown ORACLE from /etc/rc(.local).
# It should ONLY be executed as part of the system boot procedure.
#
# This script will shutdown all databases listed in the oratab file
# whose third field is a "Y" or "W". If the third field is set to "Y" and
# there is no ORACLE_SID for an entry (the first field is a *),
# then this script will ignore that entry.
#
# This script requires that ASM ORACLE_SID's start with a +, and
# that non-ASM instance ORACLE_SID's do not start with a +.
#
# Note:
# Use ORACLE_TRACE=T for tracing this script.
# Oracle Net Listener is also shutdown using this script.
#
# The progress log for each instance shutdown is logged in file
# $ORACLE_HOME/shutdown.log.
#
# To configure:
# 1) Set ORATAB:
# On Solaris
# ORATAB=/var/opt/oracle/oratab
# All other UNIX platforms
# ORATAB=/etc/oratab
#
# 2) Update $ORATAB/oratab with Database Instances that need to be shutdown.
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME:<N|Y>:
# An example entry:
# main:/usr/lib/oracle/emagent_10g:Y
#
# Note:
# Use ORACLE_TRACE=T for tracing this script.
# Oracle Net Listener is NOT shutdown using this script.
#
# The progress log for each instance shutdown is logged in file
# $ORACLE_HOME/shutdown.log.
#
# To configure:
# 1) Set ORATAB:
# On Solaris
# ORATAB=/var/opt/oracle/oratab
# All other UNIX platforms
# ORATAB=/etc/oratab
#
# 2) Update $ORATAB/oratab with Database Instances that need to be shutdown.
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME:<N|Y>:
# An example entry:
# main:/usr/lib/oracle/emagent_10g:Y
#
#####################################