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

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

  2. Reads the parameter file to determine the values of initialization parameters

  3. Allocates the SGA based on the initialization parameter settings

  4. Starts the Oracle background processes

  5. Opens the alert log and trace files and writes all explicit parameter settings to the alert log 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 mounted database, 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 "Online and Offline Tablespaces"), 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 

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

After the database is closed, Oracle Database unmounts the database to disassociate it from the instance. After a database is unmounted, Oracle Database closes the control files of the database. At this point, the instance remains in memory.

3) 实例被shutdown

实例被shutdown。

The final step in database shutdown is shutting down the instance. When the database instance is shut down, the SGA is removed from memory and the background processes are terminated.

数据库关闭的4种模式:ABORT、IMMEDIATE、TRANSACTIONAL、NORMAL。下面的表格介绍了各模式下数据库的行为。

Database Behavior ABORT IMMEDIATE TRANSACTIONAL NORMAL

Permits new user connections

No

No

No

No

Waits until current sessions end

No

No

No

Yes

Waits until current transactions end

No

No

Yes

Yes

Performs a checkpoint and closes open files

No

Yes

Yes

Yes

  • SHUTDOWN ABORT

    This mode is intended for emergency situations, such as when no other form of shutdown is successful. This mode of shutdown is the fastest. However, a subsequent open of this database may take substantially longer because instance recovery must be performed to make the data files consistent.

    Note:

    Because SHUTDOWN ABORT does not checkpoint the open data files, instance recovery is necessary before the database can reopen. The other shutdown modes do not require instance recovery before the database can reopen.

  • SHUTDOWN IMMEDIATE

    This mode is typically the fastest next to SHUTDOWN ABORT. Oracle Database terminates any executing SQL statements and disconnects users. Active transactions are terminated and uncommitted changes are rolled back.

  • SHUTDOWN TRANSACTIONAL

    This mode prevents users from starting new transactions, but waits for all current transactions to complete before shutting down. This mode can take a significant amount of time depending on the nature of the current transactions.

  • SHUTDOWN NORMAL

    This is the default mode of shutdown. The database waits for all connected users to disconnect before shutting down.

下面通过实例演示Oracle数据库的启动和关闭过程,例子中Oracle版本为11.2.0.1

1、启动数据库

当前没有任何进程和共享内存,设置好ORACLE_SID和ORACLE_HOME环境变量

wKioL1k2Iy_i7XdTAABhzv-QedM368.png

执行sqlplus / as sysdba连接到一个空实例,当前仍然没有共享内存,只增加了一个进程oracletest的进程

wKioL1k2JHzhyUjNAACUtajgHQg387.png

使用startup nomount启动数据库实例,该命令默认查找spfile参数文件启动实例,也可以使用startup nomount pfile='/dir/init.ora'指定参数文件启动,在内存中分配共享内存并创建后台进程。

wKiom1k2JQvAF1oHAAFq9fQ2gpg197.png查看当前的实例状态,当前状态只能查少量的视图如v$instance,但大部分视图无法查询如v$database、v$datafile,会报错:ORA-01507: database not mounted

wKioL1k2JZWCYeKVAAALJrstLrQ617.png

使用alter database mount命令mount数据库,这种状态只能查询部分视图,dba开头的大部分视图都不能查询会报错:ORA-01219: database not open: queries allowed on fixed tables/views only

wKioL1k2JweyHmYiAAASvmHKVqM040.png

使用alter database open命令open数据库:

wKiom1k2J6HRhIoaAAASjy3GSvQ237.png

当前数据库被打开,可以对外提供服务。

2、关闭数据库

wKiom1k2KguiXb18AACG-73jtUw232.png整个启动和关闭的过程都会记录在alert日志文件中。11g的alert日志目录是$ORACLE_BASE/diag/rdbms/dbname/sid/trace。文件名为alert_sid.log。


参考:http://docs.oracle.com/cd/E11882_01/server.112/e40540/startup.htm#CNCPT89043

《9I10G11G编程艺术  深入数据库体系结构 》


      本文转自hbxztc 51CTO博客,原文链接:http://blog.51cto.com/hbxztc/1932703,如需转载请自行联系原作者





