首先找加了SID的SPFILE,如果找不到,就找不带SID的SPFILE;如果还是找不到,就找PFILE。如果为startup 指定一个PFILE的路径,则该PFILE会覆盖默认的查找顺序。
/*=====================演示启动过程==========================*/
[oracle@localhost ~]$ cd /oracle/11g/dbs
[oracle@localhost dbs]$ ll
total 28 -rw-rw----. 1 oracle oinstall 1544 Sep 9 03:26 hc_orcl.dat -rw-r--r--. 1 oracle oinstall 2851 May 15 2009 init.ora -rw-r--r--. 1 oracle oinstall 861 Sep 9 03:27 initorcl.ora # PFILE -rw-r-----. 1 oracle oinstall 24 Aug 5 18:28 lkORCL -rw-r-----. 1 oracle oinstall 1536 Aug 7 16:08 orapworcl drwx------. 2 oracle oinstall 4096 Aug 5 18:25 peshm_orcl_0 -rw-r-----. 1 oracle oinstall 2560 Sep 8 22:10 spfileorcl.ora # SPFILE
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Tue Sep 903:26:57 2014
Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started. Total System Global Area 422670336 bytes Fixed Size 1336960 bytes Variable Size 318769536 bytes Database Buffers 96468992 bytes Redo Buffers 6094848 bytes Database mounted. Database opened. -- 默认的启动方式使用的是SPFILE文件
[oracle@localhost dbs]$ mkdir old
[oracle@localhost dbs]$ mv spfileorcl.ora old
# 将SPFILE移动到old目录下
[oracle@localhost dbs]$ rm -f initorcl.ora
[oracle@localhost dbs]$ cp old/spfileorcl.ora ./spfileabc.ora
[oracle@localhost dbs]$ vim abc123.ora
spfile=$ORACLE_HOME/dbs/spfileabc.ora # 创建一个PFILE,在这个PFILE里面指定SPFILE的路径
[oracle@localhost dbs]$ ll
total 32 -rw-r--r--. 1 oracle oinstall 38 Sep 9 03:38 abc123.ora -rw-rw----. 1 oracle oinstall 1544 Sep 9 03:32 hc_orcl.dat -rw-r--r--. 1 oracle oinstall 2851 May 15 2009 init.ora -rw-r-----. 1 oracle oinstall 24 Aug 5 18:28 lkORCL drwxr-xr-x. 2 oracle oinstall 4096 Sep 9 03:34 old -rw-r-----. 1 oracle oinstall 1536 Aug 7 16:08 orapworcl drwx------. 2 oracle oinstall 4096 Aug 5 18:25 peshm_orcl_0 -rw-r-----. 1 oracle oinstall 2560 Sep 9 03:36 spfileabc.ora
SQL> shutdown immediate
Database closed. Database dismounted. ORACLE instance shut down. -- 关闭现有的Instance
SQL> startuppfile=$ORACLE_HOME/dbs/abc123.ora
-- 启动实例是指定PFILE的路径 ORACLE instance started. Total System Global Area 422670336 bytes Fixed Size 1336960 bytes Variable Size 318769536 bytes Database Buffers 96468992 bytes Redo Buffers 6094848 bytes Database mounted. Database opened.
Unix/Linux的root用户,或者Windows的administrator 具有启动关闭数据库的权限;如果Database是基于口令认证的,而某个用户被授予了SYSDBA和SYSOPER的权限,就可以启动关闭数据库, SYSOPER的权限略小于SYSDBA;
[oracle@localhost dbs]$ id
uid=500(oracle) gid=500(oinstall)groups=500(oinstall),501(dba)context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
SQL> startup
-- 这里没有要求输入口令,这是由于当前用户已经登录了操作系统,oracle就默认该用户有启动数据库的权限;如果该用户是远程连接数据库的,那么就会提示输入口令。 ORACLE instance started. Total System Global Area 422670336 bytes Fixed Size 1336960 bytes Variable Size 318769536 bytes Database Buffers 96468992 bytes Redo Buffers 6094848 bytes Database mounted. Database opened.
Instance started是分配SGA,启动后台进程的过程:
启动时会将很多启动参数写入日志文件,如果启动过程中出现了问题,可以查看相关的日志文件。日志文件中的参数可以拷贝出来构造成一个新的parameterfile。
/*============下面来演示一下startup nomount的状态 ==============*/
[oracle@localhost ~]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.1.0 Production on Tue Sep 903:59:30 2014 Copyright (c) 1982, 2009, Oracle. All rights reserved.
SQL> conn /as sysdba
Connected to an idle instance.
[oracle@localhost dbs]$ ps -ef | grep oracle
oracle 1235112347 0 03:16 ? 00:00:00 sshd: oracle@pts/1 oracle 1235212351 0 03:16 pts/1 00:00:00 -bash oracle 1319712315 0 03:59 pts/0 00:00:00 sqlplus oracle 13198 13197 0 03:59 ? 00:00:00 oracleorcl(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) # 当前的数据库连接进程 oracle 13204 12352 0 04:00 pts/1 00:00:00 ps -ef oracle 13205 12352 0 04:00 pts/1 00:00:00 greporacle
[oracle@localhost dbs]$ ipcs
# 查看ipcs会发现此时SGA是空的 ------ Shared MemorySegments -------- key shmid owner perms bytes nattch status ------ Semaphore Arrays-------- key semid owner perms nsems ------ Message Queues-------- key msqid owner perms used-bytes messages
SQL> startup nomount
--以nomount的模式启动 ORACLE instance started. Total System GlobalArea 422670336 bytes Fixed Size 1336960 bytes Variable Size 318769536 bytes Database Buffers 96468992 bytes Redo Buffers 6094848 bytes
[oracle@localhost dbs]$ ps -ef | grep oracle
oracle 13197 12315 0 03:59 pts/0 00:00:00sqlplus oracle 13286 1 0 04:04 ? 00:00:00 ora_pmon_orcl oracle 13288 1 1 04:04 ? 00:00:00 ora_vktm_orcl oracle 13292 1 0 04:04 ? 00:00:00 ora_gen0_orcl oracle 13294 1 0 04:04 ? 00:00:00 ora_diag_orcl oracle 13296 1 0 04:04 ? 00:00:00 ora_dbrm_orcl oracle 13298 1 0 04:04 ? 00:00:00 ora_psp0_orcl oracle 13300 1 0 04:04 ? 00:00:00 ora_dia0_orcl oracle 13302 1 0 04:04 ? 00:00:00 ora_mman_orcl oracle 13304 1 0 04:04 ? 00:00:00 ora_dbw0_orcl oracle 13306 1 0 04:04 ? 00:00:00 ora_lgwr_orcl oracle 13308 1 0 04:04 ? 00:00:00 ora_ckpt_orcl oracle 13310 1 0 04:04 ? 00:00:00 ora_smon_orcl oracle 13312 1 0 04:04 ? 00:00:00 ora_reco_orcl oracle 13314 1 0 04:04 ? 00:00:00 ora_mmon_orcl oracle 13316 1 0 04:04 ? 00:00:00 ora_mmnl_orcl oracle 13318 1 0 04:04 ? 00:00:00 ora_d000_orcl oracle 13320 1 0 04:04 ? 00:00:00 ora_s000_orcl # Oracle的后台进程都已经启动了 oracle 13323 13197 0 04:04 ? 00:00:00oracleorcl (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) oracle 13347 12352 0 04:05 pts/1 00:00:00 ps -ef oracle 13348 12352 0 04:05 pts/1 00:00:00 greporacle
[oracle@localhost dbs]$ ipcs
------ Shared MemorySegments -------- key shmid owner perms bytes nattch status 0x85abc748 425984 oracle 660 4096 0 # 再次查看ipcs的资源,会发现SGA已经分配好了 ------ Semaphore Arrays-------- key semid owner perms nsems 0x974edfd4 983042 oracle 660 154 ------ Message Queues-------- key msqid owner perms used-bytes messages
/*=========已经可以查看到数据库的部分信息了=========*/
SQL> show parameter db_nam
NAME TYPE VALUE ----------------------------------------------- ------------------------------ db_name string orcl
SQL> show parameter db_block_size
NAME TYPE VALUE ----------------------------------------------- ------------------------------ db_block_size integer 8192
Mount的过程就是将实例和数据库建立关联的过程,要mount数据库,首先要找到并打开control files,这个查找的路径由初始化参数中CONTROL_FILES指定。Mount时会读取controlfiles中数据库的name和redo log files等相关信息。
这个阶段数据库仍然是关闭状态,普通用户不能访问数据库,只有管理员可以对数据库做一些维护工作,如备份和恢复等。
===================演示mount数据库的过程========================
[oracle@localhostdbs]$ strings spfileorcl.ora | more
orcl.__shared_pool_size=159383552 orcl.__streams_pool_size=4194304 *.audit_file_dest=‘/oracle/admin/orcl/adump‘ *.control_files=‘/oracle/oradata/orcl/control01.ctl‘,‘/oracle/flash_recovery_area/orcl/control02.ctl‘ # 启动项中规定的control files文件的路径 *.db_block_size=8192 *.db_domain=‘‘ *.db_name=‘orcl‘
SQL> alter database mount;
--Mount数据库 Database altered.
此阶段control files中指定的文件如redolog 或联机数据文件等都会打开;普通用户已经可以连接数据库了。
但是在上一次关闭数据库之前就已经处于offline状态的tablespace,此时仍然处于offline状态,如果要使其变成online状态,需要使用相应的启动命令。
如果某些数据文件或redo log files有错误,而导致数据库无法正常打开,那么需要先将数据库调整为mount状态,然后进行一些恢复工作。
SQL> alter database open;
Database altered.
注意,数据库的启动过程是单向的,即只能从mount到open,但不能从mount到nomount。
[oracle@localhost ~]$sqlplus /nolog
SQL*Plus: Release11.2.0.1.0 Production on Tue Sep 9 04:38:48 2014 Copyright (c) 1982, 2009,Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idleinstance.
SQL> startup mount;
ORACLE instance started. Total System GlobalArea 422670336 bytes Fixed Size 1336960 bytes Variable Size 318769536 bytes Database Buffers 96468992 bytes Redo Buffers 6094848 bytes Database mounted.
SQL> alter databasenomount;
alter database nomount * ERROR at line 1: ORA-02231: missing orinvalid option to ALTER DATABASE -- 不能从mount到nomount状态
SQL> alter database open;
Database altered. -- 但是可以由mount到open状态
本文出自 “重剑无锋 大巧不工” 博客,请务必保留此出处http://wuyelan.blog.51cto.com/6118147/1553541
原文地址:http://wuyelan.blog.51cto.com/6118147/1553541