Home » Posts tagged 'rebuild index'

Tag Archives: rebuild index

Rebuild Index dan Alter Move Table


Dalam beberapa minggu terakhir ini gw cukup banyak berkutat dengan kasus index Oracle yang dalam state “UNUSABLE”. Awalnya juga heran kenapa bisa terjadi demikian. Setelah index-index itu dibenerin, gw mulai mencari-cari cara untuk mendapatkan informasi yang lebih jelas dan akurat.

Barusan baca ebook dari Rampant Techpress (milik jagoannya Oracle, yaitu Mr. Donald Burleson), ternyata ada informasi (yang dishare oleh Mike Hordila) bahwa sebagai rule of thumb adalah selalu melakukan rebuild index apabila kita telah melakukan rebuild table. Jadi jika kita melakukan rebuild dan compress index, maka kita diharuskan melakukan rebuild index (milik tabel yang bersangkutan). Karena jika tidak dilakukan maka index tersebut akan menjadi dalam state “UNUSABLE”.

Weleh…weleh…mesti dingat-ingat neeh…

Morale Story : “Lakukan rebuild index apabila kita melakukan rebuild table

Rebuild Index di Oracle 11g (rebuild online compress)


Setelah kasus ORA-01502 yang menyebabkan beberapa index tidak bisa diakses oleh user, maka dilakukan search index-index lain yang mengalami state serupa, yaitu UNUSABLE. Setelah didapatkan beberapa index, dilakukanlah rebuild index secara online dan sekaligus melakukan index compression.

Untuk melakukannya, gw langsung lewat sqlplus dan ajaibnya cara ini lebih cepat daripada menggunakan tools dari SAP (BRTOOLS). Bahkan kecepatannya bisa mencapai 2-3 kali lebih cepat.

Berikut script yang gw bikin untuk bisa melakukan rebuild index sekaligus kompresi.

sqlplus ‘/as sysdba’
spool /oracle/WPR/index_rebuild_log.txt
alter index SAPWPR.”ACCTIT~Z01″ rebuild online compress;
alter index SAPWPR.”S514~VAB” rebuild online compress;
alter index SAPWPR.”TCJ_POSITIONS~0″ rebuild online compress;
alter index SAPWPR.”S055~VAB” rebuild online compress;
alter index SAPWPR.”S055~0″ rebuild online compress;
alter index SAPWPR.”GLPCA~7″ rebuild online compress;
alter index SAPWPR.”GLPCA~3″ rebuild online compress;
alter index SAPWPR.”GLPCA~2″ rebuild online compress;
alter index SAPWPR.”FMEP~W” rebuild online compress;
alter index SAPWPR.”FMEP~V” rebuild online compress;
alter index SAPWPR.”FMEP~R” rebuild online compress;
alter index SAPWPR.”FMEP~M” rebuild online compress;
alter index SAPWPR.”FMEP~K” rebuild online compress;
alter index SAPWPR.”ACCTIT~1″ rebuild online compress;
alter index SAPWPR.”ACCTIT~0″ rebuild online compress;
spool off
exit

File diatas disimpan sebagai file sql (rebuild_index.sql) dan bisa dipanggil dari sqlplus.

Selamat mencoba !!

Script untuk rebuild index (kasus ora-01502)


Seperti postingan gw sebelumnya (), berikut adalah script untuk melakukan rebuild index-index yang berada dalam state “UNUSABLE“. Script kecil  sql sebagai berikut :

select 'alter index '||owner||'.'||index_name||' rebuild;' from
dba_indexes where STATUS = 'UNUSABLE';

Berikut adalah hasilnya :

‘ALTERINDEX’||OWNER||’.’||INDEX_NAME||’REBUILD;’
——————————————————————————–
alter index SAPWPR.ACCTIT~Z01 rebuild;
alter index SAPWPR.S514~VAB rebuild;
alter index SAPWPR.TCJ_POSITIONS~0 rebuild;
alter index SAPWPR.S055~VAB rebuild;
alter index SAPWPR.S055~0 rebuild;
alter index SAPWPR.GLPCA~7 rebuild;
alter index SAPWPR.GLPCA~3 rebuild;
alter index SAPWPR.GLPCA~2 rebuild;
alter index SAPWPR.FMEP~W rebuild;
alter index SAPWPR.FMEP~V rebuild;
alter index SAPWPR.FMEP~R rebuild;

‘ALTERINDEX’||OWNER||’.’||INDEX_NAME||’REBUILD;’
——————————————————————————–
alter index SAPWPR.FMEP~M rebuild;
alter index SAPWPR.FMEP~K rebuild;
alter index SAPWPR.ACCTIT~1 rebuild;
alter index SAPWPR.ACCTIT~0 rebuild;

15 rows selected.

Tinggal modifikasi sedikit menjadi seperti berikut :

