Oracle数据库的启动和暂停操作讲解

1. oracle启动的4个状态

首先要知道,oracle数据库的启动过程存在4个状态

shutdown(关闭) –> nomount(启动已实例)–>mount(加载数据库)–>open(打开数据库)

1.1 shutdown状态

第一状态没什么好解释的,oracle的所有文件都静静的躺在磁盘里,一切都还未开始,属于关机状态

1.2 nomount状态

执行动作:

starting the instance (nomount)

reading the initialization file from $oracle_home/dbs in the following order:

-first spfilesid.ora

-if not found then, spfile.ora

-if not found then, initsid.ora

specifying the pfile parameter with startup overrides the default behavior.

allocating the sga

starting the background processes

opening the alertsid.log file and the trace files

the database must be named with the db_name parameter either in the initialization parameter file or in the startup command.

读取环境变量下dbs目录下的参数文件(spfile/pfile)

 [ora10@localhost dbs]$ pwd

/ora10/product/10.2.0/db_1/dbs

[ora10@localhost dbs]$ ll

-rw-r----- 1 ora11 dba  3584 07-19 22:07 spfilesid.ora

-rw-r----- 1 ora11 dba  3584 07-23 22:00 spfile.ora

-rw-r--r-- 1 ora11 dba  1106 07-19 21:47 initsid.ora

查找参数文件的顺序如上面列表的,读取优先级

spfilesid.ora > spfile.ora>initsid.ora

如果三个文件都找不到的话,那么将启动失败。

启动算法,分配内存

启动后台进程

开放alertsid.log文件和跟踪文件

数据库的名字要么是初始化参数文件中指定的名字,要么是startup命令里跟的名字,二选一

结果:

[ora10@localhost dbs]$ sqlplus 

sql*plus: release 10.2.0.1.0 - production on tue jul 24 22:33:54 2012

copyright (c) 1982, 2005, oracle.  all rights reserved.

enter user-name: /as sysdba

connected to an idle instance.

sql> startup nomount;

oracle instance started.

total system global area  205520896 bytes

fixed size                  1218532 bytes

variable size              79693852 bytes 

database buffers          121634816 bytes 

redo buffers                2973696 bytes 

现在就处在一个nomount状态。这种启动模式只会创建实例,并不加载数据库,oracle仅为实例创建各种内存结构和服务进程,不会打开任何数据文件。在nomount模式下,只能访问那些与sga区相关的数据字典视图,包括v$parameter、v$sga、v$process 和 v$session等,这些视图中的信息都是从sga区中获取的,与数据库无关。

模式用途:

(1)创建新数据库;

(2)重建控制文件。

1.3 mount状态

执行动作:

mounting a database includes the following tasks:

associating a database with a previously started instance

locating and opening the control files specified in the parameter file

reading the control files to obtain the names and status of the data files and online redo log files.however,no checks are performed to verify the existence of the data files and online redo log files at this time.

把一个数据库和启动的实例关联起来

在参数文件(spfile/pfile)中找到控制文件进行读取

查看参数文件:

[ora10@localhost dbs]$ strings spfileora10.ora | more 

......

*.control_files='/ora10/product/oradata/ora10/control01.ctl','/ora10/product/ora 

data/ora10/control02.ctl','/ora10/product/oradata/ora10/control03.ctl' 

....... 

控制文件:

[ora10@localhost ~]$ cd /ora10/product/oradata/ora10/ 

[ora10@localhost ora10]$ ll 

总计 954196 

-rw-r----- 1 ora10 dba   7061504 07-23 23:01 control01.ctl 

-rw-r----- 1 ora10 dba   7061504 07-23 23:01 control02.ctl 

-rw-r----- 1 ora10 dba   7061504 07-23 23:01 control03.ctl 

读取控制文件,获得的数据文件和联机重做日志文件,然而,在这个时候没有进行检查以验证存在的数据文件和联机重做日志文件

结果:

[ora10@localhost dbs]$ sqlplus 

sql*plus: release 10.2.0.1.0 - production on tue jul 24 23:02:28 2012 

copyright (c) 1982, 2005, oracle.  all rights reserved. 

enter user-name: /as sysdba 

connected to an idle instance. 

sql> startup mount; 

oracle instance started. 

total system global area  205520896 bytes 

fixed size                  1218532 bytes 

variable size              79693852 bytes 

database buffers          121634816 bytes 

redo buffers                2973696 bytes 

database mounted. 

