天天看點

因host指令導緻無法正常SHUTDOWN的實驗

SHUTDOWN有幾個參數可以使用:

SHUTDOWN NORMAL:NORMAL也是預設的子句,執行的條件是

No new connections are allowed after the statement is issued.

Before the database is shut down, the database waits for all currently connectedusers to disconnect from

the database.

下次啟動時不需要任何執行個體恢複過程。

SHUTDOWN IMMEDIATE:執行的場景是

To initiate an automated and unattended backup.

When a power shutdown is going to occur soon.

When the database or one of its applications is functioning irregularly and youcannot contact users to ask

them to log off or they are unable to log off.

執行的條件是

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 transactionsexist, this method of shutdown might not complete quickly, despite its name.)

Oracle Database does not wait for users currently connected

to the database todisconnect. The database implicitly rolls back active transactions and disconnectsall connected users.

同樣地,下次啟動時不需要任何執行個體恢複過程。

SHUTDOWN

TRANSACTIONAL:執行的場景是需要進行例行的執行個體停止,但首先允許所有活動的交易完成,執行的條件是

After all transactions have completed, any client still

connected to the instance isdisconnected.

At this point, the instance shuts down just as it would

when a SHUTDOWNIMMEDIATE statement is submitted.

這種關閉操作不會讓用戶端丢失任務,同時不要求所有使用者退出。

ABORT:執行的場景是

You need to shut down the database instantaneously (for

example, if you know apower shutdown is going to occur in one minute).

You experience problems when starting a database instance.

Current client SQL statements being processed by Oracle Database areimmediately terminated.

Uncommitted transactions are not rolled back.

Oracle Database does not wait for users currently connected to the database todisconnect. The database implicitly

disconnects all connected users.

下次啟動時将需要執行個體恢複過程。

可以看出ABORT是一種暴力的關閉,不會隐式地復原交易,由于仍存在髒塊,是以下次啟動時需要進行執行個體恢複。

實驗:

1. 執行shutdown normal指令關閉資料庫

SQL> shutdown normal

因host指令導緻無法正常SHUTDOWN的實驗

發現提示SHUTDOWN: waiting for logins to complete.

從上面的介紹看,使用shutdown normal的方式關閉資料庫,不允許新連接配接接入,同時需要所有已連接配接的用戶端斷開後,才能繼續正常關閉。懷疑此處可能存在仍未斷開的連接配接。

使用kill -9 7255仍不起作用。

2. 執行shutdown immediate指令關閉資料庫

于是直接CTRL+C中斷shutdown

normal,然後使用shutdown immediate指令關閉資料庫

SQL>shutdown

immediate

因host指令導緻無法正常SHUTDOWN的實驗

此時提示SHUTDOWN:

Active processes prevent shutdown operation

MOS上有篇文章(416658.1)專門介紹了immediate出現這種報錯的問題,給出的原因是:

“If

the DB Control repository is running on the database target against which shutdown immediate was attempted then an incorrect order of events seems used.You should stop DB Control first to get rid of all connections

between DB Control and the repository database and then shutdown the database with 'shutdown immediate'.”

意思是說可能DB

Control庫正在執行一些事件,需要停止DB Control避免所有DB Control和庫之間的連接配接,然後才能執行shutdown immediate關閉,但這裡我沒有這樣可能的操作,應該是沒有普通使用者未執行exit的場景,想一想,原來之前使用SYS登入後用過host切換到OS下,但并未切回退出,是以可能由于這樣的問題,導緻shutdown immediate出現hang的情況。

3.

執行shutdown abort指令關閉資料庫

按照MOS的說法,使用

SQL>

shutdown abort   直接關閉

startup restrict     允許具有restrict session權限的使用者才能登陸,換句話,避免使用者再登陸導緻無法正常關閉

shutdown normal 執行normal正常關閉

因host指令導緻無法正常SHUTDOWN的實驗

此時一切都安靜了。

總結:

1.

非到萬不得已盡量不要使用ABORT,誰知道會出現什麼詭異的事情。

2.

執行關閉前,建議斷開所有使用SYS連接配接的會話,特别是使用host切換OS的連接配接,可能會不注意,這點是教訓。