Home » SQL & PL/SQL » SQL & PL/SQL » Using DBMS_LOCK.RELEASE to release the lock owned by another process
Using DBMS_LOCK.RELEASE to release the lock owned by another process [message #10989] Sat, 28 February 2004 03:41 Go to next message
Sivakrishna
Messages: 2
Registered: February 2004
Junior Member
Hi,

We are using dbms_lock package in our application to ensure that only one process instance is running.

Before the process starts, it gets the lock handle. The lockname is the process name <PROCESS>. Then it requests the lock.

The code I used:

var lock_handle varchar2(300);

var result number;

begin

dbms_lock.allocate_unique(<PROCESS>,:lock_handle);

:result:=dbms_lock.request(:lock_handle);

end;

It is working fine, as the first process instance requests the lock and when a second instance requests the lock, it is denied (meaning an instance is already running).

The problem is, in case the first process got hanged or the connection to database is lost due to network failure, it won't be able to release the lock. Another instance won't be started because the lock is still present. Can we release the lock manually logging to a sqlplus session?

I tried to do the following logging into a sqlplus session.


var lock_handle varchar2(300);


var result number;

begin

:result:=dbms_lock.release(:lock_handle);

end;

/

print v_result;

The output was:

  V_RESULT
----------
         4

which means - 'Do not own lock; cannot release'.

Please let me know what should be done to release this lock.

Thank you
Re: Using DBMS_LOCK.RELEASE to release the lock owned by another process [message #10990 is a reply to message #10989] Sat, 28 February 2004 06:53 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9088
Registered: November 2002
Location: California, USA
Senior Member
I don't believe you can release another user's lock using dbms_lock.release. I think your only option may be to kill the session, then wait for the rollback. If it has been running for hours, then it may take hours to rollback before the lock is released.
Re: Using DBMS_LOCK.RELEASE to release the lock owned by another process [message #11001 is a reply to message #10990] Sun, 29 February 2004 17:45 Go to previous messageGo to next message
Sivakrishna
Messages: 2
Registered: February 2004
Junior Member
Hi,

Suppose the lock was created using 'USER_1' login. I'm trying to login to the database with the same userid 'USER_1' and issuing the release commands. Doesn't it mean that its the same user who requested the lock is trying to release the lock?
Re: Using DBMS_LOCK.RELEASE to release the lock owned by another process [message #11008 is a reply to message #11001] Mon, 01 March 2004 01:24 Go to previous message
Barbara Boehmer
Messages: 9088
Registered: November 2002
Location: California, USA
Senior Member
According to Tom Kyte, DBMS_LOCK.RELEASE "can only release a user defined lock created by DBMS_LOCK in the same session."
Previous Topic: error on called report
Next Topic: Calculating in SQL based on data
Goto Forum:
  


Current Time: Thu Apr 18 00:42:56 CDT 2024