SQL> SELECT KTUXEUSN, KTUXESLT, KTUXESQN, /* Transaction ID */ 2 KTUXESTA Status, KTUXECFL Flags ,KTUXESIZ 3 FROM x$ktuxe 4 WHERE ktuxesta!='INACTIVE'; KTUXEUSN KTUXESLT KTUXESQN STATUS FLAGS KTUXESIZ ---------- ---------- ---------- ---------------- ------------------------ ---------- 13 5 47447 ACTIVE DEAD 2819919 39 0 502 ACTIVE NONE 1 43 45 480 ACTIVE NONE 0
SQL> / KTUXEUSN KTUXESLT KTUXESQN STATUS FLAGS KTUXESIZ ---------- ---------- ---------- ---------------- ------------------------ ---------- 13 5 47447 ACTIVE DEAD 2819919<----該值沒減小。 39 0 502 ACTIVE NONE 1 43 45 480 ACTIVE NONE 0
查詢v$px_session和v$fast_start_servers,顯示很多並行進程在rollback,根據以往的工程經驗:
於是改為
SQL>alter system set fast_start_parallel_rollback=false scope=both;
之後,再次運行
SQL> SELECT KTUXEUSN, KTUXESLT, KTUXESQN,/* Transaction ID */ 2 KTUXESTA Status, KTUXECFL Flags ,KTUXESIZ 3 FROM x$ktuxe 4 WHERE ktuxesta!='INACTIVE'; KTUXEUSN KTUXESLT KTUXESQN STATUS FLAGS KTUXESIZ ---------- ---------- -------------------------- ------------------------ ---------- 13 5 47447 ACTIVE DEAD 2033516 35 29 502 ACTIVE NONE 1 SQL> / KTUXEUSN KTUXESLT KTUXESQN STATUS FLAGS KTUXESIZ ---------- ---------- -------------------------- ------------------------ ---------- 13 5 47447 ACTIVE DEAD 2033433<---該值不斷變小。 35 29 502 ACTIVE NONE 1
使用如下腳本查看回滾完畢的預計時間(以天為單位):
SQL> set serveroutput on SQL> declare 2 l_start number; 3 l_end number; 4 begin 5 select ktuxesiz into l_startfrom x$ktuxe where KTUXEUSN=13 and KTUXESLT=5; 6 dbms_lock.sleep(60); 7 select ktuxesiz into l_endfrom x$ktuxe where KTUXEUSN=13 and KTUXESLT=5; 8 dbms_output.put_line('time estDay:'|| round(l_end/(l_start -l_end)/60/24,2)); 9 end; 10 / time est Day:.21
24*0.21=5.04小時。即:預計5.04小時後回滾完畢。
另外注意:在其他環境使用時,請注意替換KTUXEUSN=13和KTUXESLT=5
select sid,serial#,sql_text,executions from v$sql join v$session on v$sql.sql_id=v$session.sql_id where cpu_time>20000;
檢查查出來的會話,如果sql_text正確的話,記下sid和serial#,執行以下語句殺死
alter system kill session ‘sid,serial#';
SQL> select * from test_main;
ID VALUE
---------- --------------------
2 TWO
3 THREE
1 ONE
SQL> BEGIN
2 -- 插入2條同樣的數據,使主鍵重復,引發錯誤後回滾事務.
3 INSERT INTO test_main(id, value) VALUES (4, 'FOUR');
4 INSERT INTO test_main(id, value) VALUES (4, 'FOUR');
5 COMMIT;
6 EXCEPTION
7 WHEN OTHERS THEN
8 dbms_output.put_line('Error Code = ' || TO_CHAR(SQLCODE) );
9 dbms_output.put_line('Error Message = ' || SQLERRM );
10 -- 回滾事務
11 ROLLBACK;
12 END;
13 /
PL/SQL procedure successfully completed.
SQL> select * from test_main;
ID VALUE
---------- --------------------
2 TWO
3 THREE
1 ONE
SQL>