在用戶管理的備份(一)中(詳見:Oracle—用戶管理的備份)對用戶管理備份幾種情況進行了說明;接下來說明幾種特別情況和DBverify的使用。
一.如果在表空間在備份模式下,主機發生了異常關閉,會出現什麼情況?
打開第一個會話窗口,以sys用戶登錄,把表空間users置於備份模式。
SQL> alter tablespace users begin backup;
Tablespace altered.
打開第二個會話窗口,以sys用戶登錄,用shutdown abort命令模擬斷電。
SQL> shutdown abort;
ORACLE instance shut down.
在第一個會話窗口,重新啓動。
SQL> startup
ORACLE instance started.
Total System Global Area 146472960 bytes
Fixed Size 1335080 bytes
Variable Size 92274904 bytes
Database Buffers 50331648 bytes
Redo Buffers 2531328 bytes
Database mounted.
ORA-10873: file 4 needs to be either taken out of backup mode or media
recovered
ORA-01110: data file 4: '/u01/oradata/wilson/users01.dbf'
可以看到數據庫打不開,只能處於mount狀態;
解決辦法:
SQL> select * from v$backup;(v$backup可以看到哪些文件置於備份狀態)
FILE# STATUS CHANGE# TIME
---------- ------------------ --------- ---------
1 UNKNOWN ERROR 2794785 23-AUG-13
2 UNKNOWN ERROR 2794785 23-AUG-13
3 UNKNOWN ERROR 2794785 23-AUG-13
4 ACTIVE 2805598 23-AUG-13
5 NOT ACTIVE 2794785 23-AUG-13
6 NOT ACTIVE 2794785 23-AUG-13
7 NOT ACTIVE 2794785 23-AUG-13
8 NOT ACTIVE 2794785 23-AUG-13
9 NOT ACTIVE 2794785 23-AUG-13
10 NOT ACTIVE 2794785 23-AUG-13
11 NOT ACTIVE 2794785 23-AUG-13
11 rows selected.
可以看到文件4是active的,它處於備份狀態,爲了正常啓動,必須關閉備份狀態;
SQL> alter database end backup;
Database altered.
這樣就可以把所有表空間的備份狀態關閉。
也可以用alter database datafile 4 end backup;
再查看視圖,可以看到所有的文件已經在非備份狀態了;
SQL> select * from v$backup;
FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- ---------
1 NOT ACTIVE 2794785 23-AUG-13
2 NOT ACTIVE 2794785 23-AUG-13
3 NOT ACTIVE 2794785 23-AUG-13
4 NOT ACTIVE 2805598 23-AUG-13
5 NOT ACTIVE 2794785 23-AUG-13
6 NOT ACTIVE 2794785 23-AUG-13
7 NOT ACTIVE 2794785 23-AUG-13
8 NOT ACTIVE 2794785 23-AUG-13
9 NOT ACTIVE 2794785 23-AUG-13
10 NOT ACTIVE 2794785 23-AUG-13
11 NOT ACTIVE 2794785 23-AUG-13
11 rows selected.
打開數據庫,
SQL> alter database open;
Database altered.
二.只讀表空間備份
把example表空間改爲只讀表空間,
SQL> alter tablespace example read only;
Tablespace altered.
然後用!cp命令把它複製到別的地方即可,但是有個問題就是在把example改爲只讀表空間時,控制文件發生了改變,所以要備份控制文件!
1.只讀表空間只要備份一次就可以了,因爲它不能被修改。
2.當把只讀表空間改爲可讀可寫表空間時,是否一定要備份?不用備份,保存好歸檔日誌文件即可,不過最好備份。
3.當控制文件發生改變時必須備份。
三.當大量的數據導入或者導出時,把數據庫置於nologging下,這樣就儘可能的不產生redo log信息,提高性能,等到操作完成後備份一下即可。
四.DBverify
1. 它可以用來檢查數據文件的塊是否損壞,無論是數據文件是在online狀態還是off狀態或者是備份的數據文件都可以檢查,不能檢查聯機重做日誌文件和控制文件的塊。
在操作系統下,輸入dbv可以看到有關參數,
[oracle@oracle11g ~]$ dbv
DBVERIFY: Release 11.2.0.1.0 - Production on Fri Aug 23 12:32:17 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Keyword Description (Default)
------------ ------------------ ----------------------
FILE File to Verify (NONE)
START Start Block (First Block of File)
END End Block (Last Block of File)
BLOCKSIZE Logical Block Size (8192)
LOGFILE Output Log (NONE)
FEEDBACK Display Progress (0)
PARFILE Parameter File (NONE)
USERID Username/Password (NONE)
SEGMENT_ID Segment ID (tsn.relfile.block) (NONE)
HIGH_SCN Highest Block SCN To Verify (NONE)
(scn_wrap.scn_base OR scn)
檢查數據文件system01.dbf,feedback=100表示檢查每100個數據塊就打上一個點;默認情況下,檢查從一個塊開始到最後一個結束;使用logfile可以把檢查的結果信息放到一個文件中。 如下:
如[oracle@oracle11g wilson]$ dbv file=system01.dbf feedback=100
DBVERIFY: Release 11.2.0.1.0 - Production on Fri Aug 23 12:37:43 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
DBVERIFY - Verification starting : FILE = /u01/oradata/wilson/system01.dbf
................................................................................
................................................................................
.
DBVERIFY - Verification complete
Total Pages Examined : 97280
Total Pages Processed (Data) : 66872
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 12537
Total Pages Failing (Index): 0
Total Pages Processed (Other): 3343
Total Pages Processed (Seg) : 1
Total Pages Failing (Seg) : 0
Total Pages Empty : 14528
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Total Pages Encrypted : 0
Highest block SCN : 2828302 (0.2828302)
2.它也可以來用來檢查數據文件的一個表或者索引。
在p1用戶下有一張表fruit,
SQL> select * from p1.fruit;
NAME
--------------------------------
two apple
在表sys_dba_segs中找到 Segment ID (tsn.relfile.block) 的數值;
SQL> select segment_name,tablespace_id,header_file,header_block from sys_dba_segs where owner='P1';
SEGMENT_NAME TABLESPACE_ID HEADER_FILE HEADER_BLOCK
--------------- --------------- - ----------- ------------
FRUIT 4 4 810
然後在操作系統下,使用查到的數值,就可以查到某一個表了。
[oracle@oracle11g ~]$ dbv userid=p1/p1_12345 segment_id=4.4.810
DBVERIFY: Release 11.2.0.1.0 - Production on Fri Aug 23 13:25:50 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
DBVERIFY - Verification starting : SEGMENT_ID = 4.4.810
DBVERIFY - Verification complete
Total Pages Examined : 8
Total Pages Processed (Data) : 5
Total Pages Failing (Data) : 0
Total Pages Processed (Index): 0
Total Pages Failing (Index): 0
Total Pages Processed (Other): 2
Total Pages Processed (Seg) : 1
Total Pages Failing (Seg) : 0
Total Pages Empty : 0
Total Pages Marked Corrupt : 0
Total Pages Influx : 0
Total Pages Encrypted : 0
Highest block SCN : 2798211 (0.2798211)