?
? ? ? ? 我們知道Oracle數(shù)據(jù)庫熱備有3步: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
1. alter tablespace ?tbname ?begin backup;
2. cp ?/××× ? ? ?to ? /××
3. alter tablespace ?tbname end ?backup;
?
這個過程要盡可能短,否則會造成大量的redolog。
?
那么,數(shù)據(jù)庫在你執(zhí)行begin backup時,系統(tǒng)做了什么呢?
1. tablespace 發(fā)生了一次checkpoint------會把buffer臟數(shù)據(jù)全部寫入到數(shù)據(jù)文件
2. tablespace下的數(shù)據(jù)文件的文件頭的scn會保持不變-------這里的scn即第一步發(fā)生checkpoint的scn
3. 如果此時,有改變數(shù)據(jù)的操作,數(shù)據(jù)庫會對被修改的block塊進行整個備份,以保證數(shù)據(jù)的完整性。
? (后期在恢復(fù)時,數(shù)據(jù)庫會發(fā)現(xiàn)該塊被修改,然后通過archive log 來進行恢復(fù))
? ?---------也就是說,你在熱備時,是可以修改數(shù)據(jù)的;---------------這就是熱備的優(yōu)點。
?
下面通過實驗來驗證一下第3點:
1.用一個新用戶登錄
SQL> conn yn/yn
Connected.
SQL> create table fruit(name varchar2(30));
Table created.
SQL> insert into fruit values('orange');
1 row created.
SQL> commit;
Commit complete.
SQL> select dbms_rowid.rowid_block_number(rowid) blk ,name from fruit;
BLK NAME
---------- ------------------------------
64 orange
----查看數(shù)據(jù)被保存的數(shù)據(jù)塊
(注意:commit 并不代表該數(shù)據(jù)會被寫入到數(shù)據(jù)文件中;我是在另外一個session中執(zhí)行了checkpoint來達到寫入數(shù)據(jù)文件的)
?
SQL> select username,default_tablespace from dba_users;
USERNAME DEFAULT_TABLESPACE
------------------------------ ------------------------------
HACKER SYSTEM
BBK SYSTEM
OPS$YN SYSTEM
YN ?USERS
-------該yn用戶對應(yīng)的表空間是 users
?
?
2.通過dd命令來查看block內(nèi)容
[oracle@app orcl]$ dd if=users01.dbf ibs=8192 skip=63 count=3 |strings
3+0 records in
48+0 records out
24576 bytes (25 kB) copied, 0.000252 seconds, 97.5 MB/s
orange
---這說明我們數(shù)據(jù)已經(jīng)寫入數(shù)據(jù)文件
?
3. 執(zhí)行熱備
SQL> alter tablespace users begin backup;
Tablespace altered.
?
4.修改系統(tǒng)數(shù)據(jù)
SQL> update fruit set name='apple';
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from fruit;
NAME
------------------------------
apple
?
5.再次查看block
[oracle@app orcl]$ dd if=users01.dbf ibs=8192 skip=63 count=3 |strings
3+0 records in
48+0 records out
24576 bytes (25 kB) copied, 0.000187 seconds, 131 MB/s
apple,
orange
[oracle@app orcl]$
?
----說明數(shù)據(jù)文件已經(jīng)修改
?
6.最后取消表空間備份
?alter tablespace users ?end bakcup;
?
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
