Journal Tables are like any other IOT tables. I had explained their strcture in the recent post. This post will cover following points
- Behaviour of journal table.
- Effects of killing index in between.
Please click here to understand the basic structure of journal table.
Behaviour of Journal Table
As discussed earlier, journal tables are created when we issue alter index command and gets dropped only after the job completes successfully or cleans or cancelled successfully. Whenever we kill our session or cancel our job, oracle tries to clean the journal table . If you have killed your job (CTL C), oracle tries to get a latch and then merge the entries and then drop the journal table.
In case it does not, it will try fixed number of times and will then fail. This behaviour is explained in detail in later section. However, we must verify that journal tables are no longer present.
Test Case:-
From session 1 insert a row and issue rebuild comand from session 2 and then hit ctl c to cancel the job.
Session1>insert into mytab select * from mytab where rownum<2; Session2>alter index mytab_idx rebuild online; alter index mytab_idx rebuild online * ERROR at line 1: ORA-01013: user requested cancel of current operation< /*it will error out after 2000 retries or 20000 milli seconds. Discussed later */
Lets check if the journal table exists or not.
sesion2>select object_name,object_type,object_id from dba_objects where object_name='MYTAB_IDX'; OBJECT_NAME OBJECT_TYPE OBJECT_ID -------------------- -------------------- ---------- MYTAB_IDX INDEX 98701 1 row selected. session2>select object_name,object_type from dba_objects where object_name='SYS_JOURNAL_98701'; OBJECT_NAME OBJECT_TYPE -------------------- -------------------- SYS_JOURNAL_98701 TABLE 1 row selected.
As suspected , oracle timesout and left the cleaning part. All the transaction entries will now go into the journal table from now since the trigger has not been changed back to point to the index. Its still pointing to the journal table. As we can see,if the index rebuild job does not perform cleaning, the entries will stuck in journal table and we have to take manual steps to recover it.
session1>select * from SYS_JOURNAL_98701;
session1>insert into mytab(owner,object_name) values ('AFTER INDEX','CANCEL');
1 row created.
session1>commit;
Commit complete.
C0 C1 C2 OPCODE PARTNO RID
-------------------- ---------- ----- ---------- ------ ------------------
AFTER INDEX CANCEL I 0 D/////AAEAAAwQHAAL
1 row selected.
Effects of killing index in between
As we had already discussed that even after killing index job, oracle sometimes does not able to drop the journal table. Oracle will try exactly 2000 times with avg waitng time of 10 millli second (20,000 milli seconds in all), in case all the blocking sessions are inactive, to acquire a latch to clean the journal table.
Test Case
Lets insert a row without commiting and start rebuilding from next session.
Session1>insert into mytab select * from mytab where rownum<2; 1 row created. Session2>alter index mytab_idx rebuild online;
Lets check the status from session 3 using our ndx-progress.sql
SESSION3>@ndx-progress Enter value for sid: 2178 SID ---->2178 SERIAL ---->6537 MODULE ---->SQL*Plus MACHINE ---->db-fc-admin-6001.iad6.amazon.com USERNAME ---->SUBHATIA_DBA OSUSER ---->subhatia SQL TEXT ---->alter index mytab_idx rebuild online SQL ID ---->7sk4sratkuvq8 JOURNAL NAME ---->SYS_JOURNAL_98701 TABLE NAME ---->MYTAB EVENT_NAME ---->enq: TX - row lock contention IDLE SINCE ---->223 CPU TIME ---->35995 ELAPSED TIME ---->219143299 JOURNAL COUNT ---->0 STAGE ---->Waiting for first latch. LONGOPS ---->INDEX REBUILD NOT STARTED YET PROGRESS ---->No Tx started after index rebuild has commited yet. There are 0 rows in journal table ------------SESSIONS BLOCKING FIRST LATCH ARE------------- SID SERIAL STATUS LAST_CALL_ET COMMAND SQL_ID PREV_SQL_ID MODULE MACHINE 2154 9407 INACTIVE 249 0 NONE 9babjv8yq8ru3 SQL*Plus db-fc-admin-6001.iad6.amazon.com ------------SESSIONS THAT MAY BLOCK LAST LATCH ARE------------- SID SERIAL STATUS LAST_CALL_ET COMMAND SQL_ID PREV_SQL_ID MODULE MACHINE NO POTENTIAL BLOCKERS FOUND FOR THE LAST LATCH
As expected, our insert has blocked the index rebuild. Lets cancel the job(ctl c) and check whats happening now using ndx-progress.
Yes, ndx-progress can report that one too (amazing).
SESSION3>@ndx-progress Enter value for sid: 2178 Index Rebuild has been cancelled. Cleaning going on SID ---->2178 SERIAL ---->6537 MODULE ---->SQL*Plus MACHINE ---->db-fc-admin-6001.iad6.amazon.com USERNAME ---->SUBHATIA_DBA OSUSER ---->subhatia SQL TEXT ---->alter index mytab_idx rebuild online SQL ID ---->7sk4sratkuvq8 JOURNAL NAME ---->SYS_JOURNAL_98701 TABLE NAME ---->MYTAB EVENT_NAME ---->index (re)build online cleanup IDLE SINCE ---->2116 CPU TIME ---->2164672 ELAPSED TIME ---->2113894321 JOURNAL COUNT ---->0 ------------SESSIONS BLOCKING CLEANING PROCESS------------- SID SERIAL STATUS LAST_CALL_ET COMMAND SQL_ID PREV_SQL_ID MODULE MACHINE 2154 9407 INACTIVE 2145 0 NONE 9babjv8yq8ru3 SQL*Plus db-fc-admin-6001.iad6.amazon.com ------------CLEANUP PROCESS TIMOUT------------- EVENT TOTAL WAITS TOTAL TIMEOUTS TIME WAITED AVG WAIT MAX WAIT index (re)build online cleanup 1967 1967 19799 10.07 10 10
On checking the status, index job was cancelled but journal entry was still there
Session2>alter index mytab_idx rebuild online; alter index mytab_idx rebuild online * ERROR at line 1: ORA-01013: user requested cancel of current operation SESSION3>select event,total_waits,total_timeouts,time_waited,average_wait,max_wait from v$session_event where sid=2178 and event='index (re)build online cleanup'; EVENT TOTAL_WAITS TOTAL_TIMEOUTS TIME_WAITED AVERAGE_WAIT MAX_WAIT ------------------------------ ----------- -------------- ----------- ------------ ---------- index (re)build online cleanup 2000 2000 20131 10.07 10 1 row selected.
As we can check, oracle tries for 2000 times but timeout each time. it kept tring for 2000*10 ms and then error out.
