Oracle 数据库启动和关闭步骤

1.前言

本文将介绍Oracle数据库的启动和关闭模式

2. Oracle 数据库的启动模式

封闭的Oracle数据库分三个阶段打开。最好的总结如下图:

在这里插入图片描述

2.1 Nomount model

当我们以Nomount 模式打开 Oracle 数据库时,实例和后台进程启动。Oracle在这一步读取参数文件(spfile或pfile)。在这种模式下,数据库对其他用户关闭,只有实例和后台进程是打开的。

bash-4.1$ ps -ef | grep smon
oracle 20114 19577 0 14:15 pts/0 00:00:00 grep smon
bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:15:10 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area 534462464 bytes
Fixed Size 2230072 bytes
Variable Size 339740872 bytes
Database Buffers 184549376 bytes
Redo Buffers 7942144 bytes
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
bash-4.1$ ps -ef | grep smon
oracle 20143 1 0 14:15 ? 00:00:00 ora_smon_TESTDB
oracle 20160 19577 0 14:15 pts/0 00:00:00 grep smon
bash-4.1$ ps -ef | grep ckpt
oracle 20141 1 0 14:15 ? 00:00:00 ora_ckpt_TESTDB
oracle 20162 19577 0 14:15 pts/0 00:00:00 grep ckpt
bash-4.1$ ps -ef | grep lgwr
oracle 20139 1 0 14:15 ? 00:00:00 ora_lgwr_TESTDB
oracle 20166 19577 0 14:16 pts/0 00:00:00 grep lgwr


bash-4.1$ ps -ef | grep smon
oracle 20114 19577 0 14:15 pts/0 00:00:00 grep smon
bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:15:10 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup nomount
ORACLE instance started.

Total System Global Area 534462464 bytes
Fixed Size 2230072 bytes
Variable Size 339740872 bytes
Database Buffers 184549376 bytes
Redo Buffers 7942144 bytes
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
bash-4.1$ ps -ef | grep smon
oracle 20143 1 0 14:15 ? 00:00:00 ora_smon_TESTDB
oracle 20160 19577 0 14:15 pts/0 00:00:00 grep smon
bash-4.1$ ps -ef | grep ckpt
oracle 20141 1 0 14:15 ? 00:00:00 ora_ckpt_TESTDB
oracle 20162 19577 0 14:15 pts/0 00:00:00 grep ckpt
bash-4.1$ ps -ef | grep lgwr
oracle 20139 1 0 14:15 ? 00:00:00 ora_lgwr_TESTDB
oracle 20166 19577 0 14:16 pts/0 00:00:00 grep lgwr

2.2 Mount Mode

控制文件在此步骤中打开。当数据库打开并读取控制文件时,它会知道数据文件和存档文件在哪里。但是,在这一步中,用户仍然无法访问数据库。只能访问系统视图和性能视图。

我们可以在 Nomount 模式下 mount 一个数据库,如下所示。

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:24:15 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select open_mode from v$database;
select open_mode from v$database
*
ERROR at line 1:
ORA-01507: database not mounted

SQL> alter database mount;

Database altered.
SQL> select open_mode from v$database;

OPEN_MODE
--------------------
MOUNTED


bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:24:15 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select open_mode from v$database;
select open_mode from v$database
*
ERROR at line 1:
ORA-01507: database not mounted

SQL> alter database mount;

Database altered.
SQL> select open_mode from v$database;

OPEN_MODE
--------------------
MOUNTED

或者我们可以直接mount一个关闭的数据库,如下所示。

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 15:06:58 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area 534462464 bytes
Fixed Size 2230072 bytes
Variable Size 339740872 bytes
Database Buffers 184549376 bytes
Redo Buffers 7942144 bytes
Database mounted.
SQL>

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 15:06:58 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup mount
ORACLE instance started.

Total System Global Area 534462464 bytes
Fixed Size 2230072 bytes
Variable Size 339740872 bytes
Database Buffers 184549376 bytes
Redo Buffers 7942144 bytes
Database mounted.
SQL>

2.3 Open Mode

