shutdown immediate

Immediate database shutdown proceeds with the following conditions:
■ No new connections are allowed, nor are new transactions allowed to be started, after the statement is issued.
Any uncommitted transactions are rolled back. (If long uncommitted transactions exist, this method of shutdown might not complete quickly, despite its name.)
■ Oracle Database does not wait for users currently connected to the database to disconnect. The database implicitly rolls back active transactions and disconnects all connected users.

这里的“Any uncommitted transactions are rolled back”指的是非当前session的transaction,若当前的transaction未提交,则是不允许shutdown的。
测试如下:
----------测试在非当前session中有未提交的事务
1. sysdba用户启动数据库-----session1
SQL> startup
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  1218968 bytes
Variable Size             142607976 bytes
Database Buffers          134217728 bytes
Redo Buffers                7168000 bytes
Database mounted.
Database opened.



2. 更新scott用户下的feng_test2表   -----session2
[oracle@redhat5 ~]$ sqlplus scott/tiger
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Sep 11 11:10:48 2013
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> update feng_test2 set age = 100 where name = 'guo';
1 row updated.



3. 在session1中进行关闭数据库
SQL> startup
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  1218968 bytes
Variable Size             142607976 bytes
Database Buffers          134217728 bytes
Redo Buffers                7168000 bytes
Database mounted.
Database opened.
SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.


成功关闭

4. 再次打开数据库,查看feng_test2表的数据
[oracle@redhat5 ~]$ sqlplus scott/tiger
SQL*Plus: Release 10.2.0.1.0 - Production on Wed Sep 11 11:14:56 2013
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> select * from feng_test2 where name = 'guo';
NAME              AGE
---------- ----------
guo                10


所做的修改确实回滚了。

-----下面测试在当前session下有未提交的事务
SQL> startup
ORACLE instance started.
Total System Global Area  285212672 bytes
Fixed Size                  1218968 bytes
Variable Size             142607976 bytes
Database Buffers          134217728 bytes
Redo Buffers                7168000 bytes
Database mounted.
Database opened.
SQL> update scott.feng_test2 set  age = 100 where name = 'guo';
1 row updated.
SQL> shutdown immediate
ORA-01097: cannot shutdown while in a transaction - commit or rollback first




猜你喜欢

转载自blog.csdn.net/ice2000feng/article/details/11557419
今日推荐