3.1 Oracle体系结构之实例启动与关闭

Oracle 实例分为四种状态,分别为:
关闭(SHUTDOWN)、非装载(NOMOUNT 启动)、装载(MOUNT)、打开(OPEN)。

1、关闭(SHUTDOWN)

如果实例没有打开,以普通用户身份时,会报错。
访问Oracle 数据库首先要启动数据库,管理员连接到空闲实例,然后才能发出启动实例或数据库的命令。
启动Oracle 服务器,每个阶段会打开不同的文件并且会完成不同的管理任务。

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

执行命令STARTUP,要求用户必须具有SYSDBA 或SYSOPER 系统权限,另外,如果要建立数据库,则必须以SYSDBA 身份登录。

2、非装载(NOMOUNT 启动)

shutdown->nomount
分配了内存,启动了进程

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

分配内存使用参数文件/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 默认打开初始化参数文件的顺序是:spfilesid.ora→spfile.ora→ initsid.ora
如果三个文件都不存在,则报错。

在NOMOUNT 状态下无法备份控制文件,MOUNT 状态下备份成功,说明数据库从NOMOUNT 到MOUNT 状态读取了控制文件。
装载数据库阶段,系统会按照初始化参数文件中control_files 参数的设置查找并打开控制文件。
Oracle 是通过控制文件在实例和数据库之间建立关联的,通过控制文件可以取得数据文件和重做日志的名称和所处状态。但对数据文件和日志文件是否存在不作检查。

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 状态下,我们无法读取到数据,说明数据文件没有被读取。当数据库OPEN后,我们可以读取到数据,说明数据库从MOUNT 到OPEN 加载了数据文件。

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 状态下,我们无法手工切换日志文件组,说明联机重做日志文件没有被读取。当数据库OPEN 后,可以切换,说明数据库从MOUNT 到OPEN 加载了日志文件。

4、打开(OPEN)

在这阶段启动实例恢复SMON,在这一阶段读取了日志文件和数据文件

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状态并登陆

SQL> alter user scott identified by oracle account unlock;

User altered.

SQL> conn scott/oracle;
Connected.
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,569评论 4 363
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,499评论 1 294
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,271评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,087评论 0 209
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,474评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,670评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,911评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,636评论 0 202
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,397评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,607评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,093评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,418评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,074评论 3 237
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,092评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,865评论 0 196
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,726评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,627评论 2 270

推荐阅读更多精彩内容