oracle大表創建索引


1.表分析

查看有多少條記錄

SQL> select count(1) from abce;

查看表的大小

SQL> select segment_name,sum(bytes)/1024/1024 from dba_segments where segment_name='ABCE' group by segment_name;   

2.評估創建索引需要的數據空間 需要評估表空間、臨時表空間的大小是否滿足

使用執行計划評估一下要創建的索引的大小:

SQL> explain plan for create index idx_abce_update_time on abce(update_time);
SQL> select * from table(dbms_xplan.display);

查看表空間可用空間的大小:

SQL> select tablespace_name,sum(bytes)/1024/1024/1024 gb from dba_free_space where tablespace_name='TBS_ABCE' group by tablespace_name;

查看臨時表空間可用空間的大小:

SQL> select file_name,tablespace_name,bytes/1024/1024/1024 gb,autoextensible,maxbytes/1024/1024/1024 max_gb from dba_temp_files where tablespace_name='TEMP';

3.調整部分參數

適當調整db_file_multiblock_read_count

SQL> show parameter db_file_multiblock_read_count 
SQL> alter session set db_file_multiblock_read_count=256;

調大sort_area_size 創建索引時要對大量數據進行排序操做,在oracle11g,若是workarea_size_policy的值為AUTO,sort_area_size將被忽略,pga_aggregate_target將被啟用。 pga_aggregate_target決定了整個pga大小,並且一個session並不能使用所有的pga大小,它受到一個隱藏參數的限制,大體能使用pga_agregate_target的5%。

SQL> show parameter sort_area_size 
SQL> alter system set workarea_size_policy='MANUAL';
SQL> alter session set sort_area_size=xxx;

4.創建索引 SQL> create index ind_abce_update_time on abce(update_time);

單機且沒有dg的環境,可以考慮使用nologging;有dg的環境不能使用nologging方式。 也可以考慮並行和online,但是如果使用online,就不能同時開啟並行。

SQL> create index ind_abce_update_time on abce(update_time) online;
SQL> create index ind_abce_update_time on abce(update_time) parallel nologging;

如果開啟了並行,創建結束后要修改並行度:

SQL> alter index ind_abce_update_time noparallel;

如果使用了nologging:

SQL> alter index ind_abce_update_time logging;

可以借助sql監控報告,查看創建索引的報告

SQL> select dbms_sqltune.report_sql_monitor('gb7tu2jpwng3q') from dua

 

 

5.將參數調整回原樣

SQL> alter system set workarea_size_policy='AUTO';
SQL> alter session set db_file_multiblock_read_count = xxx;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM