oracle 表空間undo丟失後的恢復

    oracle數據庫再恢復中會用到兩個東西:recover,restore數據庫

    recover:把備份的文件恢復回去oracle

    restore:利用日誌重作spa

1    undo表空間丟失後的恢復rest

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u01/oracle/oradata/orcl/system01.dbf
/u01/oracle/oradata/orcl/sysaux01.dbf
/u01/oracle/oradata/orcl/undotbs01.dbf
/u01/oracle/oradata/orcl/users01.dbf
/u01/oracle/oradata/orcl/user02.dbf
/u01/oracle/oradata/orcl/tmpspace0327

6 rows selected.

SQL> ho rm -rf /u01/oracle/oradata/orcl/undotbs01.dbf;
# undo表空間被丟失了
SQL> conn scott/tiger
Connected.
#這個時候還能切換數據庫使用,是由於undo還在內存中
SQL> conn / as sysdba
ERROR:
ORA-02002: error while writing to audit trail
ORA-00604: error occurred at recursive SQL level 1
ORA-01116: error in opening database file 3
ORA-01110: data file 3: '/u01/oracle/oradata/orcl/undotbs01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
# 切換會sys的時候已經提示文件不在了。

    如今能夠恢復數據庫日誌

因爲如今數據庫仍是能夠使用的,因此能夠採用不關閉數據庫的狀況下新建一個undo進行切換code

SQL> select name from v$datafile;

