1.shutdown ---> nomount

[oracle@db253 ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jun 13 09:42:44 2013

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

Connected to an idle instance.


SYS@orcl11g> startup nomount;
ORACLE instance started.

Total System Global Area  422670336 bytes
Fixed Size                  1345380 bytes
Variable Size             318769308 bytes
Database Buffers           96468992 bytes
Redo Buffers                6086656 bytes
SYS@orcl11g

通过数据字典确定数据库状态:
SYS@orcl11g> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
orcl11g          STARTED

通过系统命令,能看到当前启动了数据库进程:
[oracle@db253 ~]$ ps -ef | grep ora_
oracle    5263     1  0 09:43 ?        00:00:00 ora_pmon_orcl11g
oracle    5265     1  0 09:43 ?        00:00:00 ora_psp0_orcl11g
oracle    5267     1  0 09:43 ?        00:00:00 ora_vktm_orcl11g
oracle    5271     1  0 09:43 ?        00:00:00 ora_gen0_orcl11g
oracle    5273     1  0 09:43 ?        00:00:00 ora_diag_orcl11g
oracle    5275     1  0 09:43 ?        00:00:00 ora_dbrm_orcl11g
oracle    5277     1  0 09:43 ?        00:00:00 ora_dia0_orcl11g
oracle    5279     1  2 09:43 ?        00:00:00 ora_mman_orcl11g
。。。。。

[oracle@db253 ~]$ ipcs

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status      
0x00000000 52953099   oracle    640        4096       0                       
0x00000000 52985868   oracle    640        4096       0                       
0x1fbbfcb0 53018637   oracle    640        4096       0                       

------ Semaphore Arrays --------
key        semid      owner      perms      nsems     
0xa852a794 884736     oracle    640        154       

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages    

从shutdown到nomount状态,系统做了哪些事情?
 1.启动后台进程
 2.分配共享内存给oracle进程
 3.将启动过程,详细记录在oracle的alert日志文件中
[oracle@db253 trace]$ ls alert_orcl11g.log 
alert_orcl11g.log
[oracle@db253 trace]$ pwd
/u01/app/oracle/diag/rdbms/orcl11g/orcl11g/trace

需要哪些条件,oracle能够启动到nomount状态?
 1.需要oracle的参数文件
 2.注意ORACLE_SID和参数文件的匹配关系

参数文件的位置:
 [oracle@db253 trace]$ cd $ORACLE_HOME/dbs   --类unix系统
     $ORACLE_HOME/database  --windows系统

 [oracle@db253 dbs]$ ls
hc_orcl11g.dat  init.ora  lkORCL11G  orapworcl11g  spfileorcl11g.ora

 spfileorcl11g.ora
  :服务器参数文件 server parameter file
  :参数文件的构成: spfile<$ORACLE_SID>.ora
  :参数文件的类型:
  [oracle@db253 dbs]$ file spfileorcl11g.ora 
  spfileorcl11g.ora: data

 [oracle@db253 dbs]$ echo $ORACLE_SID
 orcl11g

ORACLE_SID和参数文件的关系:
 通过设定的ORACLE_SID,就能够找到对应的参数文件,然后就能启动数据库实例;

参数文件的分类:
 1.spfile 服务器参数文件 (data类型)
 2.静态参数文件  (文本类型)
   静态参数文件的构成:init<$ORACLE_SID>.ora

数据库启动的参数文件的搜索顺序:
 spfile<$ORACLE_SID>.ora   ---> spfile.ora  ---> init<$ORACLE_SID>.ora

如何判断使用的是spfile还是静态参数文件?

SYS@abc> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /u01/app/oracle/product/11.2.0
                                                 /db/dbs/spfile.ora

参数文件的问题导致的oracle系统无法启动:
[oracle@db253 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jun 13 10:31:45 2013

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

Connected to an idle instance.

SYS@abc> startup;
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/u01/app/oracle/product/11.2.0/db/dbs/initabc.ora'


参数文件之间的转换:
 通过spfile构建一个静态参数文件:
SYS@orcl11g> create pfile from spfile;

 File created.
SYS@orcl11g> create pfile='/home/oracle/init.ora' from spfile;

File created.

 [oracle@db253 dbs]$ ls $ORACLE_HOME/dbs/initorcl11g.ora
/u01/app/oracle/product/11.2.0/db/dbs/initorcl11g.ora

 [oracle@db253 dbs]$ file initorcl11g.ora 
initorcl11g.ora: ASCII text

 还可以通过静态参数文件构建spfile参数文件:

SYS@orcl11g> shutdown immediate;
ORA-01507: database not mounted


ORACLE instance shut down.
SYS@orcl11g> create spfile from pfile;

SYS@orcl11g> create spfile='/tmp/spfileorcl11g.ora' from pfile;

File created.

还可以通过内存的状态,创建一个参数文件:

SYS@orcl11g> create pfile from memory;

File created.


通过一个简单的参数文件就能启动一个实例:
[oracle@db253 dbs]$ vi initabc.ora
[oracle@db253 dbs]$ cat initabc.ora 
db_name=abc
[oracle@db253 dbs]$ export ORACLE_SID=abc
[oracle@db253 dbs]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jun 13 09:59:26 2013

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

Connected to an idle instance.

SYS@abc> startup nomount;
ORACLE instance started.

Total System Global Area  167395328 bytes
Fixed Size                  1343640 bytes
Variable Size             113250152 bytes
Database Buffers           50331648 bytes
Redo Buffers                2469888 bytes
SYS@abc

能够在nomount查看哪些信息?
SYS@orcl11g> l
  1  select name,value,isses_modifiable,issys_modifiable from v$parameter
  2* where name='nls_date_format'
SYS@orcl11g> /

NAME                           VALUE                          ISSES ISSYS_MOD
------------------------------ ------------------------------ ----- ---------
nls_date_format                (null)                         TRUE  FALSE

ISSES_MODIFIABLE VARCHAR2(5):表示能否使用alter session修改这个参数,会话级别的参数修改(true/false)

ISSYS_MODIFIABLE VARCHAR2(9):表示这个参数能够在实例级别进行修改
■ IMMEDIATE - 表示可以修改,并且立即生效
■ DEFERRED - 表示可以修改,但是下一个会话生效
■ FALSE - 表示使用spfile参数文件,可以修改,但是,下一次实例启动才生效

参数修改的语法格式:

SYS@orcl11g> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';

Session altered.

SYS@orcl11g> alter system set nls_date_format='yyyy-mm-dd hh24:mi:ss';
alter system set nls_date_format='yyyy-mm-dd hh24:mi:ss'
                 *
ERROR at line 1:
ORA-02096: specified initialization parameter is not modifiable with this
option

 表示实例级别的参数修改有修改范围选项:
  scope = memory  :表示立即生效,但是,仅仅在当前实例生效,重启之后,效果消失;
    spfile  :表示修改的效果保存在spfiile文件当中,下一次实例启动才生效
    both  : 当前实例立即生效,并且重启之后也生效(默认范围)

SYS@orcl11g> alter system set nls_date_format='yyyy-mm-dd hh24:mi:ss' scope=spfile;

System altered.

**********************************************************************
2.从nomount  ---> mount状态

 从nomount到mount,oracle需要什么条件才能启动mount状态?
 需要oracle的控制文件;

 需要找到所有的在参数文件文件中,指定的控制文件,并且保证所有的控制文件是有效的和完全一致;

 控制文件是多路复用的的。

 如何查看在参数文件中指定的控制文件呢?
SYS@orcl11g> show parameter control_files; 

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
control_files                        string      /u01/app/oracle/oradata/orcl11
                                                 g/control01.ctl, /u01/app/orac
                                                 le/fast_recovery_area/orcl11g/
                                                 control02.ctl

 从nomount到mount的转换指令:
SYS@orcl11g> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
orcl11g          STARTED

SYS@orcl11g> alter database mount;

Database altered.

SYS@orcl11g> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
orcl11g          MOUNTED

 控制文件丢失一个副本的情况,以及如何解决?(并捎带转换控制文件位置)

SYS@orcl11g> startup mount;
ORACLE instance started.

Total System Global Area  422670336 bytes
Fixed Size                  1345380 bytes
Variable Size             318769308 bytes
Database Buffers           96468992 bytes
Redo Buffers                6086656 bytes
ORA-00205: error in identifying control file, check alert log for more info

 在alert日志当中的报错信息:
 ALTER DATABASE   MOUNT
ORA-00210: cannot open the specified control file
ORA-00202: control file: '/u01/app/oracle/fast_recovery_area/orcl11g/control02.ctl'

 1.关闭数据库
 2.修改参数文件
  通过转换方式,修改文本的参数文件;
SYS@orcl11g> shutdown immediate;

SYS@orcl11g> create pfile from spfile;

  [oracle@db253 orcl11g]$ cd $ORACLE_HOME/dbs
  [oracle@db253 dbs]$ vi initorcl11g.ora 
  *.control_files='/u01/app/oracle/oradata/orcl11g/control01.ctl','/u01/app/oracle/oradata/orcl11g/control02.ctl'

SYS@orcl11g> create spfile from pfile;

  或者直接在nomount状态下,修改control_files参数也行
SYS@orcl11g> alter system set control_files='/u01/app/oracle/oradata/orcl11g/control01.ctl','/u01/app/oracle/oradata/orcl11g/control02.ctl' scope=spfile

  重新启动实例:
SYS@orcl11g> shutdown abort;

SYS@orcl11g> startup nomount;

 3.拷贝完好的控制文件,到指定位置即可
 4.alter database mount;


********************************************************************************

3.mount --> open

 数据库的数据文件是有效的; 
 数据库的数据文件和控制文件的状态保持一致,就能够打开数据库(open);

 scn,oralce内部的一种时钟机制;是一连串的递增数字;

 如何从mount到open?

SYS@orcl11g> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
orcl11g          MOUNTED

SYS@orcl11g> alter database open;

Database altered.

SYS@orcl11g> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
orcl11g          OPEN


***************************************
数据库的打开模式:

SYS@orcl11g> select name,open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
ORCL11G   READ WRITE

 正常的模式:读写模式

1.read only 只读模式
SYS@orcl11g> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@orcl11g> startup mount;
ORACLE instance started.

Total System Global Area  422670336 bytes
Fixed Size                  1345380 bytes
Variable Size             318769308 bytes
Database Buffers           96468992 bytes
Redo Buffers                6086656 bytes
Database mounted.
SYS@orcl11g> alter database open read only;

Database altered.
SYS@orcl11g> select name,open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
ORCL11G   READ ONLY

SYS@orcl11g> create table hr.tab0613 as select * from hr.employees;
create table hr.tab0613 as select * from hr.employees
                                            *
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-16000: database open for read-only access


2.受限打开模式

SYS@orcl11g> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SYS@orcl11g> startup;
ORACLE instance started.

Total System Global Area  422670336 bytes
Fixed Size                  1345380 bytes
Variable Size             318769308 bytes
Database Buffers           96468992 bytes
Redo Buffers                6086656 bytes
Database mounted.
Database opened.
SYS@orcl11g
SYS@orcl11g> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
orcl11g          OPEN

SYS@orcl11g> select name,open_mode from v$database;

NAME      OPEN_MODE
--------- --------------------
ORCL11G   READ WRITE

SYS@orcl11g> alter system enable  restricted session;

System altered.

[oracle@db253 ~]$ sqlplus hr/hr

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jun 13 11:35:19 2013

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

ERROR:
ORA-01035: ORACLE only available to users with RESTRICTED SESSION privilege

SYS@orcl11g> grant restricted session to hr;

Grant succeeded.

[oracle@db253 ~]$ sqlplus hr/hr

SQL*Plus: Release 11.2.0.3.0 Production on Thu Jun 13 11:36:27 2013

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

HR@orcl11g

如何取消受限模式:

SYS@orcl11g> alter system disable restricted session;

System altered.


3.静默受限模式

SYS@orcl11g> alter system quiesce restricted;

System altered.

SYS@orcl11g> alter system unquiesce;

System altered.