首页 > 代码库 > 谈谈Oracle数据库的关闭
谈谈Oracle数据库的关闭
之前说过了Oracle数据库的启动,今天再来说说Oracle数据库的关闭。
一、数据库关闭的三个阶段
Oracle数据库启动过程包括三个步骤: NOMOUNT -> MOUNT -> OPEN,数据库的SHUTDOWN实际也是有三个步骤:CLOSE -> DISMOUNT - > SHUTDOWN。
SQL> SHUTDOWN;
Database closed.
Database dismounted.
ORACLE instance shut down.
Database dismounted.
ORACLE instance shut down.
也可从STARTUP状态,按照CLOSE -> DISMOUNT - > SHUTDOWN的顺序逐步关闭。
1、数据库关闭
命令:
SQL> alter database close;
Database altered.
Elapsed: 00:00:02.20
Database altered.
Elapsed: 00:00:02.20
告警日志(Alert Log):
Sat Nov 15 11:48:35 2014
alter database close
Warning: ALTER DATABASE CLOSE is not a publicly supported command.
Sat Nov 15 11:48:35 2014
Stopping background process CJQ0
Sat Nov 15 11:48:35 2014
SMON: disabling tx recovery
Stopping background process QMNC
All dispatchers and shared servers shutdown
CLOSE: killing server sessions.
CLOSE: all sessions shutdown successfully.
SMON: disabling cache recovery
Sat Nov 15 11:48:37 2014
Shutting down archive processes
Archiving is disabled
Sat Nov 15 11:48:37 2014
ARCH shutting down
ARC3: Archival stopped
Sat Nov 15 11:48:37 2014
ARCH shutting down
ARC2: Archival stopped
Sat Nov 15 11:48:37 2014
ARCH shutting down
ARC1: Archival stopped
Sat Nov 15 11:48:37 2014
ARCH shutting down
ARC0: Archival stopped
Thread 1 closed at log sequence 4
Successful close of redo thread 1
Completed: alter database close
alter database close
Warning: ALTER DATABASE CLOSE is not a publicly supported command.
Sat Nov 15 11:48:35 2014
Stopping background process CJQ0
Sat Nov 15 11:48:35 2014
SMON: disabling tx recovery
Stopping background process QMNC
All dispatchers and shared servers shutdown
CLOSE: killing server sessions.
CLOSE: all sessions shutdown successfully.
SMON: disabling cache recovery
Sat Nov 15 11:48:37 2014
Shutting down archive processes
Archiving is disabled
Sat Nov 15 11:48:37 2014
ARCH shutting down
ARC3: Archival stopped
Sat Nov 15 11:48:37 2014
ARCH shutting down
ARC2: Archival stopped
Sat Nov 15 11:48:37 2014
ARCH shutting down
ARC1: Archival stopped
Sat Nov 15 11:48:37 2014
ARCH shutting down
ARC0: Archival stopped
Thread 1 closed at log sequence 4
Successful close of redo thread 1
Completed: alter database close
2、数据库卸载
命令:
SQL> alter database dismount;
Database altered.
Elapsed: 00:00:00.05
Database altered.
Elapsed: 00:00:00.05
告警日志:
Sat Nov 15 11:49:40 2014
idle dispatcher ‘D000‘ terminated, pid = (17, 1)
Sat Nov 15 11:50:04 2014
alter database dismount
Shutting down archive processes
Archiving is disabled
Completed: alter database dismount
idle dispatcher ‘D000‘ terminated, pid = (17, 1)
Sat Nov 15 11:50:04 2014
alter database dismount
Shutting down archive processes
Archiving is disabled
Completed: alter database dismount
3、关闭数据库实例
命令:
SQL> shutdown;
ORA-01507: database not mounted
ORACLE instance shut down.
SQL>
ORA-01507: database not mounted
ORACLE instance shut down.
SQL>
告警日志:
Sat Nov 15 11:51:22 2014
Shutting down instance (normal)
Shutting down instance: further logons disabled
Stopping background process MMNL
Stopping background process MMON
License high water mark = 4
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
Sat Nov 15 11:51:25 2014
Stopping background process VKTM
ARCH: Archival disabled due to shutdown: 1090
Shutting down archive processes
Archiving is disabled
Sat Nov 15 11:51:27 2014
Instance shutdown complete
Shutting down instance (normal)
Shutting down instance: further logons disabled
Stopping background process MMNL
Stopping background process MMON
License high water mark = 4
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
Sat Nov 15 11:51:25 2014
Stopping background process VKTM
ARCH: Archival disabled due to shutdown: 1090
Shutting down archive processes
Archiving is disabled
Sat Nov 15 11:51:27 2014
Instance shutdown complete
二、数据库关闭的四种选项
1、SHUTDOWN NORMAL
这是数据库关闭SHUTDOWN命令的默认选项。也就是说如果你发出SHUTDOWN这样的命令,也即是SHUTDOWN NORNAL的意思。
发出该命令后,任何新的连接都将再不允许连接到数据库。在数据库关闭之前,Oracle将等待目前连接的所有用户都从数据库中退出后才开始关闭数据库。采用这种方式关闭数据库,在下一次启动时不需要进行任何的实例恢复。但是由于Normal方式要等所有用户断开连接后才能关闭数据库,所有等待时间可能超长;在生产环境中,这种方式几乎无法关闭有大量用户连接的数据库,所以很少被采用。
这是数据库关闭SHUTDOWN命令的默认选项。也就是说如果你发出SHUTDOWN这样的命令,也即是SHUTDOWN NORNAL的意思。
发出该命令后,任何新的连接都将再不允许连接到数据库。在数据库关闭之前,Oracle将等待目前连接的所有用户都从数据库中退出后才开始关闭数据库。采用这种方式关闭数据库,在下一次启动时不需要进行任何的实例恢复。但是由于Normal方式要等所有用户断开连接后才能关闭数据库,所有等待时间可能超长;在生产环境中,这种方式几乎无法关闭有大量用户连接的数据库,所以很少被采用。
2、SHUTDOWN IMMEDIATE
这是最为常用的一种关闭数据库的方式,使用这个命令时,当前正在被Oracle处理的事务立即中断,未提交的事务将全部回滚,系统不等待连接到数据库的用户退出,强制断开所有的连接用户。然后执行检查点,将变更数据全部写回数据文件,关闭数据库。使用这种方式关闭数据库,下次启动数据库时不需要进行实例恢复,是一种安全的数据库关闭方式。
3、SHUTDOWN TRANSACTIONAL
该选项仅在Oracle 8i后才可以使用。该命令常用来计划关闭数据库,它使当前连接到系统且正在活动的事务执行完毕,运行该命令后,任何新的连接和事务都是不允许的。在所有活动的事务完成后,数据库将和SHUTDOWN IMMEDIATE同样的方式关闭数据库。
最不推荐采用的数据库关闭方式,使用此选项,数据库会立即终止所有用户连接、中断所有事务、关闭数据库,使用这种方式关闭数据库,未完成事务不会回滚,数据库也不会执行检查点,所以下次启动市,数据库必须执行实例恢复,实例恢复可能会需要大量的时间,数据库启动也因此可能需要等候很长时间。
ABORT方式关闭数据库,就类似于数据库服务器突然断电,可能会导致不一致的情况出现,所以除非不得已,轻易不要使用这种方式关闭数据库。
参考:
谈谈Oracle数据库的启动
Remote DBA team- Oracle Database Startup & Shutdown Process
谈谈Oracle数据库的关闭
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。