Tuesday, August 23, 2022
SET TERMOUT OFF;
COLUMN current_instance NEW_VALUE current_instance NOPRINT;
SELECT rpad(instance_name, 17) current_instance FROM v$instance;
SET TERMOUT ON;
PROMPT
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Rebuild Index Build Script |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------+
PROMPT
ACCEPT TS_NAME CHAR PROMPT 'Enter the index tablespace name : '
PROMPT
PROMPT Thanks... Creating rebuild index script for tablespace: &TS_NAME
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET LINESIZE 180
SET PAGESIZE 0
SET TERMOUT ON
SET TIMING OFF
SET TRIMOUT ON
SET TRIMSPOOL ON
SET VERIFY OFF
CLEAR COLUMNS
CLEAR BREAKS
CLEAR COMPUTES
SET TERMOUT OFF
spool rebuild_&TS_NAME._indexes.sql
SELECT 'REM FILE : rebuild_&TS_NAME._indexes.sql' FROM dual;
SELECT ' ' FROM dual;
SELECT 'REM' FROM dual;
SELECT 'REM ***** ALTER INDEX REBUILD commands for tablespace: &TS_NAME' FROM dual;
SELECT 'REM' FROM dual;
SELECT ' ' FROM dual;
SELECT
'REM +------------------------------------------------------------------------+' || chr(10) ||
'REM | INDEX NAME : ' || owner || '.' || segment_name
|| lpad('|', 58 - (length(owner) + length(segment_name)) )
|| chr(10) ||
'REM | BYTES : ' || bytes
|| lpad ('|', 59-(length(bytes)) ) || chr(10) ||
'REM | EXTENTS : ' || extents
|| lpad ('|', 59-(length(extents)) ) || chr(10) ||
'REM +------------------------------------------------------------------------+' || chr(10) ||
'ALTER INDEX ' || owner || '.' || segment_name || chr(10) ||
' REBUILD ONLINE' || chr(10) ||
' TABLESPACE ' || tablespace_name || chr(10) ||
' STORAGE ( ' || chr(10) ||
' INITIAL ' || initial_extent || chr(10) ||
' NEXT ' || next_extent || chr(10) ||
' MINEXTENTS ' || min_extents || chr(10) ||
' MAXEXTENTS ' || max_extents || chr(10) ||
' PCTINCREASE ' || pct_increase || chr(10) ||
');' || chr(10) || chr(10)
FROM dba_segments
WHERE segment_type = 'INDEX'
AND owner NOT IN ('SYS')
AND tablespace_name = UPPER('&TS_NAME')
ORDER BY owner, bytes DESC
/
SPOOL OFF
SET TERMOUT ON
PROMPT
PROMPT Done... Built the script rebuild_&TS_NAME._indexes.sql
PROMPT