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




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章