Oracle的启动方式:


startup nomount


startup mount


startup open (startup的默认选项)


  其他常用的参数:read only ,read write ,force,restrict


  这些参数可以一起使用,比如 startup startup open read write 是一样的效果。


Oracle的启动过程:启动实例 -> 装载数据库 -> 打开数据库


  与之对应的读取相应文件的顺序: 参数文件 -> 控制文件 -> 数据文件


  我们验证一下这些步骤的区别:


startup nomount


读取数据库参数文件,完成分配SGAPGA,启动后台进程等,如果参数文件出现问题则在nomount这步就已经启动不了,实验如下:


1、 修改参数文件


[oracle@redhat4 dbs]$ mv spfilejiagulun.ora spfilejiagulun01.ora


2、 启动数据库


SQL> startup nomount;

ORA-01078: failure in processing system parameters

LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initjiagulun.ora'

报错,不能打开数据库参数文件。


[oracle@redhat4 dbs]$ mv spfilejiagulun01.ora spfilejiagulun.ora


当环境变量设置错误也会引起弄mount失败,因为oracle读取spfilejiagulun.ora是通过环境变量找到SID jiagulun和spfile的路径。环境变量SID(等于数据库实例名)设置不正确报错如下:

SQL> startup nomount;

ORA-01078: failure in processing system parameters

LRM-00109: could not open parameter file '/u01/app/oracle/product/10.2.0/db_1/dbs/initjiagulun1.ora'



修改回来后,再nomount数据库成功。


SQL> startup nomount;

ORACLE instance started.


Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             100664912 bytes

Database Buffers          180355072 bytes

Redo Buffers                2973696 bytes

SQL>

一般启动数据库读取到这个文件,启动后不做参数修改基本不读取了。




Startup mount


读取控制文件,控制文件记录了数据库的物理结构如下信息:
1、数据库的创建时间
2、数据文件的位置
3、日志文件的位置
作用是指导数据库 找到数据文件,日志文件并将数据库启动到 open 状态。


control01.ctlcontrol02.ctlcontrol03.ctl内容全部一样,起到备份作用。


[oracle@redhat4 jiagulun]$ mv control01.ctl control.ctl  修改控制文件


SQL> startup mount;

ORACLE instance started.


Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             100664912 bytes

Database Buffers          180355072 bytes

Redo Buffers                2973696 bytes

ORA-00205: error in identifying control file, check alert log for more info


报错了ORA-00205


将控制文件02复制命名为控制文件01,在mount数据库,成功。


[oracle@redhat4 jiagulun]$ cp control02.ctl control01.ctl


SQL> startup mount;

ORACLE instance started.


Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             100664912 bytes

Database Buffers          180355072 bytes

Redo Buffers                2973696 bytes

Database mounted.

虽然三个控制文件一样,但是01 02 03改变随便一个都会读取失败报错。



Startup open


读取dbf数据文件和redo log文件。


修改redo.log文件


[oracle@redhat4 jiagulun]$ mv redo02.log redo002.log


SQL> alter database open;

alter database open

*

ERROR at line 1:

ORA-00313: open failed for members of log group 2 of thread 1

ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/jiagulun/redo02.log'

启动报错。


尝试将redo01复制重命名redo02,启动不行,证明文件肯定不一样的。


[oracle@redhat4 jiagulun]$ cp redo01.log redo02.log


SQL> startup;

ORACLE instance started.


Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             100664912 bytes

Database Buffers          180355072 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-00341: log 2 of thread 1, wrong log #  in header

ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/jiagulun/redo02.log'

改回来后启动成功


[oracle@redhat4 jiagulun]$ mv redo002.log redo02.log


SQL> startup;

ORACLE instance started.


Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             100664912 bytes

Database Buffers          180355072 bytes

Redo Buffers                2973696 bytes

Database mounted.

Database opened.


改变DBF数据文件


[oracle@redhat4 jiagulun]$ mv example01.dbf example001.dbf


SQL> startup

ORACLE instance started.


Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             104859216 bytes

Database Buffers          176160768 bytes

Redo Buffers                2973696 bytes

Database mounted.

ORA-01157: cannot identify/lock data file 5 - see DBWR trace file

ORA-01110: data file 5: '/u01/app/oracle/oradata/jiagulun/example01.dbf'


启动失败。


改回来后启动成功


[oracle@redhat4 jiagulun]$ mv example001.dbf example01.dbf


SQL> startup;

ORACLE instance started.


Total System Global Area  285212672 bytes

Fixed Size                  1218992 bytes

Variable Size             104859216 bytes

Database Buffers          176160768 bytes

Redo Buffers                2973696 bytes

Database mounted.

Database opened.




通过以上实验


1.nomount方式下还没有读取控制文件,该选项用于在数据库的控制文件全部损坏,需要重新创建数据库控制文件或创建一个新的数据库时使用。


2.mount 选项下并没有打开数据文件,该选项可以用来修改数据库的运行模式或进行数据库恢复。