alter index SAPWPR.”ACCTIT~Z01″ rebuild online compress;
alter index SAPWPR.”S514~VAB” rebuild online compress;
alter index SAPWPR.”TCJ_POSITIONS~0″ rebuild online compress;
alter index SAPWPR.”S055~VAB” rebuild online compress;
alter index SAPWPR.”S055~0″ rebuild online compress;
alter index SAPWPR.”GLPCA~7″ rebuild online compress;
alter index SAPWPR.”GLPCA~3″ rebuild online compress;
alter index SAPWPR.”GLPCA~2″ rebuild online compress;
alter index SAPWPR.”FMEP~W” rebuild online compress;
alter index SAPWPR.”FMEP~V” rebuild online compress;
alter index SAPWPR.”FMEP~R” rebuild online compress;
alter index SAPWPR.”FMEP~M” rebuild online compress;
alter index SAPWPR.”FMEP~K” rebuild online compress;
alter index SAPWPR.”ACCTIT~1″ rebuild online compress;
alter index SAPWPR.”ACCTIT~0″ rebuild online compress;

Bisa juga dijadikan script sql (misal buat file rebuild_index.sql) dan berisi seperti berikut :

sqlplus ‘/as sysdba’
spool /oracle/WPR/index_rebuild_log.txt
alter index SAPWPR.”ACCTIT~Z01″ rebuild online compress;
alter index SAPWPR.”S514~VAB” rebuild online compress;
alter index SAPWPR.”TCJ_POSITIONS~0″ rebuild online compress;
alter index SAPWPR.”S055~VAB” rebuild online compress;
alter index SAPWPR.”S055~0″ rebuild online compress;
alter index SAPWPR.”GLPCA~7″ rebuild online compress;
alter index SAPWPR.”GLPCA~3″ rebuild online compress;
alter index SAPWPR.”GLPCA~2″ rebuild online compress;
alter index SAPWPR.”FMEP~W” rebuild online compress;
alter index SAPWPR.”FMEP~V” rebuild online compress;
alter index SAPWPR.”FMEP~R” rebuild online compress;
alter index SAPWPR.”FMEP~M” rebuild online compress;
alter index SAPWPR.”FMEP~K” rebuild online compress;
alter index SAPWPR.”ACCTIT~1″ rebuild online compress;
alter index SAPWPR.”ACCTIT~0″ rebuild online compress;
spool off
exit

Selamat mencoba !!

Script to check index on unusable state


Seperti posting gw terdahulu disini (https://ardhian.wordpress.com/2011/10/19/oracle-ora-01502-on-sap-r3-4-7-ent-oracle-11g/), ternyata problem ini muncul pada saat upgrade Oracle dan beberapa index yang belum pernah gw rebuild ataupun rebuild compress pun mengalami hal yang sama. Berdasarkan data diatas, gw coba search di internet dan mendapatkan script sql kecil untuk mendapatkan informasi index mana saja yang mengalami state seperti ini.

Berikut script kecil itu :

select index_name, status, owner from
dba_indexes where STATUS = 'UNUSABLE';

Contoh yang gw dapat untuk eksekusi ini adalah.

SQL> select index_name, status, owner from
dba_indexes where STATUS = ‘UNUSABLE’;  2

INDEX_NAME                     STATUS   OWNER
—————————— ——– ——————————
ACCTIT~Z01                     UNUSABLE SAPWPR
S514~VAB                       UNUSABLE SAPWPR
TCJ_POSITIONS~0                UNUSABLE SAPWPR
S055~VAB                       UNUSABLE SAPWPR
S055~0                         UNUSABLE SAPWPR
GLPCA~7                        UNUSABLE SAPWPR
GLPCA~3                        UNUSABLE SAPWPR
GLPCA~2                        UNUSABLE SAPWPR
FMEP~W                         UNUSABLE SAPWPR
FMEP~V                         UNUSABLE SAPWPR
FMEP~R                         UNUSABLE SAPWPR

INDEX_NAME                     STATUS   OWNER
—————————— ——– ——————————
FMEP~M                         UNUSABLE SAPWPR
FMEP~K                         UNUSABLE SAPWPR
ACCTIT~1                       UNUSABLE SAPWPR
ACCTIT~0                       UNUSABLE SAPWPR

15 rows selected.

Solusi nya adalah melakukan rebuild index. Bisa rebuild biasa ataupun rebuild compress. Script solusi akan gw share ke posting berikutnya setelah gw uji coba.

Oracle : Reorganization dan Index Rebuilding


Ada 2 hal pelajaran yang gw dapet beberapa hari ini. Yang pertama adalah bahwa table reorganization tujuan utamanya adalah untuk claim wasted space di harddisk. Jadi proses reorganisasi tabel digunakan untuk meng-klaim space-space harddisk yang terbuang. Reorganisasi juga membantu untuk mempercepat akses ke tabel walaupun tidak banyak.

Second lesson is index rebuilding. Dalam beberapa hari ini keluhan user adalah akses ke beberapa tabel sangat lambat. Padahal tabel tidak terlalu besar, hanya beberapa GB. Akhirnya diputuskan untuk rebuild index. Semua index milik tabel itu di-rebuild. Hal ini ternyata sangat membantu program dan mempercepat akses ke tabel dan index tersebut.

Selama ini gw beranggapan bahwa reorganization adalah tools terbaik baik untuk klaim wasted space dan membantu mempercepat akses. Setelah membaca beberapa literatur dari SAP dan tentang cost based optimizer ternyata best practices nya adalah table reorgnization menggunakan temporary tablespace dan rebuild index.

Moral Story : Always study and check your Oracle scratchpad…