Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Killing orphaned two phase commit transactions

724046Mar 2 2010 — edited Mar 2 2010
Was there ever a solution to this thread or anyone know how to solve this issue:
[Thread from before|http://forums.oracle.com/forums/thread.jspa?threadID=222949&tstart=435]

I am running into the same issue where:
SQL> rollback force '1.5.550355';
 
rollback force '117.28.39057'
 
ORA-02058: no prepared transaction found with ID 1.5.550355

SQL> exec admin.admin_dba_main.KILL_ORPH_2PHASE_COMMITS();  -->my package name
 
begin admin.admin_dba_main.KILL_ORPH_2PHASE_COMMITS(); end;
 
ORA-01031: insufficient privileges -->this is a weird one as I am logged in as a SYSDBA user
ORA-06512: at "SYS.DBMS_TRANSACTION", line 88
ORA-06512: at "ADMIN.ADMIN_DBA_MAIN", line 44
ORA-02058: no prepared transaction found with ID 1.5.550355
ORA-06512: at line 2
My package consists of:
CREATE OR REPLACE PACKAGE ADMIN."ADMIN_DBA_MAIN" IS
  -- CURSORS **************************************************************************
  CURSOR cur_2pc IS
    SELECT p.local_tran_id FROM DBA_2PC_PENDING p;

  -- KILL_ORPH_2PHASE_COMMITS ****************************************************************
  PROCEDURE KILL_ORPH_2PHASE_COMMITS(inLocal_tran_id IN varchar2 :=NULL);

END ADMIN_DBA_MAIN;

CREATE OR REPLACE PACKAGE BODY ADMIN."ADMIN_DBA_MAIN" IS

  -- KILL_ORPH_2PHASE_COMMITS ****************************************************************
  -- Will clean orphaned processes foun in dba_2pc_pending view.
  -- Raman Gill
  PROCEDURE KILL_ORPH_2PHASE_COMMITS(inLocal_tran_id IN varchar2 :=NULL) is
    tsql            VARCHAR2(256);
    v_local_tran_id varchar2(22 byte);
  
  BEGIN
    IF inLocal_tran_id is not null then
    
      tsql := 'ROLLBACK FORCE ''' || inLocal_tran_id || '''';
      dbms_output.put_line(tsql);
    
      EXECUTE IMMEDIATE tsql;
      commit;
      RETURN;
    END IF;
    
    --open cursor
    open cur_2pc;
  
    LOOP
      --fetch cursor data
      fetch cur_2pc
        into v_local_tran_id;
    
      exit when cur_2pc%NOTFOUND;
      BEGIN
        tsql := 'ROLLBACK FORCE ''' || v_local_tran_id || '''';
        dbms_output.put_line(tsql);
      
        EXECUTE IMMEDIATE tsql;
      EXCEPTION
        WHEN OTHERS THEN
          dbms_transaction.purge_lost_db_entry('''' || v_local_tran_id || '''');
          commit;
          CLOSE cur_2pc;
      END;
    END LOOP;
    CLOSE cur_2pc;
  
  END KILL_ORPH_2PHASE_COMMITS;
I even issued commits and rollbacks in between with same issue.

I also read where sometimes it is not possible because you do not have rows in DBA_2PC_PENDING view. If this is the case, you can insert dummy rows into SYS.PENDING_TRANS$, and SYS.PENDING_SESSIONS$ tables to correct this.

I found this thread: 417195
ancesar wrote:
Below is a script that can help you if you do not have rows in DBA_2PC_PENDING view. Just enter the TRANSACTION ID, got from ORA-1591 error or from alertlog files.

--
-- Execute it connected as SYS or SYSDBA
--
ACCEPT TRANSACTION_ID PROMPT "Enter TRANSACTION ID: "
alter system disable distributed recovery;
insert into pending_trans$ (
LOCAL_TRAN_ID,
GLOBAL_TRAN_FMT,
GLOBAL_ORACLE_ID,
STATE,
STATUS,
SESSION_VECTOR,
RECO_VECTOR,
TYPE#,
FAIL_TIME,
RECO_TIME)
values( '&&TRANSACTION_ID',
306206, /* */
'XXXXXXX.12345.1.2.3', /* These values can be used without any */
'prepared','P', /* modification. Most of the values are */
hextoraw( '00000001' ), /* constant. */
hextoraw( '00000000' ), /* */
0, sysdate, sysdate );
insert into pending_sessions$
values( '&&TRANSACTION_ID',
1, hextoraw('05004F003A1500000104'),
'C', 0, 30258592, '',
146
);
commit;
rollback force '&&TRANSACTION_ID'; /* or commit force */
commit;
alter system enable distributed recovery;
exec dbms_transaction.purge_lost_db_entry( '&&TRANSACTION_ID' );
commit;
delete from pending_trans$ where local_tran_id='&&TRANSACTION_ID';
delete from pending_sessions$ where local_tran_id='&&TRANSACTION_ID';
commit;
But this to me does not make sense cause I queried the 3 views and they all show me the records so clearly all the data is in all 3 tables.

Any help? Unfortuneatly there is hardly any info out there!

FYI, all my records in the tables are in the state of 'COLLECTING'.

Edited by: Gunners on Mar 2, 2010 11:57 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 30 2010
Added on Mar 2 2010
1 comment
2,109 views