###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.