Pojok Oracle edisi 24 April 2006 --------------------------------- Do you Yahoo!? Yahoo! Movies - Search movie info and celeb profiles and photos. ----------
***************************************************************************** Pojok Oracle Edisi 24 April 2006 Redaksi Erick [EMAIL PROTECTED] ***************************************************************************** Loocking.. Mengapa ada mekanisme locking? -> Data concurrency, data akan di kunci selama data yang dimasukan belum di commit atau di rollback. -> Read consistency, semua proses dapat membaca data yang sama seperti aslinya sebelum dilakukan perubahan. Ada dua macam locking dalam oracle, yaitu: -> Row level locking, setiap baris data dapat di dikunci (lock) secara individual tanpa mempengaruhi baris data yang lainnya. Hal ini untuk menjamin adanya data yang konsisten (consistent read). -> Table level locking, setiap tabel dapat dikunci dan proses pada tabel itu hanya dapat dilakukan oleh proses yang mengunci table tersebut. Proses yang dapat mengakses table ini hanya proses yang sifatnya membaca data dalam tabel. Mode locking dalam oracle antara lain: -> Exclusive lock mode (X), mencegah resource yang sama untuk dibagi (share) yang biasa terjadi pada proses merubah data. o SELECT ... FROM table ... (mode lock: tidak di kunci). o INSERT INTO table ... (mode lock: Row Exclusive (RX)). o UPDATE table ... (mode lock: Row Exclusive (RX)). o DELETE FROM table ... (mode lock: Row Exclusive (RX)). o LOCK TABLE table IN ROW EXCLUSIVE MODE (mode lock: Row Exclusive (RX)). o LOCK TABLE table IN SHARE ROW EXCLUSIVE MODE (mode lock: Share Row Exclusive (SRX)). o LOCK TABLE table IN EXCLUSIVE MODE (mode lock: Exclusive (X)). -> Share lock mode (S), mengizinkan resource untuk dibagi berdasarkan pada operasi yang terlibat. o SELECT ... FROM table FOR UPDATE OF ... (mode lock: Row Share (RS)). o LOCK TABLE table IN ROW SHARE MODE (mode lock: Row Share (RS)). o LOCK TABLE table IN SHARE MODE (mode lock: Share (S)). o LOCK TABLE table IN SHARE ROW EXCLUSIVE MODE (mode lock: Share Row Exclusive (SRX)). Row Share Table locks (RS) Row share table lock (RS) menandakan bahwa transaksi mengunci tabel beserta baris-baris data di dalamnya untuk proses update. Contoh. Sesi 1 Select job from emp where job = CLERK for update of empno; (OK) Sesi 2 Select job from emp where job = CLERK for update of empno; (waiting) Select job from emp where job = MANAGER for update of empno; (OK) Lock table emp in share mode; (OK) Lock table emp in exclusive mode; (waiting) Insert into emp (empno, ename) values (9999,test); (OK) Delete from emp where empno = 9999; (OK) Delete from emp where empno = 7876; (waiting) --> di kunci oleh sesi 1 Update emp set job = CLIMBER where empno = 7876; (waiting) --> di kunci sesi 1 * setiap baris command diatas antara sesi 1 dan sesi 2 berada dalam satu baris. Status waiting menunjukkan bahwa command itu tidak bisa diproses dan menunggu resource untuk dilepaskan dari penguncian Jalankan skrip berikut ini, Select substr(to_char(session_id,1,5) SID, substr(lock_type,1,15) Lock Type, substr(mode_held,1,15) Mode Held, substr(Blocking_Others,1,15) Blocking? from dba_locks; Pada hasil query diatas terlihat bahwa ada transaksi yang di bloking (transaksi pada sesi 1) dan transaksi yang tidak di bloking dengan mode SX (transaksi pada sesi 2). Row Exclusive table locks (RX) Row Exclusive table locks (RX) menandakan bahwa transaksi mengunci satu atau lebih baris data dalam tabel. Contoh: Sesi 1 Update emp set ename = Zahn; (OK) Sesi 2 Lock table emp in exclusive mode; (waiting) * setiap baris command diatas antara sesi 1 dan sesi 2 berada dalam satu baris. Status waiting menunjukkan bahwa command itu tidak bisa diproses dan menunggu resource untuk tabel emp dilepaskan dari penguncian. Share table locks (S) Mode lock ini otomatis terjadi jika ada pernyataan seperti berikut: LOCK TABLE table_name IN SHARE MODE; Perlu diperhatikan jika satu table dikunci oleh beberapa proses dengan menggunakan mode lock share, maka proses update tidak bisa dilakukan dan bisa terjadi deadlock. Lebih disarankan untuk menggunakan mode lock share row exclusive (SRX) atau exclusive table lock. Exclusive table locks (X) Exclusive table locks (X) adalah mode lock yang paling ketat, mengijinkan transaksi untuk mengunci akses untuk menulis ke tabel. Kesimpulan Pembuat aplikasi seharusnya mempertimbangkan masalah locking ini dalam pembuatan aplikasi agar tidak terjadi deadlock pada multi user environment dengan transaksi yang memerlukan beberapa resource. [Non-text portions of this message have been removed] -- www.itcenter.or.id - Komunitas Teknologi Informasi Indonesia Info, Gabung, Keluar, Mode Kirim : [EMAIL PROTECTED] :: Hapus bagian yang tidak perlu (footer, dst) saat reply! :: ## Jobs: itcenter.or.id/jobs ## Bursa: itcenter.or.id/bursa ## $$ Iklan/promosi : www.itcenter.or.id/sponsorship $$ [@@] Jaket ITCENTER tersedia di http://shop.itcenter.or.id Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/ITCENTER/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/