NAME
--------------------------------------------------------------------------------
/u01/oracle/oradata/orcl/system01.dbf
/u01/oracle/oradata/orcl/sysaux01.dbf
/u01/oracle/oradata/orcl/undotbs01.dbf
/u01/oracle/oradata/orcl/users01.dbf
/u01/oracle/oradata/orcl/user02.dbf
/u01/oracle/oradata/orcl/tmpspace0327
SQL> ho ls -l /u01/oracle/oradata/orcl/*.dbf
-rw-r----- 1 oracle dba  650125312 Apr  9 15:27 /u01/oracle/oradata/orcl/sysaux01.dbf
-rw-r----- 1 oracle dba 1027612672 Apr  9 15:26 /u01/oracle/oradata/orcl/system01.dbf
-rw-r----- 1 oracle dba  275783680 Apr  9 14:32 /u01/oracle/oradata/orcl/temp1.dbf
-rw-r----- 1 oracle dba   10493952 Apr  9 14:18 /u01/oracle/oradata/orcl/user02.dbf
-rw-r----- 1 oracle dba    5251072 Apr  9 14:18 /u01/oracle/oradata/orcl/users01.dbf
# 比較 就能夠看出來undo 文件確實不在了

建立新的undo表空間orm

SQL> create undo tablespace undotbs2 datafile '/u01/oracle/oradata/orcl/undotbs02.dbf' size 10M autoextend on;
SQL>  ho ls -l /u01/oracle/oradata/orcl/*.dbf
-rw-r----- 1 oracle dba  650125312 Apr  9 15:38 /u01/oracle/oradata/orcl/sysaux01.dbf
-rw-r----- 1 oracle dba 1027612672 Apr  9 15:37 /u01/oracle/oradata/orcl/system01.dbf
-rw-r----- 1 oracle dba  275783680 Apr  9 14:32 /u01/oracle/oradata/orcl/temp1.dbf
-rw-r----- 1 oracle dba   10493952 Apr  9 15:29 /u01/oracle/oradata/orcl/undotbs02.dbf
-rw-r----- 1 oracle dba   10493952 Apr  9 14:18 /u01/oracle/oradata/orcl/user02.dbf
-rw-r----- 1 oracle dba    5251072 Apr  9 14:18 /u01/oracle/oradata/orcl/users01.dbf
# 新的undotbs2 已經建立
SQL> select TABLESPACE_NAME,status from dba_tablespaces;

TABLESPACE_NAME 	       STATUS
------------------------------ ---------
SYSTEM			       ONLINE
SYSAUX			       ONLINE
UNDOTBS1		       ONLINE
USERS			       ONLINE
UNDOTBS2		       ONLINE
USER02			       ONLINE
TMP_SPACE_0327		       ONLINE
TEMP			       ONLINE

設置系統的undo 表空間內存

SQL> show parameter undo

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
undo_management 		     string	 AUTO
undo_retention			     integer	 900
undo_tablespace 		     string	 UNDOTBS1
# 當前系統的參數undo_tablespace 仍是原來的UNDOTBS1,因此須要切換
SQL> SQL> show parameter undo

NAME				     TYPE	 VALUE
------------------------------------ ----------- ------------------------------
undo_management 		     string	 AUTO
undo_retention			     integer	 900
undo_tablespace 		     string	 UNDOTBS2
# 已經切換成功

而後把原來的undo刪除ci

SQL> drop tablespace UNDOTBS1;
drop tablespace UNDOTBS1
*
ERROR at line 1:
ORA-01116: error in opening database file 3
ORA-01110: data file 3: '/u01/oracle/oradata/orcl/undotbs01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
#文件不在,刪除失敗

能夠把原來的表空間下線get

SQL> alter tablespace UNDOTBS1 offline;
alter tablespace UNDOTBS1 offline
*
ERROR at line 1:
ORA-01116: error in opening database file 3
ORA-01110: data file 3: '/u01/oracle/oradata/orcl/undotbs01.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
#文件不在,下線失敗

能夠使用文件下線

SQL> alter database datafile 3 offline;

Database altered.

SQL> select file#,name,status from v$datafile;

     FILE# NAME 					      STATUS
---------- -------------------------------------------------- -------
	 1 /u01/oracle/oradata/orcl/system01.dbf	      SYSTEM
	 2 /u01/oracle/oradata/orcl/sysaux01.dbf	      ONLINE
	 3 /u01/oracle/oradata/orcl/undotbs01.dbf	      RECOVER
	 4 /u01/oracle/oradata/orcl/users01.dbf 	      ONLINE
	 5 /u01/oracle/oradata/orcl/user02.dbf		      ONLINE
	 6 /u01/oracle/oradata/orcl/tmpspace0327	      ONLINE
	 7 /u01/oracle/oradata/orcl/undotbs02.dbf	      ONLINE
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.

Total System Global Area  584568832 bytes
Fixed Size		    2230552 bytes
Variable Size		  440403688 bytes
Database Buffers	  134217728 bytes
Redo Buffers		    7716864 bytes
Database mounted.
Database opened.
SQL> conn scott/tiger
Connected.
SQL> conn /as sysdba
Connected.
# 數據庫已經能夠正常關閉啓動了,到此undo表空間丟失問題已經處理成功。

2    還有一種處理undo 表空間丟失的方法。

    能夠使用備份文件進行恢復。

    注意:前提是undo表空間已經被備份過

    下面咱們就再模擬一次undo丟失恢復的過程

    2.1 先再rman 備份

RMAN> backup tablespace UNDOTBS2;

Starting backup at 09-APR-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=25 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00007 name=/u01/oracle/oradata/orcl/undotbs02.dbf
channel ORA_DISK_1: starting piece 1 at 09-APR-17
channel ORA_DISK_1: finished piece 1 at 09-APR-17
piece handle=/tmp/0os1904r_1_1 tag=TAG20170409T160859 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
Finished backup at 09-APR-17

    2.2 刪除undo

SQL> select file#,name from v$datafile;

     FILE# NAME
---------- --------------------------------------------------
	 1 /u01/oracle/oradata/orcl/system01.dbf
	 2 /u01/oracle/oradata/orcl/sysaux01.dbf
	 3 /u01/oracle/oradata/orcl/undotbs01.dbf
	 4 /u01/oracle/oradata/orcl/users01.dbf
	 5 /u01/oracle/oradata/orcl/user02.dbf
	 6 /u01/oracle/oradata/orcl/tmpspace0327
	 7 /u01/oracle/oradata/orcl/undotbs02.dbf

7 rows selected.

SQL> ho rm -rf /u01/oracle/oradata/orcl/undotbs02.dbf;

刷新

SQL> alter system flush shared_pool;

System altered.
SQL> alter system flush GLOBAL CONTEXT;

System altered.

切換用戶

SQL> conn scott/tiger
ERROR:
ORA-02002: error while writing to audit trail
ORA-00604: error occurred at recursive SQL level 1
ORA-01116: error in opening database file 7
ORA-01110: data file 7: '/u01/oracle/oradata/orcl/undotbs02.dbf'
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3


Warning: You are no longer connected to ORACLE.

能夠看出來數據庫已經沒法使用。

強制關閉shutdown abort

SQL> shutdown abort;
ORACLE instance shut down.

啓動到mount

SQL> startup mount;
ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
ORACLE instance started.

Total System Global Area  584568832 bytes
Fixed Size		    2230552 bytes
Variable Size		  440403688 bytes
Database Buffers	  134217728 bytes
Redo Buffers		    7716864 bytes
Database mounted.

文件恢復(在rman裏面)

RMAN> restore datafile 7;

Starting restore at 09-APR-17
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=138 device type=DISK

channel ORA_DISK_1: starting datafile backup set restore
channel ORA_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_DISK_1: restoring datafile 00007 to /u01/oracle/oradata/orcl/undotbs02.dbf
channel ORA_DISK_1: reading from backup piece /tmp/0os1904r_1_1
channel ORA_DISK_1: piece handle=/tmp/0os1904r_1_1 tag=TAG20170409T160859
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 09-APR-17

文件重作

RMAN> recover datafile 7;

Starting recover at 09-APR-17
using channel ORA_DISK_1

starting media recovery
media recovery complete, elapsed time: 00:00:00

Finished recover at 09-APR-17

打開數據庫

SQL> alter database open;

Database altered.

SQL> conn scott/tiger
Connected.

到此undo 表空間又被徹底恢復了。

可是這樣作是須要重啓數據庫的,若是數據庫須要7*24 開機,則這中辦法不可取。

相關文章
相關標籤/搜索