oracle for Update manually locked

       The sea is boundless, the muscles are weak...

      

       Oracle's default "transaction isolation level" is read committed, which is achieved by adding "locks" to data objects through transactions!

             When operating delete, there is no response in the foreground, no error is reported in the background, the breakpoint disappears when it goes to ps.executeUpdate() and does not continue to move down, a simple delete statement, I don't want to put it on pl/sql to check, I have been looking for the code I have repeatedly compiled, replaced the jar package, restarted the process and tried again, but I still can't locate the problem. Then I tried to execute it on pl/sql, no error was reported, but it just displayed "executing...", and then it kept displaying "" Executing...", then came up with "the concept of table being locked", and then found some sql how to kill the session

 

       (1) Pay attention to the reason why the table is locked, because it is a delete operation. In order to facilitate the addition operation, for update is used when selecting a table, but there is no manual commit, then this table is added. lock not released

          (2) Sometimes the transaction in the code does not commit, the current transaction A1 is not completed, and the lock added to table B is not released. If this logic is operated again, transaction A2 cannot operate table B (of course, if the database is disconnected) , automatically closed, will the lock on table B be released, then will the operation performed by transaction A1 be committed)

 

  //查看被锁住的表
SELECT b.owner,b.object_name,a.session_id,a.locked_mode 
    FROM v$locked_object a ,dba_objects b 
    WHERE b.object_id = a.object_id;

 

select /*+ rule */ s.username,
      decode(l.type,'TM','TABLE LOCK','TX','ROW LOCK',null) lock_level,
      o.owner,
      o.object_name,
      o.object_type,
      s.sid,s.serial#,
      s.terminal,
      s.machine,
      s.program,
      s.osuser
from v$session s,v$lock l,dba_objects o
where l.sid = s.sid
and l.id1 = o.object_id(+)
and s.username is not null


   
//查看被锁住的会话
SELECT b.username,b.sid,b.serial#,logon_time 
    FROM v$locked_object a,v$session b 
    WHERE a.session_id = b.sid order by b.logon_time;

 

select /*+ rule */ lpad(' ',decode(l.xidusn ,0,3,0))||l.oracle_username user_name,
       o.owner,
       o.object_name,
       o.object_type,
       s.sid,
       s.serial#
from v$locked_object l,dba_objects o,v$session s
where l.object_id=o.object_id
and l.session_id=s.sid
order by o.object_id,xidusn desc


 
//kill session  
    Alter system kill session 'sid,serial#'

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326604943&siteId=291194637