Oracle 启动顺序
<>
1.SQL> startup nomount;        //spfile文件读取内容(也可指定从pfile文件启动数据库)
ORACLE instance started.
Total System Global Area  218103808 bytes
Fixed Size                  1218604 bytes      固定大小
Variable Size              83888084 bytes       可变大小
Database Buffers          130023424 bytes       数据库缓冲区
Redo Buffers                2973696 bytes      重做缓冲区
SQL> 
其中数据库和重做缓冲区的内容不写入磁盘
2.SQL> alter database mount;    //从控制文件读取内容
Database altered.
3.SQL> alter database open;     //把数据文件的内容读取进来 
Database altered.
<>
从上面可以看出,如果把spfile文件给破坏掉,那么数据库就不能启动,甚至根本不能启动到nomount状态下,下面验证一下:
SQL> select status from v$instance;
STATUS
------------------------
MOUNTED                   //可以看出现在的数据库时mount状态
我们把spfile文件给修改掉,关掉数据库,再重新启动
SQL> ed
Wrote file afiedt.buf
  1* alter system set processes=10000 scope=spfile    
SQL> /
System altered.
SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount;
ORA-04031: unable to allocate 253200 bytes of shared memory ("shared pool","unknown object","sga heap(1,0)","max allowable # log files")
从上面可以看出,把spfile文件修改后,数据库不能启动到nomount状态 (当然警告日志文件里边会有提示,spile的默认参数设置)。现在让数据库从pfile文件启动,然后再次修改spfile文件,让数据库从spfile文件启动。
SQL> startup pfile='/home/oracle/pfile.ora';
ORACLE instance started.
Total System Global Area  218103808 bytes
Fixed Size                  1218604 bytes
Variable Size              88082388 bytes
Database Buffers          125829120 bytes
Redo Buffers                2973696 bytes
Database mounted.
Database opened.
SQL> select status from v$instance;
STATUS
------------------------
OPEN
SQL> 
可以看出数据库已经启动了
那么下面修改spile文件有两种思路:一种是直接把错误的参数给修改过来,另外一种是根据pfile文件在重新创建一个spfile文件
1.直接把错误的参数给修改过来
 
SQL> alter system set processes=150 scope=spfile;
alter system set processes=150 scope=spfile
*
ERROR at line 1:
ORA-32001: write to SPFILE requested but no SPFILE specified at startup              
看来这样做行不通,那么就根据pfile文件在重新创建一个spfile文件
2.SQL> create spfile='/u01/app/oracle/product/10.2.0/db_1/dbs/spfileorcl.ora' from pfile='/home/oracle/pfile.ora';
File created.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.
Total System Global Area  218103808 bytes
Fixed Size                  1218604 bytes
Variable Size              88082388 bytes
Database Buffers          125829120 bytes
Redo Buffers                2973696 bytes
SQL> alter database mount;
Database altered.
SQL> show parameter spfile;
NAME                                 TYPE
------------------------------------ ----------------------
VALUE
------------------------------
spfile                               string
/u01/app/oracle/product/10.2.0
/db_1/dbs/spfileorcl.ora
SQL> alter database open;
Database altered.
可以看出数据库以spfile方式成功启动
<>
既然数据库启动到mount状态下是从控制文件中读取内容,那么如果把控制文件给破坏掉,数据库就不能启动到mount状态下了,下面做实验验证一下:
SQL> select status from v$Instance;
STATUS
------------------------
MOUNTED
SQL> show parameter control;
NAME                                 TYPE
------------------------------------ ----------------------
VALUE
------------------------------
control_file_record_keep_time        integer
7
control_files                        string
/u01/app/oracle/oradata/orcl/c
ontrol03.ctl            
从上面可以看出数据库的状态时mount,控制文件是control03.ctl,下面把控制文件修改成control_file03.ctl,而control_file03.ctl根本就不存在
SQL> alter system set control_files='/u01/app/oracle/oradata/orcl/control_file03.ctl' scope=spfile;
System altered.
SQL> shutdown immediate;
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup noomunt;
SP2-0714: invalid combination of STARTUP options
SQL> startup nomount;
ORACLE instance started.
Total System Global Area  218103808 bytes
Fixed Size                  1218604 bytes
Variable Size              88082388 bytes
Database Buffers          125829120 bytes
Redo Buffers                2973696 bytes
SQL> alter database mount;
alter database mount
*
ERROR at line 1:
ORA-00205: error in identifying control file, check alert log for more info
可以看到数据库不能启动到mount状态下,那么去看一下alert中的警告信息,如下:
alter database mount
Mon Aug 20 11:21:34 2012
ORA-00202: control file: '/u01/app/oracle/oradata/orcl/control_file03.ctl'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
Additional information: 3
Mon Aug 20 11:21:34 2012
ORA-205 signalled during: alter database mount...
提示找不到控制文件control_file03.ctl
<>
既然数据库要启动到open的状态下需要把数据文件的内容读取进来,那么把数据文件破坏掉,数据库就不能启动到open状态了,下面验证一下:
1.查看一下数据库的状态和数据文件
SQL> select status from v$Instance;
STATUS
------------------------
OPEN
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/test.dbf
2.test.dbf给破坏掉,然后关闭数据库,重新启动
  [oracle@orcldb orcl]$ mv test.dbf test.dbf.bak
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area  218103808 bytes
Fixed Size                  1218604 bytes
Variable Size              88082388 bytes
Database Buffers          125829120 bytes
Redo Buffers                2973696 bytes
Database mounted.
SQL> alter database open;
alter database open
*
ERROR at line 1:
ORA-01157: cannot identify/lock data file 5 - see DBWR trace file
ORA-01110: data file 5: '/u01/app/oracle/oradata/orcl/test.dbf'
数据库不能启动到open状态,提示是test.dbf的错误,查看一下alter警告内容:
ORA-01157: cannot identify/lock data file 5 - see DBWR trace file
ORA-01110: data file 5: '/u01/app/oracle/oradata/orcl/test.dbf'
ORA-27037: unable to obtain file status
Linux Error: 2: No such file or directory
提示找不到test.dbf文件,那么把数据文件恢复过来,再次open数据库
[oracle@orcldb orcl]$ mv test.dbf.bak test.dbf
SQL> select status from v$Instance;
STATUS
------------------------
MOUNTED
SQL> alter database open;
Database altered.
可以看到数据库正常启动到了open状态。