相对于数据库的启动,关闭数据库的操作同样有三个步骤:关闭数据库、卸载数据库、终止实例。

1、关闭数据库

当关闭数据库时,Oracle将会将重做日志高速缓存中的内容写入重做日志文件,并且将数据库高速缓存中被改动过得数据写入数据文件中,在数据文件中执行一个检查点,即记录下数据库关闭的时间,然后再关闭所有的数据文件和重做日志文件(当然这些在警告日志中看不到)。这时数据库的控制文件仍处于打开状态,但是由于数据库已经处于关闭状态,所以用户将无法访问数据库。

SYS@oracle>alter database close;

Database altered.

警告日志(Alert Log)实时监控:

[oracle@oracle trace]$ tail -f alert_oracle.log

alter database close

Warning: ALTER DATABASE CLOSE is not a publicly supported command.

Thu Sep 10 08:49:50 2015

Stopping background process CJQ0–停止协调程序进程

Thu Sep 10 08:49:50 2015

SMON: disabling tx recovery

Stopping background process QMNC–停止队列监视器进程

Stopping Job queue slave processes, flags = 27

Waiting for Job queue slaves to complete–等待作业队列系统完成

Job queue slave processes stopped

All dispatchers and shared servers shutdown–所有的调度程序和共享服务器关闭

CLOSE: killing server sessions.–杀死服务器回话

CLOSE: all sessions shutdown successfully.–所有会话成功关闭

SMON: disabling cache recovery–系统监视器进程:禁用缓存恢复

Thu Sep 10 08:49:54 2015

Shutting down archive processes

Archiving is disabled

Archive process shutdown avoided: 0 active

Thread 1 closed at log sequence 6

Successful close of redo thread 1–成功关闭一个日志线程

Completed: alter database close

由以上日志可以看出,当关闭数据库时,无法看到数据文件和控制文件的状况,但是可以从警告日志中看出一些服务于数据库的进程服务被关闭,如协调程序进程CJQ0、队列监视器QMNC等。

2、卸载数据库

关闭数据库后,实例才能卸载数据库,并在控制文件中更改相关的项目,然后关闭控制文件,但是实例仍然还在。

SYS@oracle>alter database dismount;

Database altered.

告警日志:

Thu Sep 10 08:50:58 2015

idle dispatcher ‘D000’ terminated, pid = (17, 1)–闲置调度D000终止

Thu Sep 10 10:06:00 2015

alter database dismount

Shutting down archive processes

Archiving is disabled

Completed: alter database dismount

由日志显示可知,关闭了闲置的调度程序,数据库卸载成功。

3、关闭实例

上述两步完成后接下来的操作便是终止实例了,实例所拥有的所有后台进程和服务进程将被终止(由下面实时日志可以看出),分配给实例的内存SGA区和PGA区被回收。

SYS@oracle>shutdown

ORA-01507: database not mounted

ORACLE instance shut down.

告警日志:

Thu Sep 10 10:08:22 2015

Shutting down instance (normal)

Shutting down instance: further logons disabled–进一步禁用登录

Stopping background process MMNL–停止轻量可管理性监视器进程

Stopping background process MMON–停止可管理性监视器进程

License high water mark = 3

All dispatchers and shared servers shutdown–所有的调度程序和共享服务器关闭

ALTER DATABASE CLOSE NORMAL

ORA-1507 signalled during: ALTER DATABASE CLOSE NORMAL…

ARCH: Archival disabled due to shutdown: 1090

Shutting down archive processes

Archiving is disabled

Thu Sep 10 10:08:25 2015

Stopping background process VKTM

ARCH: Archival disabled due to shutdown: 1090

Shutting down archive processes

Archiving is disabled

Thu Sep 10 10:08:27 2015

Instance shutdown complete–实例关闭完成