Oracle基础篇 --- 数据库启动
Oracle基础篇 --- 数据库启动
wangbinbin0326 发表于2年前
Oracle基础篇 --- 数据库启动
  • 发表于 2年前
  • 阅读 11
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 十分钟定制你的第一个小程序>>>   

摘要: Oracle基础篇 --- 数据库启动

###1. 启动Oracle DB 实例

此处输入图片的描述

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 模式下启动实例。

启动实例过程包括执行以下任务:

  • 按以下顺序搜索$ORACLE_HOME/dbs 中具有特定名称的文件:
  1. 搜索spfile.ora。
  2. 如果未找到spfile.ora,则搜索spfile.ora。
  3. 如果未找到spfile.ora,则搜索init.ora。 这是包含实例初始化参数的文件。使用STARTUP 指定PFILE 参数可覆盖默认行为。
  • 分配SGA。
  • 启动后台进程。
  • 打开alert_.log 文件和跟踪文件。

####1.2 MOUNT

数据库装载过程包括执行以下任务:

  • 将数据库与以前启动的实例关联。
  • 定位并打开参数文件中指定的控制文件。
  • 通过读取控制文件来获取数据文件和联机重做日志文件的名称和状态(但是,此时不会执行检查来验证是否存在数据文件和联机重做日志文件)。

要执行特定的维护操作,请启动实例,然后装载数据库,但不打开该数据库。例如,在执行以下任务期间必须装载数据库,但不得打开数据库:

  • 重命名数据文件(打开数据库时可重命名脱机表空间的数据文件)。
  • 启用和禁用联机重做日志文件归档选项。
  • 执行完整的数据库恢复。

注:即使发出了OPEN 请求,数据库仍可能处于MOUNT 模式下。这是因为可能需要以某种方式恢复数据库。如果在MOUNT 状态下执行恢复,将打开重做日志进行读取,并打开数据文件读取需要恢复的块,以及在恢复期间根据需要写入块。


####1.3 OPEN

打开数据库过程包括执行以下任务:

  • 打开数据文件。
  • 打开联机重做日志文件。

如果尝试打开数据库时任一数据文件或联机重做日志文件不存在,则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.

标签: oracle 启动 详解
共有 人打赏支持
粉丝 8
博文 39
码字总数 43554
×
wangbinbin0326
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: