Rebuild Indexes
-----check INDEX SIZE more than 1 gega bytes
SELECT OWNER AS OWNER,
SEGMENT_NAME AS SEGMENT_NAME,
SEGMENT_TYPE,
SUM(BYTES) / 1024 / 1024 AS "SEGMENT_SIZE(M)"
FROM DBA_SEGMENTS
WHERE TABLESPACE_NAME = '&TBS'
AND BYTES > 1073741824
GROUP BY OWNER, SEGMENT_NAME,SEGMENT_TYPE
ORDER BY 3;
----analyze the INDEXES in tablespace which the space used rate are too high
SELECT 'ANALYZE INDEX ' || SEGMENT_NAME || ' VALIDATE STRUCTURE;'
FROM DBA_SEGMENTS
WHERE TABLESPACE_NAME = '&TBS'
AND BYTES > 1073741824
AND SEGMENT_TYPE = 'INDEX'
ORDER BY SEGMENT_NAME;
----check the empty blocks in INDEXES
SELECT NAME, BLOCKS, LF_BLKS, BR_BLKS, BLOCKS - (LF_BLKS + BR_BLKS) EMPTY
FROM INDEX_STATS
WHERE NAME IN (SELECT SEGMENT_NAME
FROM DBA_SEGMENTS
WHERE TABLESPACE_NAME = '&TBS'
AND BYTES > 1073741824
AND SEGMENT_TYPE = 'INDEX'
ORDER BY SEGMENT_NAME);
----check delete rows in INDEXES
SELECT NAME,
LF_ROWS,
T.LF_BLKS,
T.DEL_LF_ROWS,
(T.DEL_LF_ROWS / T.LF_ROWS) * 100 RATIO
FROM INDEX_STATS T
WHERE T.NAME = '&IND_NAME';
----check INDEXES degree and usage rate
SELECT HEIGHT, NAME, BTREE_SPACE, USED_SPACE, PCT_USED FROM INDEX_STATS;
if found the degree of indexes are bigger than 4, We can rebuild those indexes
----gather table
SELECT 'exec dbms_stats.gather_table_stats(''' || OWNER || ''',''' ||
TABLE_NAME || ''',' || 'DEGREE=>8,CASCADE => TRUE);'
FROM DBA_INDEXES
WHERE TABLESPACE_NAME = '&TBS';
----ensure indexes used size
SELECT OWNER AS OWNER,
SEGMENT_NAME AS SEGMENT_NAME,
SUM(BYTES) / 1024 / 1024 AS "SEGMENT_SIZE(M)"
FROM DBA_SEGMENTS
WHERE TABLESPACE_NAME = 'MD0002ASTCOM_SNAP_INDEX'
GROUP BY OWNER, SEGMENT_NAME
ORDER BY 3;
----connect the schema where indexes is
alter session set current_schema=MD0002ASTCOM;
----rebuild the indexes which size are bigger than 2G
select 'alter index '||owner||'.'||index_name|| ' rebuild online' from dba_indexes where tablespace_name='MD0002ASTCOM_SNAP_INDEX';
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26477398/viewspace-2122498/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- best practice of rebuild your partition table local index online by using: "update indexes"RebuildIndex
- alter index rebuild 與 rebuild onlineIndexRebuild
- rebuild indexRebuildIndex
- index rebuildIndexRebuild
- Rebuild TreeRebuild
- ORACLE INDEXESOracleIndex
- rebuild與rebuild online效率比對Rebuild
- 聊聊索引Index Rebuild和Rebuild Online(下)索引IndexRebuild
- 索引rebuild和rebuild online時要慎重索引Rebuild
- 聊聊索引Index Rebuild和Rebuild Online(上)索引IndexRebuild
- rebuild index 排序RebuildIndex排序
- sybase rebuild indexRebuildIndex
- Oracle - Tables/IndexesOracleIndex
- Reverse Key IndexesIndex
- ORACLE -> NULL & INDEXESOracleNullIndex
- Overview of Partitioned IndexesViewIndex
- Local Partitioned IndexesIndex
- Global Nonpartitioned IndexesIndex
- Extents in Indexes (19)Index
- alter index rebuild和rebuild online的區別IndexRebuild
- 翻譯(九)——Clustered Indexes: Stairway to SQL Server Indexes Level 3IndexAISQLServer
- 索引rebuild和rebuild online時要慎重(轉載)索引Rebuild
- Index rebuild --case 1IndexRebuild
- MSSQL Rebuild(重建)索引SQLRebuild索引
- skip_unusable_indexesIndex
- The Secrets of Oracle Bitmap IndexesOracleIndex
- Restrictions on Create Bitmap IndexesRESTIndex
- Global Range Partitioned IndexesIndex
- Global Hash Partitioned IndexesIndex
- Maintenance of Global Partitioned IndexesAINaNIndex
- Overview of Indexes (194)ViewIndex
- Indexes and Nulls (198)IndexNull
- ORACLE中index的rebuildOracleIndexRebuild
- Index Online RebuildIndexRebuild
- Sparse Indexes vs unique indexIndex
- SKIP_UNUSABLE_INDEXES InitializationIndex
- Choosing Composite IndexesIndex
- 建立Function-Based IndexesFunctionIndex