天天看點

【ORA-16196】一個執行個體在其生命周期裡最多隻能裝載和打開一個資料庫

<a href="http://space.itpub.net/519536/viewspace-617382">http://space.itpub.net/519536/viewspace-617382</a>

"ORA-16196: database has been previously opened and closed"

這個報錯的原因是什麼呢?

原因是:

要想再打開此資料庫,必須先停掉這個執行個體再重新啟動資料庫。

ora10g@secDB /home/oracle$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.3.0 - Production on Sun Oct 25 23:07:57 2009

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

Connected to:

Edition Release 10.2.0.3.0 - 64bit Production

With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

sys@ora10g&gt; shutdown immediate;

Database closed.

Database dismounted.

ORACLE instance shut down.

sys@ora10g&gt; startup;

ORACLE instance started.

Total System Global Area 2147483648 bytes

Fixed Size                  2074152 bytes

Variable Size             637536728 bytes

Database Buffers         1493172224 bytes

Redo Buffers               14700544 bytes

Database mounted.

Database opened.

sys@ora10g&gt;

2.在資料庫啟動成功之後,我們通過v$database視圖和v$instance視圖檢視一下目前資料庫的狀态,以便和close後的狀态進行比較

sys@ora10g&gt; select open_mode from v$database;

OPEN_MODE

----------

READ WRITE

sys@ora10g&gt; select status from v$instance;

STATUS

------------

OPEN

可以看到現在的資料庫狀态是open并且是可讀寫操作的狀态。

3.此時我們使用“alter database close;”指令關閉資料庫(注意這裡我的用詞,關閉的是“資料庫”不是“執行個體”)

執行這個指令需要等待一段時間才能完成,存在一個資料庫連接配接清理的過程。如果在Oracle 9i的環境下使用這個close指令,若資料庫中存在其他的連接配接,指令将無法完成,會收到“ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected”報錯資訊,這裡的示範環境時10g,在10g中即使是存在着其他的連接配接也同樣可以完成close過程。

sys@ora10g&gt; alter database close;

Database altered.

4.再次查詢v$database視圖和v$instance視圖中有關資料庫狀态的資訊,與上面的資訊進行比較

MOUNTED

可以看到,此時資料庫的狀态已經變為“MOUNTED”的狀态。

進一步檢查一下此時資料庫伺服器有關該執行個體的背景資料庫程序資訊。通過下面的結果資訊可以進一步确信,“alter database close;”操作并沒有将資料庫的執行個體關閉,僅僅是将資料庫的狀态從“OPEN”狀态帶到了“MOUNT”狀态

sys@ora10g&gt; !ps -ef | grep 'ora_.*ora10g' | grep -v grep

oracle     867     1  0 22:31 ?        00:00:00 ora_pmon_ora10g

oracle     869     1  0 22:31 ?        00:00:00 ora_psp0_ora10g

oracle     871     1  0 22:31 ?        00:00:00 ora_mman_ora10g

oracle     873     1  0 22:31 ?        00:00:00 ora_dbw0_ora10g

oracle     875     1  0 22:31 ?        00:00:00 ora_dbw1_ora10g

oracle     877     1  0 22:31 ?        00:00:00 ora_lgwr_ora10g

oracle     879     1  0 22:31 ?        00:00:00 ora_ckpt_ora10g

oracle     881     1  0 22:31 ?        00:00:00 ora_smon_ora10g

oracle     883     1  0 22:31 ?        00:00:00 ora_reco_ora10g

oracle     887     1  0 22:31 ?        00:00:00 ora_mmon_ora10g

oracle     889     1  0 22:31 ?        00:00:00 ora_mmnl_ora10g

5.既然資料庫的狀态現在是mount狀态,我們嘗試使用open指令重新開啟該資料庫。結果很顯然,在這樣的狀态下,我們是無法再次open該資料庫的。

sys@ora10g&gt; alter database open;

alter database open

*

ERROR at line 1:

ORA-16196: database has been previously opened and closed

6.使用oerr工具檢視一下“ORA-16196”報錯資訊含義。從原因資訊描述中可以非常清晰的得到具體的原因和後續的處理方法。

sys@ora10g&gt; ! oerr ora 16196

16196, 00000, "database has been previously opened and closed"

// *Cause:  The instance has already opened and closed the database,

//          which is allowed only once in its lifetime.

// *Action: Shut down the instance.

7.此時如果想要重新使用該資料庫,隻有按照上面提示資訊中“Action:”部分描述的操作:關閉資料庫并重新開啟。

ORA-01109: database not open

sys@ora10g&gt; startup ;

OK,到此,資料庫又一個嶄新的生命周期開始了。

8.小結

通過上面的示範,大家應該對“一個執行個體在其生存期中最多隻能裝載和打開一個資料庫。”這句話有了一個更加具體的了解。其實Oracle資料庫的每一個狀态都很值得認真研究,其中充滿了N多令人神往的細節。

Good luck.

-- The End --