Oracle 實例分為四種狀態(tài)晴竞,分別為:
關(guān)閉(SHUTDOWN)亲族、非裝載(NOMOUNT 啟動)崔慧、裝載(MOUNT)拂蝎、打開(OPEN)。
1惶室、關(guān)閉(SHUTDOWN)
如果實例沒有打開温自,以普通用戶身份時玄货,會報錯。
訪問Oracle 數(shù)據(jù)庫首先要啟動數(shù)據(jù)庫捣作,管理員連接到空閑實例,然后才能發(fā)出啟動實例或數(shù)據(jù)庫的命令鹅士。
啟動Oracle 服務(wù)器券躁,每個階段會打開不同的文件并且會完成不同的管理任務(wù)。
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@ocm ~]$ sqlplus scott/oracle
SQL*Plus: Release 11.2.0.3.0 Production on Mon Jul 24 13:27:36 2017
Copyright (c) 1982, 2011, Oracle. All rights reserved.
ERROR:
ORA-01034: ORACLE not available
ORA-27101: shared memory realm does not exist
Linux Error: 2: No such file or directory
Process ID: 0
Session ID: 0 Serial number: 0
Enter user-name:
ERROR:
ORA-01017: invalid username/password; logon denied
Enter user-name:
ERROR:
ORA-01017: invalid username/password; logon denied
SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
[oracle@ocm ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Mon Jul 24 13:29:19 2017
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 368263168 bytes
Fixed Size 1345016 bytes
Variable Size 247466504 bytes
Database Buffers 113246208 bytes
Redo Buffers 6205440 bytes
Database mounted.
Database opened.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@ocm ~]$ sqlplus scott/oracle
SQL*Plus: Release 11.2.0.3.0 Production on Mon Jul 24 13:30:04 2017
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
執(zhí)行命令STARTUP掉盅,要求用戶必須具有SYSDBA 或SYSOPER 系統(tǒng)權(quán)限也拜,另外,如果要建立數(shù)據(jù)庫趾痘,則必須以SYSDBA 身份登錄慢哈。
2、非裝載(NOMOUNT 啟動)
shutdown->nomount
分配了內(nèi)存永票,啟動了進程
SQL> startup nomount
ORACLE instance started.
Total System Global Area 368263168 bytes
Fixed Size 1345016 bytes
Variable Size 239077896 bytes
Database Buffers 121634816 bytes
Redo Buffers 6205440 bytes
分配內(nèi)存使用參數(shù)文件/u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora
Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
Mon Jul 24 03:56:39 2017
Picked latch-free SCN scheme 2
Using LOG_ARCHIVE_DEST_1 parameter default value as /u01/app/oracle/product/11.2.0/db_1/dbs/arch
Autotune of undo retention is turned on.
IMODE=BR
ILAT =27
LICENSE_MAX_USERS = 0
SYS auditing is disabled
Starting up:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options.
ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1
System name: Linux
Node name: ocm.example.com
Release: 2.6.18-164.el5
Version: #1 SMP Thu Sep 3 02:16:47 EDT 2009
Machine: i686
VM name: VMWare Version: 6
Using parameter settings in server-side spfile /u01/app/oracle/product/11.2.0/db_1/dbs/spfileorcl.ora
System parameters with non-default values:
processes = 150
memory_target = 352M
control_files = "/u01/app/oracle/oradata/orcl/control01.ctl"
control_files = "/u01/app/oracle/oradata/orcl/control02.ctl"
db_block_size = 8192
compatible = "11.2.0.0.0"
undo_tablespace = "UNDOTBS1"
remote_login_passwordfile= "EXCLUSIVE"
db_domain = ""
dispatchers = "(PROTOCOL=TCP) (SERVICE=orclXDB)"
audit_file_dest = "/u01/app/oracle/admin/orcl/adump"
audit_trail = "DB"
db_name = "orcl"
open_cursors = 300
diagnostic_dest = "/u01/app/oracle"
Mon Jul 24 03:56:42 2017
PMON started with pid=2, OS id=18767
Mon Jul 24 03:56:42 2017
PSP0 started with pid=3, OS id=18769
Mon Jul 24 03:56:43 2017
VKTM started with pid=4, OS id=18771 at elevated priority
VKTM running at (1)millisec precision with DBRM quantum (100)ms
Mon Jul 24 03:56:44 2017
GEN0 started with pid=5, OS id=18775
Mon Jul 24 03:56:45 2017
DIAG started with pid=6, OS id=18777
Mon Jul 24 03:56:45 2017
DBRM started with pid=7, OS id=18779
Mon Jul 24 03:56:46 2017
DIA0 started with pid=8, OS id=18781
Mon Jul 24 03:56:46 2017
MMAN started with pid=9, OS id=18783
Mon Jul 24 03:56:48 2017
DBW0 started with pid=10, OS id=18785
Mon Jul 24 03:56:48 2017
LGWR started with pid=11, OS id=18787
Mon Jul 24 03:56:48 2017
CKPT started with pid=12, OS id=18789
Mon Jul 24 03:56:49 2017
SMON started with pid=13, OS id=18791
Mon Jul 24 03:56:49 2017
RECO started with pid=14, OS id=18793
Mon Jul 24 03:56:50 2017
MMON started with pid=15, OS id=18795
starting up 1 dispatcher(s) for network address '(ADDRESS=(PARTIAL=YES)(PROTOCOL=TCP))'...
Mon Jul 24 03:56:50 2017
MMNL started with pid=16, OS id=18797
starting up 1 shared server(s) ...
ORACLE_BASE from environment = /u01/app/oracle
查看進程
oracle@ocm orcl]$ ps -ef | grep ora_
oracle 21954 1 0 13:42 ? 00:00:00 ora_pmon_orcl
oracle 21956 1 0 13:42 ? 00:00:00 ora_psp0_orcl
oracle 21958 1 0 13:42 ? 00:00:00 ora_vktm_orcl
oracle 21962 1 0 13:42 ? 00:00:00 ora_gen0_orcl
oracle 21964 1 0 13:42 ? 00:00:00 ora_diag_orcl
oracle 21966 1 0 13:42 ? 00:00:00 ora_dbrm_orcl
oracle 21968 1 0 13:42 ? 00:00:00 ora_dia0_orcl
oracle 21970 1 1 13:42 ? 00:00:00 ora_mman_orcl
oracle 21972 1 0 13:42 ? 00:00:00 ora_dbw0_orcl
oracle 21974 1 0 13:42 ? 00:00:00 ora_lgwr_orcl
oracle 21976 1 0 13:42 ? 00:00:00 ora_ckpt_orcl
oracle 21978 1 0 13:42 ? 00:00:00 ora_smon_orcl
oracle 21980 1 0 13:42 ? 00:00:00 ora_reco_orcl
oracle 21982 1 0 13:42 ? 00:00:00 ora_mmon_orcl
oracle 21984 1 0 13:42 ? 00:00:00 ora_mmnl_orcl
oracle 21986 1 0 13:42 ? 00:00:00 ora_d000_orcl
oracle 21988 1 0 13:42 ? 00:00:00 ora_s000_orcl
oracle 22020 20904 0 13:43 pts/4 00:00:00 grep ora_
Oracle 默認打開初始化參數(shù)文件的順序是:spfilesid.ora→spfile.ora→ initsid.ora
如果三個文件都不存在卵贱,則報錯。
在NOMOUNT 狀態(tài)下無法備份控制文件侣集,MOUNT 狀態(tài)下備份成功键俱,說明數(shù)據(jù)庫從NOMOUNT 到MOUNT 狀態(tài)讀取了控制文件。
裝載數(shù)據(jù)庫階段世分,系統(tǒng)會按照初始化參數(shù)文件中control_files 參數(shù)的設(shè)置查找并打開控制文件编振。
Oracle 是通過控制文件在實例和數(shù)據(jù)庫之間建立關(guān)聯(lián)的,通過控制文件可以取得數(shù)據(jù)文件和重做日志的名稱和所處狀態(tài)臭埋。但對數(shù)據(jù)文件和日志文件是否存在不作檢查踪央。
SQL> alter database backup controlfile to '/u01/app/oracle/oradata/orcl/control_bak.ctl';
alter database backup controlfile to '/u01/app/oracle/oradata/orcl/control_bak.ctl'
*
ERROR at line 1:
ORA-01507: database not mounted
SQL> alter database mount;
Database altered.
SQL> alter database backup controlfile to '/u01/app/oracle/oradata/orcl/control_bak.ctl';
Database altered.
3、裝載(MOUNT)
SQL> select count(*)from scott.emp;
select count(*)from scott.emp
*
ERROR at line 1:
ORA-01219: database not open: queries allowed on fixed tables/views only
SQL> alter database open;
Database altered.
SQL> select count(*) from scott.emp;
COUNT(*)
----------
14
在MOUNT 狀態(tài)下瓢阴,我們無法讀取到數(shù)據(jù)畅蹂,說明數(shù)據(jù)文件沒有被讀取。當(dāng)數(shù)據(jù)庫OPEN后荣恐,我們可以讀取到數(shù)據(jù)魁莉,說明數(shù)據(jù)庫從MOUNT 到OPEN 加載了數(shù)據(jù)文件。
SQL> select status from v$instance;
STATUS
------------
MOUNTED
SQL> alter system switch logfile;
alter system switch logfile
*
ERROR at line 1:
ORA-01109: database not open
SQL> alter database open;
Database altered.
SQL> alter system switch logfile;
System altered.
在MOUNT 狀態(tài)下募胃,我們無法手工切換日志文件組旗唁,說明聯(lián)機重做日志文件沒有被讀取。當(dāng)數(shù)據(jù)庫OPEN 后痹束,可以切換检疫,說明數(shù)據(jù)庫從MOUNT 到OPEN 加載了日志文件。
4祷嘶、打開(OPEN)
在這階段啟動實例恢復(fù)SMON屎媳,在這一階段讀取了日志文件和數(shù)據(jù)文件
alter database open
Mon Jul 24 04:15:24 2017
Thread 1 opened at log sequence 14
Current log# 2 seq# 14 mem# 0: /u01/app/oracle/oradata/orcl/redo02.log
Successful open of redo thread 1
MTTR advisory is disabled because FAST_START_MTTR_TARGET is not set
Mon Jul 24 04:15:24 2017
SMON: enabling cache recovery
[19461] Successfully onlined Undo Tablespace 2.
Undo initialization finished serial:0 start:32216454 end:32216624 diff:170 (1 seconds)
Verifying file header compatibility for 11g tablespace encryption..
Verifying 11g file header compatibility for tablespace encryption completed
SMON: enabling tx recovery
Database Characterset is AL32UTF8
No Resource Manager plan active
replication_dependency_tracking turned off (no async multimaster replication found)
Starting background process QMNC
Mon Jul 24 04:15:29 2017
QMNC started with pid=20, OS id=19465
Completed: alter database open
Mon Jul 24 04:15:38 2017
Starting background process CJQ0
Mon Jul 24 04:15:39 2017
CJQ0 started with pid=22, OS id=19477
修改scott狀態(tài)并登陸
SQL> alter user scott identified by oracle account unlock;
User altered.
SQL> conn scott/oracle;
Connected.