Pages

Monday, January 15, 2024

ALTER INDEX REBUILD ONLINE in Standard Edition Oracle (SE)

Option A
ALTER INDEX IX01 REBUILD ONLINE = 
ALTER INDEX 
IX01 COALESCE; + ALTER INDEX IX01 SHRINK SPACE;

Option B
Get DDL
SET LONG 1000
SET PAGESIZE 0
SET LINESIZE 400
COL DDL_CMD FOR A400 WORD_WRAP
SET FEEDBACK OFF
SET HEADING OFF

SELECT DBMS_METADATA.get_dependent_ddl('INDEX','GA_W_COUNTERS_HISTORY', 'MY_USER') AS DDL_CMD FROM DUAL;

Drop and Create the Index using the generated DDL.


Automate the process
crontab 
1 6 * * * bash -l /software/oracle/oracle/scripts/rebuild_ix/rebuild_ix.sh

rebuild_ix.sh
#!/bin/bash

WORK_DIR=/software/oracle/oracle/scripts/rebuild_ix
. /etc/sh/orash/oracle_login.sh igt

ORACLE_SID=igt
ORACLE_BASE=/software/oracle
ORACLE_HOME=/software/oracle/121

cd ${WORK_DIR}
sqlplus / as sysdba @rebuild_ix.sql

rebuild_ix.sql
ALTER INDEX USER_A.INDEX_A COALESCE;
ALTER INDEX USER_A.INDEX_A SHRINK SPACE;

ALTER INDEX USER_B.INDEX_B COALESCE;
ALTER INDEX USER_B.INDEX_B SHRINK SPACE;

EXIT;


No comments:

Post a Comment