打开模式:该模式下,数据库正常打开,其他用户可以访问。我们可以直接在 Open 模式下启动一个关闭的数据库,如下所示。

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:29:41 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 534462464 bytes
Fixed Size 2230072 bytes
Variable Size 339740872 bytes
Database Buffers 184549376 bytes
Redo Buffers 7942144 bytes
Database mounted.
Database opened.
SQL>

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:29:41 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 534462464 bytes
Fixed Size 2230072 bytes
Variable Size 339740872 bytes
Database Buffers 184549376 bytes
Redo Buffers 7942144 bytes
Database mounted.
Database opened.
SQL>

即使我们直接在打开模式下打开一个关闭的数据库,上述操作都是在后台进行的。也就是说,数据库首先以nomount 模式打开,然后进入mount 模式,然后再打开。这发生得非常快。

我们可以将处于 Mount 模式的数据库变为 Open 模式,如下所示。

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:32:06 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
MOUNTED

SQL> alter database open;

Database altered.

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:32:06 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select open_mode from v$database;

OPEN_MODE
--------------------
MOUNTED

SQL> alter database open;

Database altered.

3.Oracle 数据库关闭模式

Oracle 为我们提供了 5 种不同的数据库关闭方法。由于每种方法具有不同的功能,我们将在下面分别对其进行研究。

在这里插入图片描述
Shutdown immediate: 此方法是最优选的方法。因为数据库以健康且一致的方式关闭。执行此命令时,oracle 会回滚未提交的事务并执行关闭程序。命令的使用如下。

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:50:17 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:50:17 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

Shutdown Normal: 这种方法不是首选,但有时可能需要。当我们尝试用这种方法关闭数据库时,Oracle 会等待所有连接到数据库的用户完成他们的工作并关闭他们的会话。即使打开单个会话,数据库也不会关闭。命令的使用如下。

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:50:17 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:50:17 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

Shutdown Transactional:在这种方法中,Oracle 等待所有用户提交他们的事务。在 Commit 进程完成后,Oracle 终止该会话并继续关闭进程。此方法具有零数据丢失保证。命令的使用如下。

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:59:47 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 – 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown transactional;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>


bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:59:47 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown transactional;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>

Shutdown abort: 这个方法就像拔掉数据库一样。所有事务突然停止,数据库不一致关闭。虽然这种方法不是首选,但有时是非常必要的。例如,您正在执行一项非常关键的操作,时间对您来说非常重要,您需要关闭或重新启动数据库。如果以一致的方式关闭数据库需要很长时间,则可以使用此方法。命令的使用如下。

bash-4.1$ ps -ef | grep smon
oracle 20376 1 0 14:31 ? 00:00:00 ora_smon_TESTDB
oracle 20486 19577 0 14:45 pts/0 00:00:00 grep smon
bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:46:02 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown abort
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


bash-4.1$ ps -ef | grep smon
oracle 20490 19577 0 14:46 pts/0 00:00:00 grep smon
bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:46:23 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to an idle instance.

SQL>
bash-4.1$ ps -ef | grep smon
oracle 20376 1 0 14:31 ? 00:00:00 ora_smon_TESTDB
oracle 20486 19577 0 14:45 pts/0 00:00:00 grep smon
bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:46:02 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown abort
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
bash-4.1$ ps -ef | grep smon
oracle 20490 19577 0 14:46 pts/0 00:00:00 grep smon
bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 14:46:23 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to an idle instance.

SQL>

此外,还有一个强制重启命令。最后,我将解释这个命令。

Startup Force: 此命令在后台运行 Shutdown abort + Startup 命令。所以随着Shutdown abort,数据库突然关闭,然后启动和数据库以正常格式打开。命令的使用如下。

bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 15:03:47 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> startup force
ORACLE instance started.

Total System Global Area 534462464 bytes
Fixed Size 2230072 bytes
Variable Size 339740872 bytes
Database Buffers 184549376 bytes
Redo Buffers 7942144 bytes
Database mounted.
Database opened.
SQL>
bash-4.1$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Mon Oct 7 15:03:47 2013

Copyright (c) 1982, 2011, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> startup force
ORACLE instance started.

Total System Global Area 534462464 bytes
Fixed Size 2230072 bytes
Variable Size 339740872 bytes
Database Buffers 184549376 bytes
Redo Buffers 7942144 bytes
Database mounted.
Database opened.
SQL>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值