oracle8i誤刪除臨時表空間後的恢復

流浪的野狼發表於2013-06-21

事故原因如下:
今天早上檢視錶空間利用率時發現一oracle8i資料庫當機了操作完後過段時間導致資料庫當機。查詢警告日誌發現大量的關於資料檔案的臨時讀取錯誤。

原來一同事因磁碟空間達到95%,去清理臨時資料和log時,錯誤的執行了如下命令,清空了臨時資料檔案。

cat /dev/null > /opt/oracle/oradata/openview/OPC_TEMP_1.dbf
cat /dev/null > /opt/oracle/oradata/openview/OPC_TEMP_1.dbf
cat /dev/null > /opt/oracle/oradata/openview/OPC_TEMP_1.dbf

之後我在啟動資料庫的時候報錯如下:

Starting ORACLE instance (normal)
LICENSE_MAX_SESSION = 0
LICENSE_SESSIONS_WARNING = 0
LICENSE_MAX_USERS = 0
Starting up ORACLE RDBMS Version: 8.1.7.0.0.
System parameters with non-default values:
  processes                = 50
  shared_pool_size         = 120000000
  control_files            = /opt/oracle/oradata/openview/control01.ctl, /opt/oracle/oradata/openview/control02.ctl, /opt/oracle/oradata/openview/control03.ctl
  db_block_buffers         = 550
  db_block_size            = 8192
  compatible               = 8.1.7.0.0
  log_archive_start        = FALSE
  log_archive_dest         = /opt/oracle/admin/openview/arch
  log_archive_format       = T%TS%S.ARC
  log_buffer               = 65536
  log_checkpoint_interval  = 99999
  db_files                 = 50
  db_file_multiblock_read_count= 8
  dml_locks                = 100
  rollback_segments        = r01, r02, r03, r04
  remote_os_authent        = TRUE
  db_name                  = openview
  open_cursors             = 500
  os_authent_prefix        =
  background_dump_dest     = /opt/oracle/admin/openview/bdump
  user_dump_dest           = /opt/oracle/admin/openview/udump
  max_dump_file_size       = 10240
  core_dump_dest           = /opt/oracle/admin/openview/cdump
