Oracle数据库启动和关闭

要了解Oracle数据库的启动和停止需要先了解“实例”(instance)和“数据库”(database)这两个名词的定义:

数据库(database):物理操作系统文件或磁盘(disk)的集合。

实例(instance):一组Oracle后台进程/线程以及一个共享内存区,这些内存由同一个计算机上运行的线程/进程所共享。

这两个词有时可以互换使用,不过二者的概念完全不同。实例和数据库之间的关系是:数据库可以由多个实例mount和open,而实例可以在任何时间点mount和open一个数据库。

Oracle System Identifier (SID)

SID是Oracle实例在服务器上的唯一名字,在UNIX和Linux机器上,Oracle用SID和Oracle home值来创建共享内存的键值,即SID和Oracle home指定一个实例,SID也是用来定位参数文件。

有了对以上概念的认识,下面来看Oracle数据库的启动和关闭过程。

1、Oracle实例和数据库的启动

启动Oracle数据库的方式有很多种,最简单的启动Oracle数据库的方式是就是使用sqlplus执行startup命令。

先来看官方给的图:

wKiom1k2EjjBE2OeAAAj0AwZ-Z4125.gif

从上图可以看出库Oracle从shutdown状态到open状态经历以下阶段:

1) 启动实例,不mount数据库

实例被启动,但还没关联数据库,对应的命令是startup nomount

Searches for a  in a platform-specific default location and, if not found, for a text  (specifying STARTUP with the SPFILE or PFILE parameters overrides the default behavior)

Reads the parameter file to determine the values of initialization parameters

Allocates the SGA based on the initialization parameter settings

Starts the Oracle background processes

Opens the  and trace files and writes all explicit parameter settings to the  in valid parameter syntax

2) 数据库被mount

实例被启动,打开数据库的控制文件关联一个数据库。数据库对用户还是close状态。对就的命令是alter database mount;

To mount the database, the instance obtains the names of the database control files specified in the CONTROL_FILES initialization parameter and opens the files. Oracle Database reads the control files to find the names of the data files and the online redo log files that it will attempt to access when opening the database.

In a , the database is closed and accessible only to database administrators. Administrators can keep the database closed while completing specific maintenance operations. However, the database is not available for normal operations.

3) 数据库被open

实例被启动,关联的数据库被open。数据库中的数据可以被用户访问。对应的命令是alter database open。

Opens the online data files in tablespaces other than undo tablespaces

If a tablespace was offline when the database was previously shut down (see ), then the tablespace and its corresponding data files will be offline when the database reopens.

Acquires an undo tablespace

If multiple undo tablespaces exists, then the UNDO_TABLESPACE initialization parameter designates the undo tablespace to use. If this parameter is not set, then the first available undo tablespace is chosen.

Opens the online redo log files

2、Oracle实例和数据库的关闭

通常关闭Oracle数据库使用sqlplus执行shutdown命令

再看官方给的图:

wKiom1k2HTTQzWUzAAAmi26t8tA952.gif

从上图中也可以看出从数据库open状态到shutdown状态也经历三个阶段:

1) 数据库被关闭

数据库还是mount状态,但在线数据文件和日志文件被关闭了。

The database close operation is implicit in a database shutdown. The nature of the operation depends on whether the database shutdown is normal or abnormal.

When a database is closed as part of a SHUTDOWN with any option other than ABORT, Oracle Database writes data in the SGA to the data files and online redo log files. Next, the database closes online data files and online redo log files. Any offline data files of offline tablespaces have been closed already. When the database reopens, any tablespace that was offline remains offline.

At this stage, the database is closed and inaccessible for normal operations. The control files remain open after a database is closed.

If a SHUTDOWN ABORT or abnormal termination occurs, then the instance of an open database closes and shuts down the database instantaneously. Oracle Database does not write data in the buffers of the SGA to the data files and redo log files. The subsequent reopening of the database requires instance recovery, which Oracle Database performs automatically.

2) 数据库被umount 

实例是启动的,但不再通过控制文件关联数据库。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/500f5bcbd0a79ae80c13eff33d65396e.html