<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 :: 首頁 :: 新隨筆 :: 聯(lián)系 ::  :: 管理 ::
      397 隨筆 :: 33 文章 :: 29 評論 :: 0 Trackbacks
    使用DBMS_REPAIR包修復壞塊(一)
    ?
    ??? 今天來學習一下數(shù)據(jù)壞塊的檢測和修復。Oracle為了檢測和糾正數(shù)據(jù)塊隨壞,提供了不同的方法,糾正方法有很多,第一是在檢測到損壞之后,就刪除并重建該對象,但是這個方法有時是不可用的,而且效果也不理想。如果數(shù)據(jù)塊損壞局限于行的子集,則可以選取除了損壞行之外的所有行來重建表。 第二個方法是使用DBMS_REPAIR包來檢測和修復表或索引中的損壞數(shù)據(jù)塊。這個方法的好處在于可以確定損壞出現(xiàn)的位置,并重建或修復它們,使對象可以繼續(xù)使用。
    ?
    ??? 需要注意的是:任何包含數(shù)據(jù)丟失的損壞都需要分析和理解數(shù)據(jù)是如何填充進整個數(shù)據(jù)庫系統(tǒng)中的。所以DBMS_REPAIR的修復方法并不一定適用于每個損壞問題,基于損壞的本質(zhì),是有可能丟失數(shù)據(jù)或引入邏輯矛盾的,因此在使用DBMS_REPAIR修復時要權(quán)衡其帶來的得失利弊。
    ?
    ?
    ??? 首先介紹一下DBMS_REPAIR包(注意:這個包只能由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用于修復或隔離鍵表的管理函數(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用于檢測和報告表中或索引中的損壞
    ?
    ? --
    ? 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報告指出損壞數(shù)據(jù)塊中的行的索引項(在一個孤立鍵表中)
    ?
    ? --
    ? 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標記出來的數(shù)據(jù)塊標記為軟件錯誤
    ?
    ? --
    ? 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用于重建對象的空閑列表
    ?
    ? --
    ? 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掃描或索引期間,忽略被標記為損壞的數(shù)據(jù)塊
    ? --不使用是遇到損壞塊會報錯: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:當SEGMENT管理為AUTO時,提供確定位圖項的損壞狀態(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的限制有以下幾點:
    ?
    ??? 1、支持具有LOB列、嵌入表、varray列的表,但忽略out of line columns
    ??? 2、SKIP_CORRUPT_BLOCKS和REBUILD_FREELISTS支持簇,但CHECK_OBJECT不支持簇
    ??? 3、不支持索引結(jié)構(gòu)表和LOB索引
    ??? 4、DUMP_ORPHAN_KEYS過程不能用于位圖索引或基于函數(shù)的索引
    ??? 5、DUMP_ORPHAN_KEYS過程最多處理3950字節(jié)長的鍵
    ?
    ??? 下面開始從頭來說明檢測、修復壞塊的過程:
    ?
    一、檢測和報告損壞
    ?
    ??? 這個過程不僅僅是指出數(shù)據(jù)塊出什么錯了,還要指出相關(guān)的修復方針。為了檢測損壞,除了DBMS_REPAIR之外,還有幾個其他不同的選擇:
    ?
    ??? 1、DBMS_REPAIR
    ?
    ??? 對一個指定的表、分區(qū)或索引執(zhí)行數(shù)據(jù)塊檢查,用結(jié)果填充一個修復表。使用CHECK_OBJECT和ADMIN_TABLES兩個過程。
    ?
    ??? CHECK_OBJECT檢查和報告指定對象的數(shù)據(jù)塊損壞,與用于索引和表的ANALYZE...VALIDATE STRUCTURE語句相同,數(shù)據(jù)塊檢查是用于索引和數(shù)據(jù)塊的。CHECK_OBJECT不僅報告損壞,如果以后在該對象上運行FIX_CORRUPT_BLOCKS時,它還標識任何方位。通過將這些信息填充進修復表而使這些信息可用,必須先用ADMIN_TABLES過程創(chuàng)建修復表。(執(zhí)行CHECK_OBJECT過程后,查詢修復表即可知道對象的損壞和修復方針)
    ?
    ??? 2、DB_VERIFY
    ?
    ??? 外部命令行工具,它在脫機數(shù)據(jù)庫上執(zhí)行數(shù)據(jù)塊檢查,具體使用方法另詳。
    ?
    ??? 3、ANALYZE
    ?
    ??? 與VALIDATE STRUCTURE選項一起使用,確認索引、表或簇的結(jié)構(gòu)完整性;檢查或確認表和索引是同步的。
    ?
    ??? ANALYZE TABLE ... VALIDATE STRUCTURE 語句校驗被分析對象的結(jié)構(gòu)。如果Oracle成功地校驗了該結(jié)構(gòu),則返回一條確認消息,如果Oracle遇到了對象結(jié)構(gòu)中的損壞,則返回一條錯誤消息。此時就應該刪除并重建該對象。
    ?
    ??? 4、DB_BLOCK_CHECKING
    ?
    ??? 當DB_BLOCK_CHECKING=TRUE時被執(zhí)行。在實際被標記成損壞之前識別損壞的數(shù)據(jù)塊。當數(shù)據(jù)塊被修改是執(zhí)行檢查。
    ?
    ?
    ------------------
    ??? 剩下關(guān)于如何操作和修復明天再學習。
    ?
    ?
    posted on 2009-07-30 21:54 decode360 閱讀(434) 評論(0)  編輯  收藏 所屬分類: 08.DBA
    主站蜘蛛池模板: 国产成人亚洲综合网站不卡| 一出一进一爽一粗一大视频免费的| 成年轻人网站色免费看| 亚洲国产精品无码第一区二区三区 | 亚洲一卡二卡三卡| 免费一看一级毛片人| 国产精品免费看久久久| 中文日韩亚洲欧美制服| 亚洲精品自在在线观看| 免费观看黄网站在线播放| 精品多毛少妇人妻AV免费久久| 亚洲高清无在码在线电影不卡| 日本免费中文字幕在线看| 99久9在线|免费| 老司机福利在线免费观看| 久久亚洲美女精品国产精品| 国产成人精品男人免费| 性无码免费一区二区三区在线| 亚洲av无码有乱码在线观看| 亚洲人成电影在在线观看网色| 日本免费的一级v一片| 91麻豆国产免费观看| 羞羞漫画小舞被黄漫免费| 亚洲手机中文字幕| 久久精品国产亚洲5555| 好吊妞在线成人免费| 欧洲人成在线免费| 老司机精品视频免费| 中文字幕乱码亚洲无线三区| 亚洲一区二区三区四区在线观看| 亚洲?v女人的天堂在线观看| 国国内清清草原免费视频99| 日本免费污片中国特一级| 黄色一级视频免费| 亚洲日本VA午夜在线电影| 久久夜色精品国产噜噜噜亚洲AV| 国产精品亚洲视频| 免费国产综合视频在线看| 最近免费中文字幕4| 亚洲黄色免费观看| 久久久久免费精品国产|