您的位置:首页 > 数据库 > Oracle

Oracle 数据库关闭 之 使用TRANSACTIONAL选项关闭数据库

2012-02-03 18:23 886 查看
问:如何用NORMAL选项关闭数据库?
答:使用shutdown transactional命令!

场景一:在执行shutdown transactional命令的时候,是否还可以有新的用户连接到数据库?

会话一:

SQL> startup
ORACLE instance started.

Total System Global Area  236000356 bytes
Fixed Size                   451684 bytes
Variable Size             201326592 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.
再运行以下语句:
SQL> shutdown transactional
同时,在会话二,新连接一个用户到数据库,执行以下语句:
SQL> conn scott/tiger
此时,会产生如下结果:

会话一:

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

会话二:

SQL> conn scott/tiger
ERROR:
ORA-01089: immediate shutdown in progress - no operations are permitted

结论:在执行shutdown transactional命令之后,不允许有新的用户连接到数据库。

场景二:在执行shutdown
transactional命令的时候,假设用户scott执行DDL语句,请问是否会执行成功?

会话一:

SQL> startup
ORACLE instance started.

Total System Global Area  236000356 bytes
Fixed Size                   451684 bytes
Variable Size             201326592 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.
会话二:
SQL> conn scott/tiger
Connected

会话一:

SQL> shutdown transactional

同时,在会话二,执行以下DDL语句:

SQL> create table t (x number);
此时,会产生如下结果:
会话一:

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

会话二:

SQL> conn scott/tiger
ERROR:
ORA-01089: immediate shutdown in progress - no operations are permitted
结论:在执行shutdown transactional命令之后,所有连接到数据库的用户执行的DDL语句都无效。

场景三:在执行shutdown
transactional命令的时候,假设用户scott执行DML语句,启动新的事务,请问是否会执行成功?

会话一:

SQL> startup
ORACLE instance started.

Total System Global Area  236000356 bytes
Fixed Size                   451684 bytes
Variable Size             201326592 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.

会话二:

SQL> conn scott/tiger
Connected
SQL> create table t(x number);

Table created.

会话一:

SQL> shutdown transactional
同时,在会话二,执行以下DML语句:

SQL> insert into t values(1);
此时,会产生如下结果:
会话一:

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

会话二:

SQL> insert into t values(1);
insert into t values(1)
*
ERROR at line 1:
ORA-01089: immediate shutdown in progress - no operations are permitted
结论:在执行shutdowntransactional命令之后,不允许启动新的事务。

场景四:在执行shutdown transactional命令的时候,假设用户scott执行Insert语句,事务没有提交,请问是否会自动提交还是会回滚?

会话一:

SQL> startup
ORACLE instance started.

Total System Global Area  236000356 bytes
Fixed Size                   451684 bytes
Variable Size             201326592 bytes
Database Buffers           33554432 bytes
Redo Buffers                 667648 bytes
Database mounted.
Database opened.
会话二:
SQL> conn scott/tiger
Connected.
SQL> create table t(x number);

Table created.

SQL> insert into t values(1);

1 row created.

此时,会话一一直处于等待状态,直到会话二提交事务之后,会话一才会关闭数据库。

结论:在执行shutdown transactional命令之后,在完成所有事务后,任何一个仍连接到实例的客户都将被解除连接。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: