---
title: " 从Alert_Log看Oracle数据库启动三阶段"
author: "paynexss"
date: "2016-12-14T09:16:47Z"
tags: ["Oracle"]
categories: ["数据库"]
slug: "alert-log-oracle"
draft: false
lastmod: "2016-12-14T09:20:32Z"
id: 2344781
url: "https://paynexss.iteye.com/blog/2344781"
---

[**Oracle**](http://lib.csdn.net/base/oracle "Oracle知识库")[**数据库**](http://lib.csdn.net/base/mysql "MySQL知识库")[启动是分为三个不同的阶段的，分别为](http://space.itpub.net/17203031/viewspace-691806)[**nomount**](http://blog.csdn.net/tongyu2009/article/details/8174369)[、](http://space.itpub.net/17203031/viewspace-691806)[**mount**](http://blog.csdn.net/tongyu2009/article/details/8174369)[和](http://space.itpub.net/17203031/viewspace-691806)[**open**](http://blog.csdn.net/tongyu2009/article/details/8174369)[。在不同的阶段，Oracle进行不同的行为，执行不同的操作。在笔者《Oracle启动三阶段》（http://space.itpub](http://space.itpub.net/17203031/viewspace-691806)[.NET](http://lib.csdn.net/base/dotnet ".NET知识库")/17203031/viewspace-684503）系列中，已经进行一定程度的说明。本篇打算从[**Alert\_log**](http://blog.csdn.net/tongyu2009/article/details/8174369)[，也就是数据库自身的日志中，分析启动三阶段的不同行为和操作。](http://space.itpub.net/17203031/viewspace-691806)

 

Alert\_log是Oracle数据库运行阶段的运行日志。在Oracle工作时，会将所有会影响到整体性能的操作、变化和错误信息记录在一个日志中，就是Alert\_log。在Oracle[**11g**](http://blog.csdn.net/tongyu2009/article/details/8174369)[中，提供了文本文件和](http://space.itpub.net/17203031/viewspace-691806)[**XML**](http://blog.csdn.net/tongyu2009/article/details/8174369)[格式文件两种日志格式。对我们来说，Alert\_Log是进行数据库故障诊断、监控和调整的重要研究对象。](http://space.itpub.net/17203031/viewspace-691806)

 

环境准备

 

采用Oracle11gR2 For [Linux](http://lib.csdn.net/base/linux "Linux知识库")版本进行研究，具体过程如下。

Last login: Sun Apr 3 10:51:03 2011

\[root@oracle11g~]# ps -ef | grep ora //当前后台没有与oracle相关的进程；

root     5514 5481 0 08:28 pts/0   00:00:00 grep ora

 

\[root@oracle11g~]# su - oracle

\[oracle@oracle11g~]$ env | grep ORACLE//启动所必需使用的环境变量；

ORACLE\_SID=wilson

ORACLE\_BASE=/u01

ORACLE\_HOME=/u01/oracle

 

启动阶段操作

 

分阶段进行启动操作，之后我们查看效果。

1、 nomount阶段

 

\[oracle@oracle11g~]$ sqlplus /nolog

 

SQL\*Plus: Release11.2.0.1.0 Production on Tue Apr 5 08:31:25 2011

 

Copyright (c) 1982, 2009, Oracle. All rights reserved.

 

SQL&gt; conn / as sysdba;

Connected to an idle instance. //当前实例未启动

 

SQL&gt; startup nomount

ORACLE instance started.//实例启动，共享内容空间分配！

 

Total System Global Area 414298112 bytes

Fixed Size                 1336904 bytes

Variable Size            310380984 bytes

Database Buffers          96468992 bytes

Redo Buffers               6111232 bytes

 

 

此时，我们观察后台活动进程情况，可以看到。

  

\[oracle@oracle11g~]$ ps -ef | grep ora    

oracle   5594    1 0 08:32 ?       00:00:00 ora\_pmon\_wilson

oracle   5596    1 0 08:32 ?       00:00:00 ora\_vktm\_wilson

oracle   5600    1 0 08:32 ?       00:00:00 ora\_gen0\_wilson

oracle   5602    1 0 08:32 ?       00:00:00 ora\_diag\_wilson

oracle   5604    1 0 08:32 ?       00:00:00 ora\_dbrm\_wilson

oracle   5606    1 0 08:32 ?       00:00:00 ora\_psp0\_wilson

oracle   5608    1 0 08:32 ?       00:00:00 ora\_dia0\_wilson

oracle   5610    1 2 08:32 ?       00:00:00 ora\_mman\_wilson

oracle   5612    1 0 08:32 ?       00:00:00 ora\_dbw0\_wilson

oracle   5614    1 0 08:32 ?       00:00:00 ora\_lgwr\_wilson

oracle   5616    1 0 08:32 ?       00:00:00 ora\_ckpt\_wilson

oracle   5618    1 0 08:32 ?       00:00:00 ora\_smon\_wilson

oracle   5620    1 0 08:32 ?       00:00:00 ora\_reco\_wilson

oracle   5622    1 0 08:32 ?       00:00:00 ora\_mmon\_wilson

oracle   5624    1 0 08:32 ?       00:00:00 ora\_mmnl\_wilson

oracle   5626    1 0 08:32 ?       00:00:00 ora\_d000\_wilson

oracle   5628    1 0 08:32 ?       00:00:00 ora\_s000\_wilson

oracle   5630    1 0 08:32 ?       00:00:00 ora\_s001\_wilson

oracle   5632 5547 1 08:32 ?       00:00:00 oraclewilson (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))

 

 

在nomount状态，虽然没有涉及到数据文件读取、控制文件读取等内容。但是最重要的数据库实例已经建立。核心后台进程PMON、DBWn、LGWr、SMON和CKPT已经建立，共享内存SGA区已经分配。

 

2、 Mount状态

 

进入mount状态

  

SQL&gt; alter database mount;

 

Database altered. 

3、 Open

 

进入Open状态 

SQL&gt; alter database open;

 

Database altered.

 

SQL&gt; select count(\*) from scott.emp;

 

 COUNT(\*)

\----------

       14

 

日志分析

 

根据系统参数可以获取到alert\_log的路径，文件名默认为alert\_&lt;sid&gt;.log，其中sid为数据库的唯一标志。在[**实验**](http://blog.csdn.net/tongyu2009/article/details/8174369)[环境中，数据库名称alert\_wilson.log。](http://space.itpub.net/17203031/viewspace-691806)

  

SQL&gt; show parameter dump\_dest;

 

NAME                                TYPE       VALUE

\------------------------------------ ----------- ------------------------------

background\_dump\_dest                string     /u01/diag/rdbms/wilson/wilson/

                                                trace

core\_dump\_dest                      string     /u01/diag/rdbms/wilson/wilson/

                                                cdump

user\_dump\_dest                      string     /u01/diag/rdbms/wilson/wilson/

                                                trace

 

\[oracle@oracle11g~]$ date

Tue Apr 5 08:37:40 CST 2011

 

 

根据时间间隔进行整理日志，我们看到三个阶段数据库操作情况。

 

1、 nomount阶段

 

nomount阶段进行的主要是Oracle实例的构建，共享内存的开启，以及初始化参数的读取定位。下面为日志相关部分片段。

  

Tue Apr 05 08:32:27 2011

Starting ORACLE instance (normal)

LICENSE\_MAX\_SESSION = 0

LICENSE\_SESSIONS\_WARNING = 0

Picked latch-free SCN scheme 2

Using LOG\_ARCHIVE\_DEST\_1 parameter default value as USE\_DB\_RECOVERY\_FILE\_DEST

Autotune of undo retention is turned on.

IMODE=BR

ILAT =27

LICENSE\_MAX\_USERS = 0

SYS auditing is disabled

Starting up:

Oracle Database11gEnterpriseEdition Release11.2.0.1.0 - Production

With the Partitioning, OLAP, [**Data**](http://blog.csdn.net/tongyu2009/article/details/8174369) [Mining and Real Application Testing options.](http://space.itpub.net/17203031/viewspace-691806)

Using parameter settings in server-side spfile /u01/oracle/dbs/spfilewilson.ora

System parameters with non-default values:

 processes               = 150

 memory\_target           =396M

 control\_files           = "/u01/oradata/WILSON/controlfile/o1\_mf\_6bcsqm50\_.ctl"

 control\_files           = "/u01/flash\_recovery\_area/WILSON/controlfile/o1\_mf\_6bcsqmd8\_.ctl"

 db\_block\_size           = 8192

 compatible              = "11.2.0.0.0"

 db\_create\_file\_dest     = "/u01/oradata"

 db\_recovery\_file\_dest   = "/u01/flash\_recovery\_area"

 db\_recovery\_file\_dest\_size=3852M

 undo\_tablespace         = "UNDOTBS1"

 remote\_login\_passwordfile= "EXCLUSIVE"

 db\_domain               = ""

 dispatchers             = "(PROTOCOL=TCP) (SERVICE=wilsonXDB)"

 shared\_servers          = 2

 audit\_file\_dest         = "/u01/admin/wilson/adump"

 audit\_trail             = "DB"

 db\_name                 = "wilson"

 open\_cursors            = 300

 diagnostic\_dest         = "/u01"

Tue Apr 05 08:32:30 2011

PMON started with pid=2, OS id=5594

Tue Apr 05 08:32:30 2011

VKTM started with pid=3, OS id=5596 at elevated priority

VKTM running at (10)millisec precision with DBRM quantum (100)ms

Tue Apr 05 08:32:30 2011

GEN0 started with pid=4, OS id=5600

Tue Apr 05 08:32:30 2011

DIAG started with pid=5, OS id=5602

Tue Apr 05 08:32:30 2011

DBRM started with pid=6, OS id=5604

Tue Apr 05 08:32:31 2011

PSP0 started with pid=7, OS id=5606

Tue Apr 05 08:32:31 2011

DIA0 started with pid=8, OS id=5608

Tue Apr 05 08:32:31 2011

MMAN started with pid=9, OS id=5610

Tue Apr 05 08:32:31 2011

DBW0 started with pid=10, OS id=5612

Tue Apr 05 08:32:31 2011

CKPT started with pid=12, OS id=5616

Tue Apr 05 08:32:31 2011

LGWR started with pid=11, OS id=5614

Tue Apr 05 08:32:31 2011

SMON started with pid=13, OS id=5618

Tue Apr 05 08:32:31 2011

RECO started with pid=14, OS id=5620

Tue Apr 05 08:32:31 2011

MMON started with pid=15, OS id=5622

starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...

Tue Apr 05 08:32:31 2011

MMNL started with pid=16, OS id=5624

starting up 2 shared [**server**](http://blog.csdn.net/tongyu2009/article/details/8174369)[(s) ...](http://space.itpub.net/17203031/viewspace-691806)

ORACLE\_BASE from environment = /u01

 

 

总结：在本阶段，Oracle忙于进行如下阶段顺序操作。

ü        根据环境变量，确定初始化参数文件位置。根据环境变量中对ORACLE\_SID、ORACLE\_HOME等的设置，确定要启动数据库在物理磁盘上的位置。根据Oracle的OFS结构，来确定使用参数文件可能的位置。根据spfile&lt;sid&gt;.ora、spfile.ora、init&lt;sid&gt;.ora和init.ora的顺序来定位参数文件。

ü        读取参数文件，确定基础的参数内容。通过读取参数文件，Oracle启动过程获取到该数据库的基本信息，包括控制文件位置、块大小、各种类型目录的具体位置、特殊表空间名称等内容。其中，对控制文件的定位，是进一步读取更多数据库信息，定位数据库文件的重要前置步骤；

 

2、 mount阶段

 

在mount阶段，数据库日志的内容相对简单些了。

  

Tue Apr 05 08:33:09 2011

alter database mount

Tue Apr 05 08:33:13 2011

Successful mount of redo thread 1, with mount id 3868018373

Database mounted in Exclusive Mode

Lost write protection disabled

Completed: alter database mount

 

 

总结：mount阶段，Oracle主要进行的各类型文件（数据文件、日志文件）的定位寻找工作。通过在nomount阶段加载的控制文件信息，确定了当前系统的文件的具体位置已经SCN信息。在此阶段，可以进行数据恢复方面的一些工作。

 

3、 Open阶段

  

Tue Apr 05 08:33:29 2011

alter database open

Beginning crash recovery of 1 threads

Started redo scan

Completed redo scan

 read 18880 KB redo, 1853 data blocks need recovery

Started redo application at

 Thread 1: logseq 87, block 4964

Recovery of Online Redo Log: Thread 1 Group 3 Seq 87 Reading mem 0

 Mem# 0: /u01/oradata/WILSON/onlinelog/o1\_mf\_3\_6bcsqtfj\_.log

 Mem# 1: /u01/flash\_recovery\_area/WILSON/onlinelog/o1\_mf\_3\_6bcsqtwv\_.log

Completed redo application of 15.28MB

Completed crash recovery at

 Thread 1: logseq 87, block 42725, scn 2965918

 1853 data blocks read, 1853 data blocks written, 18880 redo k-bytes read

Tue Apr 05 08:33:33 2011

Thread 1 advanced to log sequence 88 (thread open)

Thread 1 opened at log sequence 88

 Current log# 1 seq# 88 mem# 0: /u01/oradata/WILSON/onlinelog/o1\_mf\_1\_6bcsqpty\_.log

 Current log# 1 seq# 88 mem# 1: /u01/flash\_recovery\_area/WILSON/onlinelog/o1\_mf\_1\_6bcsqqt0\_.log

Successful open of redo thread 1

MTTR advisory is disabled because FAST\_START\_MTTR\_TARGET is not set

Tue Apr 05 08:33:34 2011

SMON: enabling cache recovery

Successfully onlined Undo Tablespace 2.

Verifying file header compatibility for11gtablespace encryption..

Verifying11gfile header compatibility for tablespace encryption completed

SMON: enabling tx recovery

Database Characterset is AL32UTF8

No Resource Manager plan active

replication\_dependency\_tracking turned off (no async multimaster replication found)

Starting background process QMNC

Tue Apr 05 08:33:38 2011

QMNC started with pid=21, OS id=5721

Tue Apr 05 08:33:40 2011

Completed: alter database open

 

 

总结：在进入Open阶段之后，Oracle进行了一系列的工作；

 

ü        由于上次关闭数据库非正常关闭。Oracle会自动检查是否需要进行前滚、后滚的回复操作。此时，控制文件、日志文件以及各个数据文件上的检查点和SCN记录就是一个重要依据。在本段代码中，Oracle发现需要进行crash恢复，并且使用Group3、顺序号为87的重做日志进行恢复；

ü        确定当前的Oracle Redo Log。进行Seq87的恢复后，确定Seq88作为当前使用的Redo Log记录；

ü        其他组件进程启动；

 

应该说，Oracle的启动是一个相当复杂精密、且层层相关的过程。深入的进行Alert\_Log分析，可以帮助我们更好的理解Oracle内部机制和机理，进而提高我们使用数据库、解决数据库问题的能力。