Oracle索引資料表空間資料檔案丟失及重建

來源:互聯網
上載者:User

Oracle索引資料表空間資料檔案丟失及重建

重新建立索引:
使用以下選項可縮短建立索引所花費的時間:

PARALLEL NOLOGGING

PARALLEL(NOPARALLEL 是預設值):多個進程可以同時協同工作來建立索引。與單個伺服器處理序按順序建立索引相比,通過在多個伺服器處理序之間分配建立索引所需的工作,Oracle 伺服器可以更快速地建立索引。將隨機對錶取樣並找到一組索引關鍵字,這些索引關鍵字按照指定的並行度將索引平均分為相同數目的片段。第一組查詢進程將掃描表,提取關鍵字、行 ID 對並基於關鍵字將每個對發送到第二組查詢進程中的一個進程中。第二組中的每個進程都對關鍵字進行排序並按常規方式構建索引。所有索引片段構建完成後,並行協調程式會將這些片段(已進行排序)級聯以形成最終的索引。

SQL> CREATE INDEX rname_idx 
  ON hr.regions (region_name)
  PARALLEL 4;

 
  NOLOGGING:使用此關鍵字會加快索引的建立速度,因為建立進程建立的重做日誌 條目極少。這種工作量大幅減小的重做生

成也適用於直接路徑插入和 Direct Loader (SQL*Loader) 插入。這是永久性屬性,因此將顯示在資料字典中。可以隨時使用

ALTER INDEX NOLOGGING/LOGGING 命令來加以更新。
註:若資料庫在nologging狀態時,所操作的資料應該備份,再將nologging改回來,以免重大失誤難以恢複
 
丟失了索引資料表空間後進行恢複:
  索引丟失時,更為快速、簡單的方法是重新建立而不是嘗試恢複索引。
 
 索引是計算得到的對象,因為它們不提供任何未經處理資料,只是已存在資料的另一表示形式。因此,在大多數情況下,可以很容易地重新建立索引。
如果您的資料表空間僅包含索引,則可以簡化在丟失了屬於該資料表空間的資料檔案後的恢複工作。
如果丟失了此類資料檔案,則可以

執行以下步驟:
 

1.刪除資料檔案。

2.刪除資料表空間。
3.重新建立索引資料表空間。

4.重新建立包含在資料表空間中的索引。
1.可以在不執行 RECOVER 任務的情況下恢複僅包含索引的資料表空間。

2.如果屬於僅包含索引的資料表空間的資料檔案丟失,則更為簡單的方法可能是重新建立資料表空間和重新建立索引。

 

實驗:索引資料表空間資料檔案丟失

1.建立實驗資料;

create tablespace INT_TBS datafile
  '/u01/app/oracle/oradata/PROD/ind_tbs.dbf' size 20m;
create user ind_user indentified by user
    default tablespace ind_tbs;

grant dba to ind_user;

conn ind_user/user

create table t1 tablespace user
    as select  * from dba_objects
    where rownum<=100;

create index ind_t1_id on t1 (object_id);
create index ind_t1_name on t1 (upper(object_name));
create index ind_t1_com on t1 (object_id,object_name);

select index_name,tablespace_name,status from ind;
  --查看索引狀態

2.刪除所有資料表空間的資料檔案

!rm /u01/app/oracle/oradata/PROD/ind_tbs.dbf
!ls /u01/app/oracle/oradata/PROD/ind_tbs.dbf

3.觸發問題;
set autot traceonly
  --開啟跟蹤
select * from t1 where object_id=2;
  --報錯,索引檔案沒有找到
set autot off

alter index ind_t1_id rebuild online;
  --報錯,索引檔案未找到

4.重建索引並指定到別的資料表空間

set long 99999
select dbms_metadata.get_ddl('INDEX','IND_T1_ID') from dual;

IND_USER@PROD>select dbms_metadata.get_ddl('INDEX','IND_T1_ID') FROM DUAL;

  CREATE INDEX "IND_USER"."IND_T1_ID" ON "IND_USER"."T1" ("OBJECT_ID")
  PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
  BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
  TABLESPACE "IND_TBS"
  --建議關注compute statistics

alter index ind_t1_id rebulid online tablespace users;
alter index ind_t1_name rebulid online tablespace users;
alter index ind_t1_com rebulid online tablespace users;

select index_name,tablespace_name,status from ind;
  --查看重建結果

5.刪除或重建資料檔案丟失的索引資料表空間

drop tablespace ind_tbs including contents and datafiles;
  --刪除資料表空間
alter system datafile 7 offline;
  --如果刪除資料表空間報錯,資料檔案正在開啟,先offline 7 ,再刪除;

create tablespace ind_tbs datafile '/u01/app/oracle/oradata/PROD/ind_tbs.dbf' size 20m;

alter index ind_t1_id rebulid online tablespace ind_tbs;
alter index ind_t1_name  rebulid online tablespace ind_tbs;
alter index ind_t1_com rebulid online tablespace ind_tbs;

select index_name,tablespace_name,status from ind;
  --查看重建狀態;

Oracle 11g資料表空間dbf檔案遷移

移動Oracle資料表空間資料檔案方案

刪除暫存資料表空間ORA-25152錯誤

Oracle資料表空間增長異常解決又一例

Oracle資料表空間Offline的三種參數詳述

Oracle 11g下加密資料表空間的使用

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.