热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Oracle基础篇数据库启动

2019独角兽企业重金招聘Python工程师标准###1.启动OracleDB实例SyntaxSTARTUPoptions|upgrade_optionsoptionssy

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

###1. 启动Oracle DB 实例

此处输入图片的描述

Syntax
STARTUP options | upgrade_optionsoptions syntax:
[FORCE] [RESTRICT] [PFILE=filename] [QUIET] [ MOUNT [dbname] | [ OPEN [open_options] [dbname] ] | NOMOUNT ]open_options syntax:
READ {ONLY | WRITE [RECOVER]} | RECOVERupgrade_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@tonytestSQL*Plus: Release 11.2.0.2.0 Production on Tue May 26 05:21:01 2015Copyright (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 optionSQL> select count(*) from employees;COUNT(*)
----------109SQL> 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#######################
Shutting down instance (abort)

Instance shutdown complete
####################startup normal#######################
Starting ORACLE instance (normal)
ALTER DATABASE MOUNT
ALTER DATABASE OPEN
####################performs recovery automatically#######################
Beginning crash recovery of 1 threads
read 193 KB redo, 84 data blocks need recovery
Recovery of Online Redo Log: Thread 1 Group 2 Seq 2697 Reading mem 0


####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@tonytestSQL*Plus: Release 11.2.0.2.0 Production on Tue May 26 05:55:42 2015Copyright (c) 1982, 2010, Oracle. All rights reserved.ERROR:
ORA-12526: TNS:listener: all appropriate instances are in restricted modeSQL> alter system disable restricted session;System altered.[root@hzvscmdb alert]# sqlplus hr/pass@tonytestSQL*Plus: Release 11.2.0.2.0 Production on Tue May 26 08:14:38 2015Copyright (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.oraSQL> 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.


转:https://my.oschina.net/wangbinbin0326/blog/420260



推荐阅读
author-avatar
zmhua123_681
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有