oracle - Detecting a Deadlock in a Stored Procedure -
i trying write deadlock proof stored procedure. based on following concept.
i have been trying write stored procedure based on following concept. procedure try drop constraint on table , if in case detects deadlock situation, wait time before trying again. important thing should retry in case of deadlock or nowait error, other errors handled via exceptions.
procedure test begin <<label>> drop constraint on table if (deadlock(ora-00060)/nowait error (ora-0054)) detected sleep 60 seconds goto label exception when others.
it great if of experts please me this. similar example highly helpful. thank help.
while people harbour irrational aversion goto
remains true can implement same logic without using construct. true here: simple while
loop necessary:
create or replace procedure drop_constraint_for_sure ( p_table_name in varchar2 , p_constraint_name in varchar2 ) x_deadlock exception; pragma exception_init(x_deadlock, -60); x_nowait exception; pragma exception_init(x_nowait, -54); begin loop begin execute immediate 'alter table '|| p_table_name || ' drop constraint ' || p_constraint_name || ' cascade' ; exit; exception when x_deadlock null; when x_nowait null; end; dbms_lock.sleep(60); end loop; end; /
note sleep function requires execute
privilege on sys.dbms_lock. not granted default, if don't have you'll need ask friendly dba grant it.
also note implementation doesn't have form of abort. loop eternally, until constraint dropped or other exception occurs. in real life should include loop count additional exit test on threshold count. although in real life wouldn't want stored procedure anyway: prefer knowing possible when using table i'm trying alter.
wiki
Comments
Post a Comment