PMON started with pid=2
DBW0 started with pid=3
LGWR started with pid=4
CKPT started with pid=5
SMON started with pid=6
RECO started with pid=7
Fri Jun 21 08:18:51 2013
ALTER DATABASE   MOUNT
Fri Jun 21 08:18:55 2013
Successful mount of redo thread 1, with mount id 2788845359.
Fri Jun 21 08:18:55 2013
Database mounted in Exclusive Mode.
Completed: ALTER DATABASE   MOUNT
Fri Jun 21 08:18:55 2013
ALTER DATABASE OPEN
Fri Jun 21 08:18:55 2013
Errors in file /opt/oracle/admin/openview/udump/ora_10395_openview.trc:
ORA-01110: data file 5: '/opt/oracle/oradata/openview/OPC_TEMP_1.dbf'
ORA-01115: IO error reading block from file 5 (block # 1)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
Additional information: 1
Additional information: 1
ORA-01110: data file 2: '/opt/oracle/oradata/openview/temp_1.dbf'
ORA-01115: IO error reading block from file 2 (block # 1)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
Additional information: 1
Additional information: 1
Fri Jun 21 08:18:55 2013
Errors in file /opt/oracle/admin/openview/udump/ora_10395_openview.trc:
ORA-01110: data file 21: '/opt/oracle/oradata/openview/OPC_TEMP_2.dbf'
ORA-01115: IO error reading block from file 21 (block # 1)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
Additional information: 1
Additional information: 1
ORA-01110: data file 2: '/opt/oracle/oradata/openview/temp_1.dbf'
ORA-01115: IO error reading block from file 2 (block # 1)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
Additional information: 1
Additional information: 1
ORA-1110 signalled during: ALTER DATABASE OPEN...
Fri Jun 21 08:20:09 2013
重新執行:
alter database open
Fri Jun 21 08:20:31 2013
Errors in file /opt/oracle/admin/openview/udump/ora_10401_openview.trc:
ORA-01110: data file 5: '/opt/oracle/oradata/openview/OPC_TEMP_1.dbf'
ORA-01115: IO error reading block from file 5 (block # 1)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
Additional information: 1
Additional information: 1
ORA-01110: data file 2: '/opt/oracle/oradata/openview/temp_1.dbf'
ORA-01115: IO error reading block from file 2 (block # 1)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
Additional information: 1
Additional information: 1
Fri Jun 21 08:20:31 2013
Errors in file /opt/oracle/admin/openview/udump/ora_10401_openview.trc:
ORA-01110: data file 21: '/opt/oracle/oradata/openview/OPC_TEMP_2.dbf'
ORA-01115: IO error reading block from file 21 (block # 1)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
Additional information: 1
Additional information: 1
ORA-01110: data file 2: '/opt/oracle/oradata/openview/temp_1.dbf'
ORA-01115: IO error reading block from file 2 (block # 1)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
Additional information: 1
Additional information: 1
ORA-1110 signalled during: alter database open
...
select status,instance_name from v$instance;
發現資料庫在mounted狀態下,仍然無法正常啟動。
recover database;也不行。

最後確定清空的資料檔案及所在表空間後做如下操作:

alter database datafile '/opt/oracle/oradata/openview/temp_1.dbf' offline drop
Fri Jun 21 08:56:45 2013
Completed: alter database datafile '/opt/oracle/oradata/openv
Fri Jun 21 08:57:02 2013
alter database open
Fri Jun 21 08:57:02 2013
Errors in file /opt/oracle/admin/openview/udump/ora_19584_openview.trc:
ORA-01110: data file 21: '/opt/oracle/oradata/openview/OPC_TEMP_2.dbf'
ORA-01115: IO error reading block from file 21 (block # 1)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
Additional information: 1
Additional information: 1
ORA-01110: data file 5: '/opt/oracle/oradata/openview/OPC_TEMP_1.dbf'
ORA-01115: IO error reading block from file 5 (block # 1)
ORA-27069: skgfdisp: attempt to do I/O beyond the range of the file
Additional information: 1
Additional information: 1
Fri Jun 21 08:57:02 2013
ORA-1110 signalled during: alter database open
...
Fri Jun 21 08:57:50 2013
alter database datafile '/opt/oracle/oradata/openview/OPC_TEMP_1.dbf' offline drop
Fri Jun 21 08:57:50 2013
Completed: alter database datafile '/opt/oracle/oradata/openv
Fri Jun 21 08:58:00 2013
alter database open
ORA-1110 signalled during: alter database open
...
Fri Jun 21 08:58:24 2013
alter database datafile '/opt/oracle/oradata/openview/OPC_TEMP_2.dbf' offline drop
Fri Jun 21 08:58:24 2013
Completed: alter database datafile '/opt/oracle/oradata/openv
Fri Jun 21 08:58:33 2013
alter database open
Beginning crash recovery of 1 threads
Fri Jun 21 08:58:33 2013
Thread recovery: start rolling forward thread 1
Recovery of Online Redo Log: Thread 1 Group 1 Seq 93032 Reading mem 0
  Mem# 0 errs 0: /opt/oracle/oradata/openview/redo01.log
Recovery of Online Redo Log: Thread 1 Group 2 Seq 93033 Reading mem 0
  Mem# 0 errs 0: /opt/oracle/oradata/openview/redo02.log
Fri Jun 21 08:58:34 2013
Thread recovery: finish rolling forward thread 1
Thread recovery: 551 data blocks read, 249 data blocks written, 1508 redo blocks read
Crash recovery completed successfully
Fri Jun 21 08:58:34 2013
Thread 1 advanced to log sequence 93034
Thread 1 opened at log sequence 93034
  Current log# 3 seq# 93034 mem# 0: /opt/oracle/oradata/openview/redo03.log
Successful open of redo thread 1.
Fri Jun 21 08:58:34 2013
SMON: enabling cache recovery
SMON: enabling tx recovery
Fri Jun 21 08:58:35 2013
Completed: alter database open

最終資料庫開啟ok;接著開始重建臨時資料檔案及表空:
alter tablespace opc_temp add tempfile '/opt/oracle/oradata/openview/OPC_TEMP_3.dbf' SIZE 100M
Fri Jun 21 09:13:42 2013
ORA-3217 signalled during: alter tablespace opc_temp add tempfile '/opt/oracl...
Fri Jun 21 09:15:16 2013
DROP TABLESPACE TEMP
Fri Jun 21 09:15:16 2013
Completed: DROP TABLESPACE TEMP
Fri Jun 21 09:26:12 2013
create temporary tablespace temp tempfile '/opt/oracle/oradata/openview/temp_1.dbf[D[D[D[2[C[C[C[C' size 100M
Fri Jun 21 09:26:40 2013
Completed: create temporary tablespace temp tempfile '/opt/or

alter tablespace opc_temp add tempfile '/opt/oracle/oradata/openview/OPC_TEMP_1.dbf' size 200M
Fri Jun 21 09:32:46 2013
ORA-3217 signalled during: alter tablespace opc_temp add tempfile '/opt/oracl...

drop tablespace opc_temp
Fri Jun 21 09:38:57 2013
Completed: drop tablespace opc_temp
Fri Jun 21 09:41:21 2013
create temporary tablespace opc_temp tempfile '/opt/oracle/oradata/openview/OPC_TEMP_1.dbf' size 200M
Fri Jun 21 09:41:21 2013
Completed: create temporary tablespace opc_temp tempfile '/op

總結測試:此問題後在oracle10g,11g中測試如上操作清空臨時資料檔案後,然而並不會導致資料庫當機問題。只需要重建臨時表空間及資料檔案即可。此檔案在oracle管理機制中不同於其他資料檔案的管理。

臨時資料檔案簡介:

Oracle中的臨時資料檔案是一個特殊的資料檔案型別。當記憶體不足以在RAM中儲存一個大規模排序操作的中間結果或結果集時,Oracle將使用臨時檔案來儲存它們。永久資料物件,如表或一個索引,是不會儲存到臨時檔案中的,但臨時表或臨時索引的內容則可能儲存到臨時檔案中。所以,不能在臨時檔案中建立自己的應用程式表,但可以使用臨時表儲存臨時資料。臨時檔案從不生成重做日誌,但生成撤銷日誌,當用於全域性臨時表時,如果準備回滾一些事務,就可以在自己的會話中完成。

本地管理的(locally managed)臨時表空間(temporary tablespace)使用臨時的資料檔案(datafile)(臨時檔案),這樣的檔案與普通資料檔案類似,用於磁碟上的分類和臨時的儲存。

但有以下區別:
● 臨時檔案總是被設定為 NOLOGGING 模式。
● 使用者不能將臨時檔案設為之讀
● 使用者不能使用 ALTER DATABASE 語句建立臨時檔案
● 介質恢復(media recovery)不能識別臨時檔案:
● BACKUP CONTROLFILE 不會產生與臨時檔案有關的資訊
● CREATE CONTROLFILE 不能設定與臨時檔案有關的資訊
● 當使用者建立臨時檔案或改變其容量時,Oracle並不保證按照使用者指定的檔案容量為其分配磁碟空間。在某些檔案系統(file systems)中(例如UNIX)磁碟塊(disk block)並不會在檔案建立或改變容量時分配,而是在其被使用之前 才分配。

值得注意的是:

臨時檔案(tempfile)建立與改變容量操作執行的更快。但是隨著臨時檔案的使用可能會導致磁碟空間不足。

● 臨時檔案(tempfile)資訊可以從 DBA_TEMP_FILES 資料字典表及 V$TEMPFILE 動態效能檢視(dynamic performance view)中查詢,但是不存在於 DBA_DATA_FILES 或 V$DATAFILE 檢視中。

參考資料:

%3A%2F%2Fblog.csdn.net%2Ffufeihappy%2Farchive%2F2010%2F12%2F07%2F6061031.aspx&did=5e937446bd287857-1a05c43acea40f30-3fb7963f295d97f5a566a9882f02535a&k=5facfb3c3bf028dd01d7539f93452a85&encodedQuery=%E5%85%B3%E4%BA%8Eoracle%E7%9A%84%E4%B8%B4%E6%97%B6%E6%95%B0%E6%8D%AE%E6%96%87%E4%BB%B6&query=%E5%85%B3%E4%BA%8Eoracle%E7%9A%84%E4%B8%B4%E6%97%B6%E6%95%B0%E6%8D%AE%E6%96%87%E4%BB%B6&&pid=Af52148&duppid=1&p=50040111&dp=1&w=01020400&m=0&st=0

擴充套件內容,臨時資料檔案及表空間的修改要用如下語句:

alter database tempfile 'file_path/file_name' resize;即可同時也可透過alter tablespace temp_tbs add tempfile 新增資料檔案。

undo表空間及資料檔案的修改:

undo 資料檔案可直接alter database datafile修改,同時undo表空間也可透過alter tablespace undo_tbs add datafie 新增資料檔案。

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28612416/viewspace-764491/,如需轉載,請註明出處,否則將追究法律責任。

相關文章