<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Decode360's Blog

    業(yè)精于勤而荒于嬉 QQ:150355677 MSN:decode360@hotmail.com

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 ::  :: 管理 ::
      397 隨筆 :: 33 文章 :: 29 評(píng)論 :: 0 Trackbacks
    使用DBMS_REPAIR包修復(fù)壞塊(一)
    ?
    ??? 今天來(lái)學(xué)習(xí)一下數(shù)據(jù)壞塊的檢測(cè)和修復(fù)。Oracle為了檢測(cè)和糾正數(shù)據(jù)塊隨壞,提供了不同的方法,糾正方法有很多,第一是在檢測(cè)到損壞之后,就刪除并重建該對(duì)象,但是這個(gè)方法有時(shí)是不可用的,而且效果也不理想。如果數(shù)據(jù)塊損壞局限于行的子集,則可以選取除了損壞行之外的所有行來(lái)重建表。 第二個(gè)方法是使用DBMS_REPAIR包來(lái)檢測(cè)和修復(fù)表或索引中的損壞數(shù)據(jù)塊。這個(gè)方法的好處在于可以確定損壞出現(xiàn)的位置,并重建或修復(fù)它們,使對(duì)象可以繼續(xù)使用。
    ?
    ??? 需要注意的是:任何包含數(shù)據(jù)丟失的損壞都需要分析和理解數(shù)據(jù)是如何填充進(jìn)整個(gè)數(shù)據(jù)庫(kù)系統(tǒng)中的。所以DBMS_REPAIR的修復(fù)方法并不一定適用于每個(gè)損壞問(wèn)題,基于損壞的本質(zhì),是有可能丟失數(shù)據(jù)或引入邏輯矛盾的,因此在使用DBMS_REPAIR修復(fù)時(shí)要權(quán)衡其帶來(lái)的得失利弊。
    ?
    ?
    ??? 首先介紹一下DBMS_REPAIR包(注意:這個(gè)包只能由sys用戶查看、使用):
    ?
    CREATE OR REPLACE PACKAGE dbms_repair
    ?
    ? IS
    ? ----------------------------------
    ? --? OVERVIEW
    ? --
    ? --? The DBMS_REPAIR package consists of data corruption repair procedures
    ? --
    ? --? SECURITY
    ? --
    ? --? The package is owned by SYS.
    ? --? Execution privilege is not granted to other users.
    ? ----------------------------------
    ? --
    ? --? ENUMERATION TYPES:
    ? --
    ? --? Object Type Specification
    ? --
    ? TABLE_OBJECT constant binary_integer := 1;
    ? INDEX_OBJECT constant binary_integer := 2;
    ? CLUSTER_OBJECT constant binary_integer := 4;
    ?
    ? --
    ? -- Flags Specification
    ? --
    ? SKIP_FLAG??? constant binary_integer := 1;
    ? NOSKIP_FLAG? constant binary_integer := 2;
    ?
    ? --
    ? -- Admin Action Specification
    ? --
    ? CREATE_ACTION constant binary_integer := 1;
    ? PURGE_ACTION? constant binary_integer := 2;
    ? DROP_ACTION?? constant binary_integer := 3;
    ?
    ? --
    ? -- Admin Table Type Specification
    ? --
    ? REPAIR_TABLE constant binary_integer :=1;
    ? ORPHAN_TABLE constant binary_integer :=2;
    ?
    ? --
    ? -- Object Id Specification
    ? --
    ? ALL_INDEX_ID constant binary_integer :=0;
    ?
    ? --
    ? -- Lock Wait Specification
    ? --
    ? LOCK_NOWAIT constant binary_integer := 0;
    ? LOCK_WAIT?? constant binary_integer := 1;
    ? -----------------------------------
    ? --
    ? -- PROCEDURES AND FUNCTIONS
    ? --
    ? --
    ?
    ? --
    ? -- NOTE: default table_name will be 'REPAIR_TABLE' when table_type is
    ? -- REPAIR_TABLE, and will be 'ORPHAN_KEY_TABLE' when table_type is
    ? -- ORPHAN_TABLE
    ? procedure admin_tables(
    ??? table_name IN varchar2 DEFAULT 'GENERATE_DEFAULT_TABLE_NAME',
    ??? table_type IN binary_integer,
    ??? action IN binary_integer,
    ??? tablespace IN varchar2 DEFAULT NULL);
    ? --admin_tables用于修復(fù)或隔離鍵表的管理函數(shù)(創(chuàng)建、刪除、凈化)
    ?
    ? --
    ? procedure check_object(
    ??? schema_name IN varchar2,
    ??? object_name IN varchar2,
    ??? partition_name IN varchar2 DEFAULT NULL,
    ??? object_type IN binary_integer DEFAULT TABLE_OBJECT,
    ??? repair_table_name IN varchar2 DEFAULT 'REPAIR_TABLE',
    ??? flags IN binary_integer DEFAULT NULL,
    ??? relative_fno IN binary_integer DEFAULT NULL,
    ??? block_start IN binary_integer DEFAULT NULL,
    ??? block_end IN binary_integer DEFAULT NULL,
    ??? corrupt_count OUT binary_integer);
    ? --check_object用于檢測(cè)和報(bào)告表中或索引中的損壞
    ?
    ? --
    ? procedure dump_orphan_keys(
    ??? schema_name IN varchar2,
    ??? object_name IN varchar2,
    ??? partition_name IN varchar2 DEFAULT NULL,
    ??? object_type IN binary_integer DEFAULT INDEX_OBJECT,
    ??? repair_table_name IN varchar2 DEFAULT 'REPAIR_TABLE',
    ??? orphan_table_name IN varchar2 DEFAULT 'ORPHAN_KEY_TABLE',
    ??? flags IN binary_integer DEFAULT NULL,
    ??? key_count OUT binary_integer);
    ? --dump_orphan_keys報(bào)告指出損壞數(shù)據(jù)塊中的行的索引項(xiàng)(在一個(gè)孤立鍵表中)
    ?
    ? --
    ? procedure fix_corrupt_blocks(
    ??? schema_name IN varchar2,
    ??? object_name IN varchar2,
    ??? partition_name IN varchar2 DEFAULT NULL,
    ??? object_type IN binary_integer DEFAULT TABLE_OBJECT,
    ??? repair_table_name IN varchar2 DEFAULT 'REPAIR_TABLE',
    ??? flags IN binary_integer DEFAULT NULL,
    ??? fix_count OUT binary_integer);
    ? --fix_corrupt_blocks用于將被check_object標(biāo)記出來(lái)的數(shù)據(jù)塊標(biāo)記為軟件錯(cuò)誤
    ?
    ? --
    ? procedure rebuild_freelists(
    ??? schema_name IN varchar2,
    ??? object_name IN varchar2,
    ??? partition_name IN varchar2 DEFAULT NULL,
    ??? object_type IN binary_integer DEFAULT TABLE_OBJECT);
    ? --rebuild_freelists用于重建對(duì)象的空閑列表
    ?
    ? --
    ? procedure skip_corrupt_blocks(
    ??? schema_name IN varchar2,
    ??? object_name IN varchar2,
    ??? object_type IN binary_integer DEFAULT TABLE_OBJECT,
    ??? flags IN binary_integer DEFAULT SKIP_FLAG);
    ? --skip_corrupt_blocks掃描或索引期間,忽略被標(biāo)記為損壞的數(shù)據(jù)塊
    ? --不使用是遇到損壞塊會(huì)報(bào)錯(cuò):ORA-01578
    ?
    ? --
    ? procedure segment_fix_status(
    ??? segment_owner IN varchar2,
    ??? segment_name? IN varchar2,
    ??? segment_type?? IN binary_integer DEFAULT TABLE_OBJECT,
    ??? file_number??? IN binary_integer DEFAULT NULL,
    ??? block_number?? IN binary_integer DEFAULT NULL,
    ??? status_value?? IN binary_integer DEFAULT NULL,
    ??? partition_name IN varchar2 DEFAULT NULL);
    ? --segment_fix_status:當(dāng)SEGMENT管理為AUTO時(shí),提供確定位圖項(xiàng)的損壞狀態(tài)。
    ?
    ? --
    ? procedure rebuild_shc_index(
    ??? segment_owner? IN varchar2,
    ??? cluster_name?? IN varchar2);
    ?
    ? --
    ? function online_index_clean(
    ??? object_id????? IN binary_integer DEFAULT ALL_INDEX_ID,
    ??? wait_for_lock? IN binary_integer DEFAULT LOCK_WAIT)
    ??? return boolean;

    ? --?? Example Usage of online_index_clean:
    ? --?? DECLARE
    ? --???? isClean BOOLEAN;
    ? --?? BEGIN
    ? --
    ? --???? isClean := FALSE;
    ? --???? WHILE isClean=FALSE
    ? --???? LOOP
    ? --?????? isClean := DBMS_REPAIR.ONLINE_INDEX_CLEAN(DBMS_REPAIR.ALL_INDEX_ID,
    ? --???????????????????????????????????????????????? DBMS_REPAIR.LOCK_WAIT);
    ? --?????? DBMS_LOCK.SLEEP(10);
    ? --???? END LOOP;
    ? --
    ? --???? EXCEPTION
    ? --????? WHEN OTHERS THEN
    ? --????? RAISE;
    ? --?? END;
    ? --?? /
    ?
    END dbms_repair;
    ?
    ?
    ??? DBMS_REPAIR的限制有以下幾點(diǎn):
    ?
    ??? 1、支持具有LOB列、嵌入表、varray列的表,但忽略out of line columns
    ??? 2、SKIP_CORRUPT_BLOCKS和REBUILD_FREELISTS支持簇,但CHECK_OBJECT不支持簇
    ??? 3、不支持索引結(jié)構(gòu)表和LOB索引
    ??? 4、DUMP_ORPHAN_KEYS過(guò)程不能用于位圖索引或基于函數(shù)的索引
    ??? 5、DUMP_ORPHAN_KEYS過(guò)程最多處理3950字節(jié)長(zhǎng)的鍵
    ?
    ??? 下面開(kāi)始從頭來(lái)說(shuō)明檢測(cè)、修復(fù)壞塊的過(guò)程:
    ?
    一、檢測(cè)和報(bào)告損壞
    ?
    ??? 這個(gè)過(guò)程不僅僅是指出數(shù)據(jù)塊出什么錯(cuò)了,還要指出相關(guān)的修復(fù)方針。為了檢測(cè)損壞,除了DBMS_REPAIR之外,還有幾個(gè)其他不同的選擇:
    ?
    ??? 1、DBMS_REPAIR
    ?
    ??? 對(duì)一個(gè)指定的表、分區(qū)或索引執(zhí)行數(shù)據(jù)塊檢查,用結(jié)果填充一個(gè)修復(fù)表。使用CHECK_OBJECT和ADMIN_TABLES兩個(gè)過(guò)程。
    ?
    ??? CHECK_OBJECT檢查和報(bào)告指定對(duì)象的數(shù)據(jù)塊損壞,與用于索引和表的ANALYZE...VALIDATE STRUCTURE語(yǔ)句相同,數(shù)據(jù)塊檢查是用于索引和數(shù)據(jù)塊的。CHECK_OBJECT不僅報(bào)告損壞,如果以后在該對(duì)象上運(yùn)行FIX_CORRUPT_BLOCKS時(shí),它還標(biāo)識(shí)任何方位。通過(guò)將這些信息填充進(jìn)修復(fù)表而使這些信息可用,必須先用ADMIN_TABLES過(guò)程創(chuàng)建修復(fù)表。(執(zhí)行CHECK_OBJECT過(guò)程后,查詢修復(fù)表即可知道對(duì)象的損壞和修復(fù)方針)
    ?
    ??? 2、DB_VERIFY
    ?
    ??? 外部命令行工具,它在脫機(jī)數(shù)據(jù)庫(kù)上執(zhí)行數(shù)據(jù)塊檢查,具體使用方法另詳。
    ?
    ??? 3、ANALYZE
    ?
    ??? 與VALIDATE STRUCTURE選項(xiàng)一起使用,確認(rèn)索引、表或簇的結(jié)構(gòu)完整性;檢查或確認(rèn)表和索引是同步的。
    ?
    ??? ANALYZE TABLE ... VALIDATE STRUCTURE 語(yǔ)句校驗(yàn)被分析對(duì)象的結(jié)構(gòu)。如果Oracle成功地校驗(yàn)了該結(jié)構(gòu),則返回一條確認(rèn)消息,如果Oracle遇到了對(duì)象結(jié)構(gòu)中的損壞,則返回一條錯(cuò)誤消息。此時(shí)就應(yīng)該刪除并重建該對(duì)象。
    ?
    ??? 4、DB_BLOCK_CHECKING
    ?
    ??? 當(dāng)DB_BLOCK_CHECKING=TRUE時(shí)被執(zhí)行。在實(shí)際被標(biāo)記成損壞之前識(shí)別損壞的數(shù)據(jù)塊。當(dāng)數(shù)據(jù)塊被修改是執(zhí)行檢查。
    ?
    ?
    ------------------
    ??? 剩下關(guān)于如何操作和修復(fù)明天再學(xué)習(xí)。
    ?
    ?
    posted on 2009-07-30 21:54 decode360 閱讀(442) 評(píng)論(0)  編輯  收藏 所屬分類: 08.DBA
    主站蜘蛛池模板: 99在线免费观看视频| 黄色a级片免费看| 久久国产精品一区免费下载| 国产亚洲精品国看不卡| 男人j进女人p免费视频| 免费h成人黄漫画嘿咻破解版| 亚洲精品天堂无码中文字幕| 免费看的成人yellow视频| 亚洲人成网站999久久久综合| 好爽…又高潮了免费毛片| 亚洲欧美成人综合久久久| 成全视频免费高清| 国产亚洲视频在线观看网址| 亚洲福利在线播放| 国产午夜精品理论片免费观看 | 日韩高清在线免费看| 在线观看亚洲视频| 国产精品亚洲视频| 免费毛片在线看不用播放器| 亚洲国产女人aaa毛片在线 | 久久久久亚洲av毛片大| 免费无码黄网站在线看| 亚洲一区二区影院| 国产三级在线观看免费| 精品在线视频免费| 国产成人精品日本亚洲网站| 久久久久久曰本AV免费免费| 亚洲另类无码一区二区三区| 免费一级特黄特色大片在线观看| aaa毛片免费观看| 亚洲免费视频观看| 日本中文一区二区三区亚洲 | 巨胸狂喷奶水视频www网站免费| 久久久久久亚洲精品| 手机在线看永久av片免费| 久久无码av亚洲精品色午夜| 亚洲精品一品区二品区三品区| 国产福利在线免费| xvideos永久免费入口| 亚洲视频国产视频| 又爽又黄无遮挡高清免费视频|