12 Database and Instance Startup and Shutdown
001 |
This chapter explains the procedures involved in starting and stopping
an Oracle instance and database. |
本章讲述 Oracle 实例及数据库启动与停止的过程。 |
002 | This chapter contains the following topics: | 本章包含以下主题: |
003 |
Introduction to an Oracle Instance |
12.1 Oracle 实例简介 |
004 |
Every running Oracle database is associated with an Oracle instance.
When a database is started on a database server (regardless of the type
of computer), Oracle allocates a memory area called the System Global
Area (SGA) and starts one or more Oracle processes. This combination of
the SGA and the Oracle processes is called an Oracle
instance. The memory and processes of an instance manage the
associated database's data efficiently and serve the one or multiple
users of the database. |
Oracle 数据库在运行期间总存在一个与之对应的实例。当用户在服务器(无论何种计算机)上启动数据库时,Oracle
将为数据库分配被称为系统全局区(System Global Area,SGA)的内存区,并启动一个或多个 Oracle 进程。SGA 与
Oracle 进程被统称为 Oracle
实例。构成实例的内存区及进程负责对数据库数据进行管理,并为多用户提供服务。 |
005 |
Figure 12-1 shows an Oracle
instance. |
图12-1
展示了一个 Oracle 实例。 |
006 |
Figure 12-1 An Oracle
Instance |
图12-1 Oracle 实例 |
007 | ||
008 |
|
图12-1 显示了 SGA 与 Oracle 进程可以进行双向通信。SGA 中包含了数据库缓存区,重做日志缓冲区,及上下文区。 |
009 |
|
|
010 |
The Instance and the Database |
12.1.1 实例与数据库 |
011 |
After starting an instance, Oracle associates the instance with the
specified database. This is a
mounted database. The database is then ready to be opened, which
makes it accessible to authorized users. |
当一个实例启动后,Oracle 将令此实例与指定的数据库共同工作。当数据库与实例关联后被称为已挂载的数据库(mounted
database)。已挂载的数据库可以被打开(open),供授权用户访问。 |
012 |
Multiple instances can run concurrently on the same computer, each
accessing its own physical database. In large-scale cluster systems,
Real Application Clusters enables multiple instances to mount a single
database. |
在同一计算机上可以同时运行多个实例,每个实例和一个与之相关的数据库共同工作。在应用了 RAC 的大型集群系统(cluster
system)中,一个数据库可以挂载到多个实例上。 |
013 |
Only the database administrator can start up an instance and open the
database. If a database is open, then the database administrator can
shut down the database so that it is closed. When a database is
closed, users cannot access the information that it contains. |
只有 DBA 能够执行启动实例及打开数据库的操作。当数据库处于打开状态后,DBA 还能够执行停止(shut
down)操作令数据库进入关闭状态。当数据库处于关闭状态(closed)后,其中的数据不能被继续访问。 |
014 |
Security for database startup and shutdown is controlled through
connections to Oracle with administrator privileges. Normal users do not
have control over the current status of an Oracle database. |
只有以管理员权限连接 Oracle 的用户才能执行启动及停止操作。普通用户不能改变 Oracle 数据库的运行状态。 |
015 |
Connection with Administrator Privileges |
12.1.2 以管理员权限连接数据库 |
016 |
Database startup and shutdown are powerful administrative options and
are restricted to users who connect to Oracle with administrator
privileges. Depending on the operating system, one of the following
conditions establishes administrator privileges for a user:
|
数据库的启动与停止是极为重要的管理性功能,只能由以管理员权限连接数据库的用户使用。依据操作系统的不同,Oracle
将赋予满足以下条件的用户管理员权限:
|
017 |
When you connect with SYSDBA privileges,
you are in the schema owned by SYS. When
you connect as SYSOPER, you are in the
public schema. SYSOPER privileges are a
subset of SYSDBA privileges. |
当用户以 SYSDBA 权限连接数据库时,其所处的方案(schema)由
SYS 用户所拥有。而用户以 SYSOPER
权限连接数据库时将处于 public schema 方案。SYSOPER
权限是 SYSDBA 权限的一个子集。 |
018 |
|
|
019 |
Initialization Parameter Files and Server Parameter Files |
12.1.3 初始化参数文件与服务器参数文件 |
020 |
To start an instance, Oracle must read either an initialization
parameter file or a server parameter file. These files
contain a list of configuration parameters for that instance and
database. Oracle traditionally stored initialization parameters in a
text initialization parameter file. You can also choose to maintain
initialization parameters in a binary server parameter file (SPFILE). |
在启动实例时,Oracle 需要读取初始化参数文件(initialization
parameter file)或服务器参数文件(server parameter file)。这两个文件中包含了一组供实例及数据库使用的配置参数。在较早的版本中,Oracle
将初始化参数存储于文本格式的初始化参数文件中。而在最近的版本中,用户也可以使用二进制格式的服务器参数文件(SPFILE)维护初始化参数。 |
021 |
Initialization parameters stored in a server parameter file are
persistent, in that any changes made to the parameters while an instance
is running can persist across instance shutdown and startup. |
服务器参数文件能够持续地(persistent)存储系统的初始化参数。在实例运行期间对初始化参数所做的修改能够保存到服务器参数文件中,供下次实例启动
时使用。 |
022 |
Initialization parameters are divided into two groups: basic and
advanced. In the majority of cases, it is necessary to set and tune only
the basic parameters to get reasonable performance. In rare situations,
modification to the advanced parameters may be needed for optimal
performance. |
初始化参数可以被分为两部分:基础(basic)参数与高级(advanced)参数。在大多数情况下,用户只需调整基础参数就能保证数据库正常运行。而在极少数情况下,用户还需要对高级参数进行调整才能优化系统性能。 |
023 |
Most initialization parameters belong to one of the following groups:
|
绝大多数初始化参数的作用可以被分为以下三类:
|
024 |
Among other things, the initialization parameters tell Oracle:
|
而其他的初始化参数则用于进行以下设定:
|
025 |
|
另见: |
026 |
How Parameter Values Are Changed |
12.1.3.1 如何修改初始化参数 |
027 |
The database administrator can adjust variable parameters to improve the
performance of a database system. Exactly which parameters most affect a
system depends on numerous database characteristics and variables. |
DBA 可以通过调整变量参数(variable
parameter)的值来提高数据库系统的性能。根据数据库的特性及运行状态,管理员可以修改不同的参数来提高数据库的性能。 |
028 |
Some parameters can be changed dynamically with the
ALTER SESSION or
ALTER SYSTEM statement while the instance is running. Unless you
are using a server parameter file (SPFILE),
changes made using the ALTER SYSTEM
statement are only in effect for the current instance. You must manually
update the text initialization parameter file for the changes to be
known the next time you start up an instance. When you use a
SPFILE, you can update the parameters on
disk, so that changes persist across database shutdown and startup. |
有些初始化参数可以在实例运行时使用
ALTER SESSION 或
ALTER SYSTEM 语句动态地修改。如果没有使用服务器参数文件(server parameter file,SPFILE),使用 ALTER SYSTEM
语句对初始化参数的修改只对当前实例有效。管理员必须手工修改初始化参数文件(initialization parameter
file)才能使这些修改在下次实例启动时仍旧有效。而在使用了 SPFILE
后,管理员能够将修改的参数保存在磁盘上,这样修改在实例重启后依然有效。 |
029 |
Oracle provides values in the starter initialization parameter file
provided with your database software, or as created for you by the
Database Configuration Assistant. You can edit these Oracle-supplied
initialization parameters and add others, depending upon your
configuration and options and how you plan to tune the database. For any
relevant initialization parameters not specifically included in the
initialization parameter file, Oracle supplies defaults. If you are
creating an Oracle database for the first time, it is suggested that you
minimize the number of parameter values that you alter. |
Oracle 随数据库软件提供了一个预设的初始化参数文件,用户也可以使用 DBCA(Database Configuration
Assistant)自动创建一个初始化参数文件。用户可以在这些自动生成的初始化参数文件的基础上,根据自身系统的配置,安装选项,及调优目标修改或添加参数。在实例启动时,Oracle
将为没有在初始化参数文件中进行设定的参数赋予默认值。当数据库第一次被创建时,Oracle 建议用户尽可能不修改初始化参数。 |
030 |
|
|
031 |
Overview of Instance and Database Startup |
12.2 实例与数据库启动概述 |
032 |
The three steps to starting an Oracle database and making it available
for systemwide use are:
|
启动 Oracle 数据库并使其可以为所有用户提供服务的三个步骤如下:
|
033 |
A database administrator can perform these steps using the SQL*Plus
STARTUP statement or Enterprise Manager. |
DBA 可以使用 SQL*Plus 的
STARTUP 语句或企业管理器(Enterprise
Manager)来执行这三个步骤。 |
034 |
|
另见: |
035 |
How an Instance Is Started |
12.2.1 实例是如何启动的 |
036 |
When Oracle starts an instance, it reads the server parameter file (SPFILE)
or initialization parameter file to determine the values of
initialization parameters. Then, it allocates an SGA, which is a shared
area of memory used for database information, and creates background
processes. At this point, no database is associated with these memory
structures and processes. |
当 Oracle 启动实例时,首先需要从服务器参数文件(server parameter
file)或初始化参数文件(initialization parameter file)中读取初始化参数,之后创建存储数据库信息的共享内存区
SGA,最后创建后台进程(background process)。此时,构成实例的内存区及进程还没有和数据库产生联系。 |
037 |
|
|
038 |
Restricted Mode of Instance Startup |
12.2.1.1 以限制模式启动实例 |
039 |
You can start an instance in restricted mode (or later alter an existing
instance to be in restricted mode). This restricts connections to only
those users who have been granted the RESTRICTED
SESSION system privilege. |
管理员可以使实例以限制模式(restricted mode)启动,也可以将当前运行的实例切换到限制模式。运行在限制模式下的实例只允许具有 RESTRICTED
SESSION 系统权限的用户连接到数据库。 |
040 |
Forced Startup in Abnormal Situations |
12.2.1.2 在异常情况下强制启动 |
041 |
In unusual circumstances, a previous instance might not have been shut
down cleanly. For example, one of the instance's processes might not
have terminated properly. In such situations, the database can return an
error during normal instance startup. To resolve this problem, you must
terminate all remnant Oracle processes of the previous instance before
starting the new instance. |
在某些特殊情况下,一个实例也许不能被正常停止。例如,实例的某些进程没有正常结束。此时,如果用户按正常程序启动实例,数据库将返回错误。管理员需要在启动实例前手工结束系统中残留的
Oracle 进程才能解决这个问题。 |
042 |
How a Database Is Mounted |
12.2.2 数据库是如何挂载的 |
043 |
The instance mounts a database to associate the database with that
instance. To mount the database, the instance finds the database control
files and opens them. Control files are specified in the
CONTROL_FILES initialization parameter in
the parameter file used to start the instance. Oracle then reads the
control files to get the names of the database's datafiles and redo log
files. |
Oracle 将数据库挂载(mount)到实例,以便实例和数据库共同工作。在挂载数据库时,实例首先需要找到并打开数据库控制文件(control
file)。控制文件的名称及位置信息记录在参数文件的
CONTROL_FILES 参数中。接着 Oracle
将读取控制文件获取数据库的数据文件(datafile)名及重做日志文件(redo log file)名。 |
044 |
At this point, the database is still closed and is accessible only to
the database administrator. The database administrator can keep the
database closed while completing specific maintenance operations.
However, the database is not yet available for normal operations. |
此时,数据库还没有被打开,只有 DBA 才能访问数据库。当数据库处于挂载状态时,管理员可以进行维护性的操作。此时数据库的常规操作都是被禁止的。 |
045 |
How a Database Is Mounted with Real Application Clusters |
12.2.2.1 RAC 系统中的数据库是如何挂载的 |
046 |
If Oracle allows multiple instances to mount the same database
concurrently, then the database administrator can use the
CLUSTER_DATABASE initialization parameter
to make the database available to multiple instances. The default value
of the CLUSTER_DATABASE parameter is
false. Versions of Oracle that do not
support Real Application Clusters only allow
CLUSTER_DATABASE to be false. |
某些版本的 Oracle 允许多个实例同时挂载(mount)同一个数据库,DBA 需要使用
CLUSTER_DATABASE 初始化参数来开启此项功能。此参数的默认值为
false。而在较早版本的不支持 RAC 的 Oracle 中,此参数只能被设为
false。 |
047 |
If CLUSTER_DATABASE is
false for the first instance that
mounts a database, then only that instance can mount the database.
If CLUSTER_DATABASE is set to
true on the first instance, then other
instances can mount the database if their
CLUSTER_DATABASE parameters are set to
true. The number of instances that can mount the database is
subject to a predetermined maximum, which you can specify when
creating the database. |
如果第一个挂载某数据库的实例的 CLUSTER_DATABASE 参数为
false,那么只有此实例才能够挂载这个数据库。而当第一个挂载数据库的实例的
CLUSTER_DATABASE 参数为 true 时,其它
CLUSTER_DATABASE 参数为 true
的实例也可以挂载同一个数据库。挂载同一数据库的实例的数量受一个预设的最大值限制,此值是在创建数据库时设定的。 |
048 |
|
|
049 |
How a Standby Database Is Mounted |
12.2.2.2 备用数据库是如何挂载的 |
050 |
A
standby database maintains a duplicate copy of your primary database
and provides continued availability in the event of a disaster. |
备用数据库(standby database)是一个与主数据库(primary
database)完全相同的副本,她能在发生灾难时保证系统的持续可用性(availability)。 |
051 |
The standby database is constantly in recovery mode. To maintain your
standby database, you must mount it in standby mode using the
ALTER DATABASE statement and apply the
archived redo logs that your primary database generates. |
备用数据库永远处于恢复模式(recovery mode)。为了构造一个备份数据库,管理与必须使用
ALTER DATABASE 语句使一个数据库以备份模式(standby
mode)挂载,并将主数据库中产生的归档重做日志(archived redo log)加载到此数据库中。 |
052 |
You can open a standby database in read-only mode to use it as a
temporary reporting database. You cannot open a standby database in
read/write mode. |
用户可以将一个备份数据库以只读模式(read-only
mode)打开,作为临时的报表查询数据库。备份数据库不能以可读写状态(read/write mode)打开。 |
053 |
|
|
054 |
How a Clone Database Is Mounted |
12.2.2.3 克隆数据库是如何挂载的 |
055 |
A clone database is a specialized copy of a database that can be
used for tablespace point-in-time recovery. When you perform tablespace
point-in-time recovery, you mount the clone database and recover the
tablespaces to the desired time, then export metadata from the clone to
the primary database and copy the datafiles from the recovered
tablespaces. |
克隆数据库(clone database)是专供按时间点恢复(point-in-time
recovery)表空间功能使用的数据库副本。当用户按时间点恢复表空间时,需要将克隆数据库挂载(mount)并将其中的表空间恢复到期望的时间,之后将克隆数据库中被恢复的表空间的元数据及数据文件复制到主数据库(primary
database)。 |
056 |
|
另见: |
057 |
What Happens When You Open a Database |
12.2.3 数据库是如何打开的 |
058 |
Opening a
mounted database makes it available for normal database operations.
Any valid user can connect to an open database and access its
information. Usually, a database administrator opens the database to
make it available for general use. |
将已挂载数据库(mounted
database)打开(open)就可以使此数据库正常工作。任何有效的用户都可以连接到一个打开的数据库并访问其中的信息。通常数据库是处于打开状态的,以便为用户提供服务。 |
059 |
When you open the database, Oracle opens the online datafiles and redo
log files. If a tablespace was offline when the database was previously
shut down, the tablespace and its corresponding datafiles will still be
offline when you reopen the database. |
当管理员打开数据库时,Oracle 将打开所有联机的数据文件(datafile)及重做日志文件(redo log
file)。如果数据库上次停止时某个表空间处于脱机状态,那么打开数据库时此表空间及相关的数据文件将依旧处于脱机状态。 |
060 |
If any of the datafiles or redo log files are not present when you
attempt to open the database, then Oracle returns an error. You must
perform recovery on a backup of any damaged or missing files before you
can open the database. |
如果 Oracle
在打开数据库时找不到所需的数据文件或重做日志文件,系统将返回错误信息。管理员必须从备份中恢复损坏或缺失的文件后,才能打开数据库。 |
061 |
|
另见 |
062 |
Instance Recovery |
12.2.3.1 实例恢复 |
063 |
If the database was last closed abnormally, either because the database
administrator terminated its instance or because of a power failure,
then Oracle automatically performs recovery when the database is
reopened. |
如果数据库上次关闭时发生了异常情况(DBA 终止了数据库实例或出现电源故障),Oracle 将在数据库再次打开时自动地执行恢复操作。 |
064 |
Undo Space Acquisition and Management |
12.2.3.2 撤销空间的获取与管理 |
065 |
When you open the database, the instance attempts to acquire one or more
undo tablespaces. You determine whether to operate in automatic undo
management mode or manual undo management mode at instance startup using
the UNDO_MANAGEMENT initialization
parameter. The supported values are AUTO or
MANUAL. If AUTO,
then the instance is started in automatic undo management mode. The
default value is MANUAL.
|
当 DBA 打开数据库时,实例将请求一个或多个撤销表空间(undo tablespace)。管理员在实例启动时通过 UNDO_MANAGEMENT
初始化参数决定数据库运行于自动撤销管理模式(automatic undo management mode)或手工撤销管理模式(manual
undo management mode)。可选的参数值为 AUTO 或
MANUAL。当此值为 AUTO
时,实例将运行在自动撤销管理模式下。此参数的默认值为 MANUAL。
|
066 |
|
另见: |
067 |
Resolution of In-Doubt Distributed Transaction |
12.2.3.3 消除不可信的分布式事务 |
068 |
Occasionally a database closes abnormally with one or more distributed
transactions in doubt (neither committed nor rolled back). When
you reopen the database and recovery is complete, the RECO background
process automatically, immediately, and consistently resolves any
in-doubt distributed transactions. |
当数据库发生异常关闭时,可能会遗留下一些不可信的分布式事务(In-Doubt Distributed
Transaction)(既未提交也未回滚的分布式事务)。当管理员重新打开数据库并完成恢复工作后,RECO
后台进程将自动地处理不可信的分布式事务,以保证数据库的完整性。 |
069 |
|
另见: |
070 |
Open a Database in Read-Only Mode |
12.2.3.4 以只读模式打开数据库 |
071 |
You can open any database in read-only mode to prevent its data from
being modified by user transactions. Read-only mode restricts database
access to read-only transactions, which cannot write to the datafiles or
to the redo log files. |
DBA 能够以只读模式(read-only
mode)打开数据库,防止数据被用户事务修改。在只读模式下,只有只读事务才能访问数据库,只读事务不能向数据文件(datafile)及重做日志文件(redo
log file)写入信息。 |
072 |
Disk writes to other files, such as control files, operating system
audit trails, trace files, and alert logs, can continue in read-only
mode. Temporary tablespaces for sort operations are not affected by the
database being open in read-only mode. However, you cannot take
permanent tablespaces offline while a database is open in read-only
mode. Also, job queues are not available in read-only mode. |
在只读模式下,其他文件(例如控制文件(control file),操作系统监控文件(audit trail),跟踪文件(trace
file)及告警日志(alert log))依然可以被写入。用于进行排序操作的临时表空间(temporary
tablespace)在只读模式下依然可用。但是用户不能在只读模式下将永久表空间(permanent
tablespace)脱机。作业队列(job queue)在只读模式下无法使用。 |
073 |
Read-only mode does not restrict database recovery or operations that
change the database's state without generating redo data. For example,
in read-only mode:
|
在只读模式下,依旧可以执行数据库恢复,也可以执行改变数据库状态的操作(只要此类操作不产生重做(redo)数据即可)。例如,在只读模式下:
|
074 |
|
另见: |
075 |
Overview of Database and Instance Shutdown |
12.3 实例与数据库停止概述 |
076 |
The three steps to shutting down a database and its associated instance
are:
|
关闭一个数据库及相关实例的三个步骤如下:
|
077 |
A database administrator can perform these steps using Enterprise
Manager. Oracle automatically performs all three steps whenever an
instance is shut down. |
DBA 能够在企业管理器(Enterprise Manager)中执行以上操作,Oracle 也能够在实例停止时自动地执行以上步骤。 |
078 |
|
另见: |
079 |
Close a Database |
12.3.1 关闭数据库 |
080 |
When you close a database, Oracle writes all database data and recovery
data in the SGA to the datafiles and redo log files, respectively. Next,
Oracle closes all online datafiles and redo log files. (Any offline
datafiles of any offline tablespaces have been closed already. If you
subsequently reopen the database, any tablespace that was offline and
its datafiles remain offline and closed, respectively.) At this point,
the database is closed and inaccessible for normal operations. The
control files remain open after a database is closed but still mounted. |
当 DBA 关闭数据库时,Oracle 将 SGA 内的数据库数据及恢复数据分别写入数据文件(datafile)及重做日志文件(redo log
file)。之后,Oracle
关闭所有联机的数据文件及重做日志文件。(脱机表空间的脱机数据文件已经处于关闭状态。当用户再次打开数据库时,脱机的表空间及其中的数据文件将保持脱机状态。)此时数据库已经处于关闭状态,不能执行一般操作。在数据库已经关闭但仍旧挂载时,控制文件(control
file)还是处于打开状态。 |
081 |
Close the Database by Terminating the Instance |
12.3.1.1 通过终止实例来关闭数据库 |
082 |
In rare emergency situations, you can terminate the instance of an open
database to close and completely shut down the database instantaneously.
This process is fast, because the operation of writing all data in the
buffers of the SGA to the datafiles and redo log files is skipped. The
subsequent reopening of the database requires recovery, which Oracle
performs automatically. |
在紧急情况下,DBA
可以终止一个处于打开(open)状态的数据库的实例,以便立即关闭(close)并完全停止(shutdown)一个数据库。这个过程很快,因为将
SGA 内各缓冲区的数据写入磁盘的步骤被省略了。数据库重新打开的时候 Oracle 将自动地执行恢复操作。 |
083 |
|
提示: |
084 |
Unmount a Database |
12.3.2 卸载数据库 |
085 |
After the database is closed, Oracle unmounts the database to
disassociate it from the instance. At this point, the instance remains
in the memory of your computer. |
当数据库被关闭(close)后,Oracle 将卸载数据库,使之与实例分离。此时,实例依旧存在于计算机的内存中。 |
086 |
After a database is unmounted, Oracle closes the control files of the
database. |
数据库被卸载后,Oracle 将关闭数据库的控制文件(control file)。 |
087 |
Shut Down an Instance |
12.3.3 停止实例 |
088 |
The final step in database shutdown is shutting down the instance. When
you shut down an instance, the SGA is removed from memory and the
background processes are terminated. |
停止(shutdown)数据库的最后一个步骤是停止实例。当 DBA 停止实例时,SGA 将被从内存中清除,后台进程将被终止。 |
089 |
Abnormal Instance Shutdown |
12.3.3.1 关闭异常的实例 |
090 |
In unusual circumstances, shutdown of an instance might not occur
cleanly; all memory structures might not be removed from memory or one
of the background processes might not be terminated. When remnants of a
previous instance exist, a subsequent instance startup most likely will
fail. In such situations, the database administrator can force the new
instance to start up by first removing the remnants of the previous
instance and then starting a new instance, or by issuing a
SHUTDOWN ABORT statement in SQL*Plus or
using Enterprise Manager. |
在异常情况下,可能出现实例停止(shutdown)不完全的情况:内存中可能依然存在未被清除的内存结构,或者某些后台进程未被终止。如果系统中存在未完全清除的实例,此实例再次启动时将会出错。在此种情况下,DBA
可以采用两种方法强制启动实例,第一种方法是彻底清除之前的实例并启动新实例,第二种方法是在 SQL*Plus 或企业管理器(Enterprise
Manager)中执行
SHUTDOWN ABORT 语句。 |
091 |
|
另见: |
[007] context |
[011] mounted database [076] Unmount |
[004] instance [011] mounted database [018] Database Security [050] standby database [058] mounted database |
1、为什么要特别提到 temporary tablespace? [072] Temporary tablespaces for sort operations are not affected by the database being open in read-only mode. |