自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

教您如何實現(xiàn)Oracle重建索引

數(shù)據(jù)庫 Oracle
如果Oracle數(shù)據(jù)庫下某些應(yīng)用項目有大量的修改刪除操作,就需要周期性的重建索引,提高Oracle數(shù)據(jù)庫的查詢效率。

Oracle重建索引操作大家經(jīng)常會用到,下面就為您詳細介紹Oracle重建索引方面的知識,供您參考,如果您對此方面感興趣的話,不妨一看。

如果你管理的Oracle數(shù)據(jù)庫下某些應(yīng)用項目有大量的修改刪除操作, 數(shù)據(jù)索引是需要周期性的重建的.

它不僅可以提高查詢性能, 還能增加索引表空間空閑空間大小. 在ORACLE里大量刪除記錄后, 表和索引里占用的數(shù)據(jù)塊空間并沒有釋放. Oracle重建索引可以釋放已刪除記錄索引占用的數(shù)據(jù)塊空間. 轉(zhuǎn)移數(shù)據(jù), 重命名的方法可以重新組織表里的數(shù)據(jù).

下面是可以按ORACLE用戶名生成Oracle重建索引的SQL腳本:

  1. SET ECHO OFF;   
  2.  
  3. SET FEEDBACK OFF;   
  4.  
  5. SET VERIFY OFF;   
  6.  
  7. SET PAGESIZE 0;   
  8.  
  9. SET TERMOUT ON;   
  10.  
  11. SET HEADING OFF;   
  12.  
  13. ACCEPT username CHAR PROMPT 'Enter the index username: ';   
  14.  
  15. spool /oracle/rebuild_&username.sql;   
  16.  
  17. SELECT   
  18.  
  19. 'REM +-----------------------------------------------+' || chr(10) ||   
  20.  
  21. 'REM | INDEX NAME : ' || owner || '.' || segment_name   
  22.  
  23. || lpad('|', 33 - (length(owner) + length(segment_name)) )   
  24.  
  25. || chr(10) ||   
  26.  
  27. 'REM | BYTES : ' || bytes   
  28.  
  29. || lpad ('|', 34-(length(bytes)) ) || chr(10) ||   
  30.  
  31. 'REM | EXTENTS : ' || extents   
  32.  
  33. || lpad ('|', 34-(length(extents)) ) || chr(10) ||   
  34.  
  35. 'REM +-----------------------------------------------+' || chr(10) ||   
  36.  
  37. 'ALTER INDEX ' || owner || '.' || segment_name || chr(10) ||   
  38.  
  39. 'REBUILD ' || chr(10) ||   
  40.  
  41. 'TABLESPACE ' || tablespace_name || chr(10) ||   
  42.  
  43. 'STORAGE ( ' || chr(10) ||   
  44.  
  45. ' INITIAL ' || initial_extent || chr(10) ||   
  46.  
  47. ' NEXT ' || next_extent || chr(10) ||   
  48.  
  49. ' MINEXTENTS ' || min_extents || chr(10) ||   
  50.  
  51. ' MAXEXTENTS ' || max_extents || chr(10) ||   
  52.  
  53. ' PCTINCREASE ' || pct_increase || chr(10) ||   
  54.  
  55. ');' || chr(10) || chr(10)   
  56.  
  57. FROM dba_segments   
  58.  
  59. WHERE segment_type = 'INDEX'   
  60.  
  61. AND owner='&username'   
  62.  
  63. ORDER BY owner, bytes DESC;   
  64.  
  65. spool off;   

如果你用的是WINDOWS系統(tǒng), 想改變輸出文件的存放目錄, 修改spool后面的路徑成:

spool c:\oracle\rebuild_&username.sql;

如果你只想對大于max_bytes的索引重建索引, 可以修改上面的SQL語句:

在AND owner='&username' 后面加個限制條件 AND bytes> &max_bytes

如果你想修改索引的存儲參數(shù), 在Oracle重建索引rebuild_&username.sql里改也可以. 比如把pctincrease不等于零的值改成是零. 生成的rebuild_&username.sql文件我們需要來分析一下, 它們是否到了需要重建的程度:

分析索引,看是否碎片嚴重

  1. SQL>ANALYZE INDEX &index_name VALIDATE STRUCTURE;   
  2.  
  3. col name heading 'Index Name' format a30   
  4.  
  5. col del_lf_rows heading 'Deleted|Leaf Rows' format 99999999   
  6.  
  7. col lf_rows_used heading 'Used|Leaf Rows' format 99999999   
  8.  
  9. col ratio heading '% Deleted|Leaf Rows' format 999.99999   
  10.  
  11. SELECT name,   
  12.  
  13. del_lf_rows,   
  14.  
  15. lf_rows - del_lf_rows lf_rows_used,   
  16.  
  17. to_char(del_lf_rows / (lf_rows)*100,'999.99999') ratio   
  18.  
  19. FROM index_stats where name = upper('&index_name');   

當刪除的比率大于15 - 20% 時,肯定是需要索引重建的. 經(jīng)過刪改后的rebuild_&username.sql文件我們可以放到ORACLE的定時作業(yè)里:

比如一個月或者兩個月在非繁忙時間運行. 如果遇到ORA-00054錯誤, 表示索引在的表上有鎖信息, 不能重建索引. 那就忽略這個錯誤, 看下次是否成功. 對那些特別忙的表要區(qū)別對待, 不能用這里介紹的方法, 還要把它們的索引從rebuild_&username.sql里刪去。
 

 

【編輯推薦】

全面解析Oracle文件系統(tǒng)

當前Oracle系統(tǒng)時間的查詢方法

ORACLE系統(tǒng)表和數(shù)據(jù)字典視圖

深度解析Oracle ERP系統(tǒng)模塊

詳解四大類Oracle索引掃描

   

 

責任編輯:段燃 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-10-26 10:48:16

ORACLE備份

2010-11-18 16:27:37

2010-11-18 16:41:13

oracle死鎖

2010-10-12 14:53:31

mysql索引優(yōu)化

2010-11-16 09:18:39

oracle重建索引

2010-10-26 16:54:16

oracle全文索引

2010-10-13 15:59:21

MySQL索引

2010-10-28 11:29:18

ORACLE用戶權(quán)限

2010-10-29 13:30:33

Oracle歸檔日志

2010-10-27 16:56:05

Oracle重復(fù)記錄

2010-10-28 09:21:42

oracle中存圖片

2010-10-29 11:51:30

oracle用戶名

2010-09-26 13:56:43

SQL遠程查詢

2010-11-29 13:28:55

sybase自動備份

2010-11-22 16:05:53

MySQL多表插入

2010-11-25 14:56:46

MySQL全文查詢

2010-10-14 10:28:18

MySQL動態(tài)視圖

2010-09-28 11:07:37

SQL索引

2010-10-08 10:37:00

MYSQL添加新字段

2010-10-19 16:58:34

SQL Server日
點贊
收藏

51CTO技術(shù)棧公眾號