现在进入了数据库的mount状态,我们通过mount启动的时候,下面会多一句提示“database mounted.” 数据库准备就绪。这种启动模式将为实例加载数据库,但保持数据库为关闭状态。因为加载数据库时需要打开数据库控制文件,但数据文件和重做日志文件都都无法进行读写,所以用户还无法对数据库进行操作。 在mount模式下,只能访问那些与控制文件相关的数据字典视图,包括v$thread、v$controlfile、v$database、v$datafile 和 v$logfile等,这些视图都是从控制文件中获取的。

模式用途:

(1)重命名数据文件;

(2)添加、删除或重命名重做日志文件;

(3)执行数据库完全恢复操作;

(4)改变数据库的归档模式。

1.4 open状态

执行动作:
opening the database includes the following tasks

opening the online data log files

opening the onling redo log files

  if any of the datafiles or noline redo log files are not present when you attempt to open the database ,the oracle server returns an error.

  during this final stage,the oracle server verfies that all the data files and online redo log files can be opened and checks the consistency of the database . if necessary , the smon background process initiates instance recovery.

打开数据库包括下列任务:

打开在线数据日志文件

打开联机重做日志文件

如果任何数据文件或非线性重做日志文件不存在,当您试图打开的数据库,服务器返回错误。 

在这最后阶段,该服务器验证所有数据文件和联机重做日志文件可以打开并检查数据库的一致性。如果需要,该监控进程开始实例恢复。

结果:

[ora10@localhost dbs]$ sqlplus /nolog
  
  sql*plus: release 10.2.0.1.0 - production on wed jul 25 21:50:55 2012
  
  copyright (c) 1982, 2005, oracle.  all rights reserved.
  
  sql> conn /as sysdba
  connected to an idle instance.
  sql> startup
  oracle instance started.
  
  total system global area  205520896 bytes
  fixed size                  1218532 bytes
  variable size              79693852 bytes
  database buffers          121634816 bytes
  redo buffers                2973696 bytes
  database mounted.
  
  database opened.

在上面的命令中,startup后面不加其它信息的话,系统会为我们直接顺序启动,直到第open状态。

模式用途:应用开发和使用。

2. oracle数据库的三中关闭方式

与数据库启动一下,关闭数据库与实例也分为3步:关闭数据库–>实例卸载数据库—>终止实例

2.1 nomal(正常关闭方式)

命令:shutdown nomal

说明:正常方式关闭数据时,oracle执行如下操作:

阻止任何用户建立新的连接。 等待当前所有正在连接的用户主动断开连接(此方式下oracle不会立即断掉当前用户的连接,这些用户仍然操作相关的操作) 一旦所有的用户都断开连接,则立即关闭、卸载数据库,并终止实例。(所以,一般以正常方式关闭数据库时,应该通知所有在线的用户尽快断开连接)

2.2 immediate(立即关闭方式)

命令:shutdown immediate

说明:

阻止任何用户建立新的连接,同时阻止当前连接的用户开始任何新的事务。 oracle不等待在线用户主动断开连接,强制终止用户的当前事务,将任何未提交的事务回退。(如果存在太多未提交的事务,此方式将会耗费很长时间终止和回退事务) 直接关闭、卸载数据库,并终止实例。

2.3 transactional(事务关闭方式)

命令:shutdown transactional

说明:这种方式介于正常关闭方式跟立即关闭方式之间,响应时间会比较快,处理也将比较得当。执行过程如下:

阻止任何用户建立新的连接,同时阻止当前连接的用户开始任何新的事务。

等待所有未提交的活动事务提交完毕,然后立即断开用户的连接。

直接关闭、卸载数据库,并终止实例。

2.4 abort(终止关闭方式)

命令:shutdown abort

说明:这是比较粗暴的一种关闭方式,当前面3种方式都无法关闭时,可以尝试使用终止方式来关闭数据库。但是以这种方式关闭数据库将会丢失一部份数据信息,当重新启动实例并打开数据库时,后台进程smon会执行实例恢复操作。一般情况下,应当尽量避免使用这种方式来关闭数据库。执行过程如下:

阻止任何用户建立新的连接,同时阻止当前连接的用户开始任何新的事务。

立即终止当前正在执行的sql语句。

任何未提交的事务均不被回退。

直接断开所有用户的连接,关闭、卸载数据库,并终止实例。

(0)
上一篇 2022年3月22日
下一篇 2022年3月22日

相关推荐