###1. 启动Oracle DB 实例sql
Syntax STARTUP options | upgrade_options options syntax: [FORCE] [RESTRICT] [PFILE=filename] [QUIET] [ MOUNT [dbname] | [ OPEN [open_options] [dbname] ] | NOMOUNT ] open_options syntax: READ {ONLY | WRITE [RECOVER]} | RECOVER upgrade_options syntax: [PFILE=filename] {UPGRADE | DOWNGRADE} [QUIET]
####1.1 NOMOUNT数据库
在建立数据库期间、从新建立控制文件期间,或执行某些备份和恢复方案期间,一般只在NOMOUNT 模式下启动实例。服务器
启动实例过程包括执行如下任务:session
- 按如下顺序搜索$ORACLE_HOME/dbs 中具备特定名称的文件:
- 分配SGA。
- 启动后台进程。
- 打开alert_<SID>.log 文件和跟踪文件。
####1.2 MOUNToracle
数据库装载过程包括执行如下任务:app
- 将数据库与之前启动的实例关联。
- 定位并打开参数文件中指定的控制文件。
- 经过读取控制文件来获取数据文件和联机重作日志文件的名称和状态(可是,此时不会执行检查来验证是否存在数据文件和联机重作日志文件)。
要执行特定的维护操做,请启动实例,而后装载数据库,但不打开该数据库。例如,在执行如下任务期间必须装载数据库,但不得打开数据库:this
- 重命名数据文件(打开数据库时可重命名脱机表空间的数据文件)。
- 启用和禁用联机重作日志文件归档选项。
- 执行完整的数据库恢复。
注:即便发出了OPEN 请求,数据库仍可能处于MOUNT 模式下。这是由于可能须要以某种方式恢复数据库。若是在MOUNT 状态下执行恢复,将打开重作日志进行读取,并打开数据文件读取须要恢复的块,以及在恢复期间根据须要写入块。rest
####1.3 OPEN日志
打开数据库过程包括执行如下任务:code
- 打开数据文件。
- 打开联机重作日志文件。
若是尝试打开数据库时任一数据文件或联机重作日志文件不存在,则Oracle 服务器返回错误。 在最后这个阶段,Oracle 服务器会验证是否能够打开全部数据文件和联机重作日志文件,还会检查数据库的一致性。若有必要,系统监视器(SMON) 后台进程将启动实例恢复。
OPEN READ ONLY
Specify OPEN READ ONLY to restrict users to read-only transactions, preventing them from generating redo logs. This setting is the default when you are opening a physical standby database, so that the physical standby database is available for queries even while archive logs are being copied from the primary database site.
SQL> startup mount; ORACLE instance started. Total System Global Area 6714322944 bytes Fixed Size 2239192 bytes Variable Size 6526338344 bytes Database Buffers 167772160 bytes Redo Buffers 17973248 bytes Database mounted. SQL> alter database open read only; Database altered. [root@hzvscmdb alert]# sqlplus hr/pass@tonytest SQL*Plus: Release 11.2.0.2.0 Production on Tue May 26 05:21:01 2015 Copyright (c) 1982, 2010, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning option SQL> select count(*) from employees; COUNT(*) ---------- 109 SQL> delete from employees; delete from employees * ERROR at line 1: ORA-16000: database open for read-only access
OPEN READ WRITE Specify OPEN READ WRITE to open the database in read/write mode, allowing users to generate redo logs. This is the default if you are opening a primary database. You cannot specify this clause for a physical standby database.
SQL> startup mount; ORACLE instance started. Total System Global Area 6714322944 bytes Fixed Size 2239192 bytes Variable Size 6526338344 bytes Database Buffers 167772160 bytes Redo Buffers 17973248 bytes Database mounted. SQL> alter database open read write; Database altered. SQL> delete from table1; 10 rows deleted. SQL> commit; Commit complete.
####1.4 FORCE
If the database is open, then FORCE shuts down the database with a SHUTDOWN ABORT statement before re-opening it. If the database is closed, then FORCE opens the database.
#以force 方式 startup数据库 SQL> startup force; ORACLE instance started. Total System Global Area 6714322944 bytes Fixed Size 2239192 bytes Variable Size 6526338344 bytes Database Buffers 167772160 bytes Redo Buffers 17973248 bytes Database mounted. Database opened. [root@hzvscmdb alert]# pwd /home/oracle/app/oracle/diag/rdbms/tonytest/tonytest/alert [root@hzvscmdb alert]# vi log.xml ####################首先shutdown abort####################### <msg time='2015-05-26T02:08:20.847+00:00' org_id='oracle' comp_id='rdbms' msg_id='opistp_real:1497:251923032' client_id='' type='NOTIFICATION' group='shutdown' level='16' host_id='hzvscmdb' host_addr='0.0.0.200' module='sqlplus@hzvscmdb (TNS V1-V3)' pid='3875'> <txt>Shutting down instance (abort) </txt> </msg> <msg time='2015-05-26T02:08:22.169+00:00' org_id='oracle' comp_id='rdbms' msg_id='opistp_real:1514:503144415' type='NOTIFICATION' group='shutdown' level='16' host_id='hzvscmdb' host_addr='0.0.0.200' pid='3875'> <txt>Instance shutdown complete </txt> </msg> ####################startup normal####################### <msg time='2015-05-26T02:08:22.551+00:00' org_id='oracle' comp_id='rdbms' msg_id='opistr_real:948:3971575317' type='NOTIFICATION' group='startup' level='16' host_id='hzvscmdb' host_addr='0.0.0.200' pid='4654'> <txt>Starting ORACLE instance (normal) </txt> </msg> <msg time='2015-05-26T02:08:26.524+00:00' org_id='oracle' comp_id='rdbms' msg_id='opiexe:2974:4222364190' client_id='' type='NOTIFICATION' group='admin_ddl' level='16' host_id='hzvscmdb' host_addr='0.0.0.200' module='sqlplus@hzvscmdb (TNS V1-V3)' pid='4840'> <txt>ALTER DATABASE MOUNT </txt> </msg> <msg time='2015-05-26T02:08:30.791+00:00' org_id='oracle' comp_id='rdbms' msg_id='opiexe:2974:4222364190' client_id='' type='NOTIFICATION' group='admin_ddl' level='16' host_id='hzvscmdb' host_addr='0.0.0.200' module='sqlplus@hzvscmdb (TNS V1-V3)' pid='4845'> <txt>ALTER DATABASE OPEN </txt> </msg> ####################performs recovery automatically####################### <msg time='2015-05-26T02:08:30.829+00:00' org_id='oracle' comp_id='rdbms' client_id='' type='UNKNOWN' level='16' host_id='hzvscmdb' host_addr='0.0.0.200' module='sqlplus@hzvscmdb (TNS V1-V3)' pid='4845'> <txt>Beginning crash recovery of 1 threads </txt> </msg> <msg time='2015-05-26T02:08:30.984+00:00' org_id='oracle' comp_id='rdbms' client_id='' type='UNKNOWN' level='16' host_id='hzvscmdb' host_addr='0.0.0.200' module='sqlplus@hzvscmdb (TNS V1-V3)' pid='4845'> <txt> read 193 KB redo, 84 data blocks need recovery </txt> </msg> <msg time='2015-05-26T02:08:31.168+00:00' org_id='oracle' comp_id='rdbms' client_id='' type='UNKNOWN' level='16' host_id='hzvscmdb' host_addr='0.0.0.200' module='sqlplus@hzvscmdb (TNS V1-V3)' pid='4845'> <txt>Recovery of Online Redo Log: Thread 1 Group 2 Seq 2697 Reading mem 0 </txt> </msg>
####1.5 RESTRICT
Only enables Oracle Database users with the RESTRICTED SESSION system privilege to connect to the database. Later, you can use the ALTER SYSTEM command to disable the restricted session feature.
SQL> startup restrict mount ; ORACLE instance started. Total System Global Area 6714322944 bytes Fixed Size 2239192 bytes Variable Size 6526338344 bytes Database Buffers 167772160 bytes Redo Buffers 17973248 bytes Database mounted. SQL> alter database open; Database altered. [root@hzvscmdb alert]# sqlplus hr/pass@tonytest SQL*Plus: Release 11.2.0.2.0 Production on Tue May 26 05:55:42 2015 Copyright (c) 1982, 2010, Oracle. All rights reserved. ERROR: ORA-12526: TNS:listener: all appropriate instances are in restricted mode SQL> alter system disable restricted session; System altered. [root@hzvscmdb alert]# sqlplus hr/pass@tonytest SQL*Plus: Release 11.2.0.2.0 Production on Tue May 26 08:14:38 2015 Copyright (c) 1982, 2010, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning option
####1.6 PFILE
PFILE=filename
- Specifies the client parameter file to be used while starting the instance. If PFILE is not specified, the server attempts to access a default server parameter file (spfile). If the default spfile isn't found, the server then attempts to access a default pfile. The default files are platform specific. For example, the default file is $ORACLE_HOME/dbs/init$ORACLE_SID.ora on UNIX, and ORACLE_HOME\database\initORCL.ora on Windows.
[oracle@hzvscmdb dbs]$ pwd /home/oracle/app/oracle/product/11.2.0/dbhome_1/dbs [oracle@hzvscmdb dbs]$ ll *tonytest.ora -rw-r--r-- 1 oracle oinstall 1128 Aug 5 2014 inittonytest.ora -rw-r-----. 1 oracle oinstall 3584 May 26 05:47 spfiletonytest.ora SQL> startup pfile = inittonytest.ora; ORACLE instance started. Total System Global Area 6714322944 bytes Fixed Size 2239192 bytes Variable Size 5150606632 bytes Database Buffers 1543503872 bytes Redo Buffers 17973248 bytes Database mounted. Database opened.