Skip to main content
Question

Record is locked

  • May 15, 2024
  • 4 replies
  • 489 views

Forum|alt.badge.img+10
  • Hero (Customer)
  • 142 replies

Hello.

I have a record which is locked, how can I unlock it?

 

 

4 replies

Marcel.Ausan
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Ultimate Hero (Partner)
  • 1298 replies
  • May 15, 2024

@romsar this is a generic error message thrown by ERROR_SYS package.

If you have access to the DB, you could use the query from below site to see which are the locked objects and you could kill the session that’s locking the object.

Finding Oracle locked objects (dba-oracle.com)


Forum|alt.badge.img+10
  • Author
  • Hero (Customer)
  • 142 replies
  • May 15, 2024

@Marcel.Ausan I ran the following sql querry, I got no result :

select

   (select username from v$session where sid=a.sid) blocker,

   a.sid,

   ' is blocking ',

   (select username from v$session where sid=b.sid) blockee,

   b.sid

from

   v$lock a,

   v$lock b

where

   a.block = 1

and

   b.request > 0

and

   a.id1 = b.id1

and

   a.id2 = b.id2;


Marcel.Ausan
Ultimate Hero (Partner)
Forum|alt.badge.img+22
  • Ultimate Hero (Partner)
  • 1298 replies
  • May 15, 2024

@romsar ok, then you could check if there’s any session that’s locking the object. Maybe some long-running transaction or maybe even hanging.

select
blocking_session,
sid,
serial#,
wait_class,
seconds_in_wait
from
v$session
where
blocking_session is not NULL
order by
blocking_session

 


Forum|alt.badge.img+10
  • Author
  • Hero (Customer)
  • 142 replies
  • May 15, 2024

These 2 sql querries return no result :

select
blocking_session,
sid,
serial#,
wait_class,
seconds_in_wait
from
v$session
where
blocking_session is not NULL
order by
blocking_session

 

select *
from v$lock
where block = 1

 

I asked Chat GPT who asked me to use this procedure, but I dunno if it’s safe or not to use it, I didn’t even try it yet :

CREATE OR REPLACE PROCEDURE unlock_record (p_rowid IN ROWID)
IS
l_lockhandle VARCHAR2(128);
BEGIN
l_lockhandle := DBMS_LOCK.REQUEST(DBMS_LOCK.X_MODE, p_rowid, release_on_commit => TRUE);
END unlock_record;