相关文章
|
2月前
|
存储 Oracle 关系型数据库
服务器数据恢复—光纤存储上oracle数据库数据恢复案例
一台光纤服务器存储上有16块FC硬盘,上层部署了Oracle数据库。服务器存储前面板2个硬盘指示灯显示异常,存储映射到linux操作系统上的卷挂载不上,业务中断。 通过storage manager查看存储状态,发现逻辑卷状态失败。再查看物理磁盘状态,发现其中一块盘报告“警告”,硬盘指示灯显示异常的2块盘报告“失败”。 将当前存储的完整日志状态备份下来,解析备份出来的存储日志并获得了关于逻辑卷结构的部分信息。
|
2月前
|
存储 Oracle 关系型数据库
【赵渝强老师】Oracle RMAN的目录数据库
Oracle RMAN默认将备份元信息存储在控制文件中,但控制文件损坏或丢失会导致恢复失败,且备份增多会使控制文件无限增长。为解决这些问题,Oracle引入了RMAN目录数据库(Catalog Database),专门用于存储RMAN备份的元信息。使用目录数据库可提升备份管理效率,支持多数据库共享、长期备份历史记录存储,并可保存RMAN脚本。本文详细介绍了如何创建目录数据库、注册目标数据库及其操作步骤。
|
5月前
|
Oracle 安全 关系型数据库
【Oracle】使用Navicat Premium连接Oracle数据库两种方法
以上就是两种使用Navicat Premium连接Oracle数据库的方法介绍,希望对你有所帮助!
1095 28
|
3月前
|
存储 Oracle 关系型数据库
oracle数据恢复—oracle数据库执行错误truncate命令的数据恢复案例
oracle数据库误执行truncate命令导致数据丢失是一种常见情况。通常情况下,oracle数据库误操作删除数据只需要通过备份恢复数据即可。也会碰到一些特殊情况,例如数据库备份无法使用或者还原报错等。下面和大家分享一例oracle数据库误执行truncate命令导致数据丢失的数据库数据恢复过程。
|
5月前
|
SQL Oracle 关系型数据库
【赵渝强老师】Oracle的闪回数据库
Oracle闪回数据库功能类似于“倒带按钮”,可快速将数据库恢复至 earlier 状态,无需还原备份。本文介绍了闪回数据库的使用方法及实战案例:包括设置归档模式、开启闪回功能、记录SCN号、执行误操作后的恢复步骤等。通过具体 SQL 操作演示了如何利用闪回数据库恢复被误删的用户数据。注意,使用此功能前需确保数据库为归档模式。
159 9
|
6月前
|
Oracle 关系型数据库 数据库
【赵渝强老师】Oracle数据库的闪回表
本文介绍了Oracle数据库中的闪回表(Flashback Table)功能,它能够将表的数据快速恢复到特定时间点或系统改变号(SCN),无需备份。文章通过实战示例详细演示了如何使用闪回表恢复数据,包括授权、创建测试表、记录时间与SCN号、删除数据、启用行移动功能、执行闪回操作以及验证恢复结果等步骤。同时,还展示了如何通过触发器禁止插入操作,并在闪回过程中处理触发器的启用问题。文末附有视频讲解,帮助读者更好地理解闪回表的使用方法。
228 10
|
监控 Oracle 关系型数据库
"深度剖析:Oracle SGA大小调整策略——从组件解析到动态优化,打造高效数据库性能"
【8月更文挑战第9天】在Oracle数据库性能优化中,系统全局区(SGA)的大小调整至关重要。SGA作为一组共享内存区域,直接影响数据库处理能力和响应速度。本文通过问答形式介绍SGA调整策略:包括SGA的组成(如数据缓冲区、共享池等),如何根据负载与物理内存确定初始大小,手动调整SGA的方法(如使用`ALTER SYSTEM`命令),以及利用自动内存管理(AMM)特性实现智能调整。调整过程中需注意监控与测试,确保稳定性和性能。
863 2
|
存储 缓存 Oracle
Oracle数据库可扩展性和性能
【7月更文挑战第6天】
271 7

热门文章

最新文章

推荐镜像

更多