How to deal with Oracle lock table

Source: Internet
Author: User

[Solution]

1) Search for the locked database table and related Sid, serial #, spid;

Select object_name,S. Sid, S. Serial #,P. spidFrom v $ locked_object L, dba_objects o, V $ session S, V $ PROCESS p where L. object_id = O. object_id and L. session_id = S. sid and S. paddr = P. ADDR;

 

2) Killing sessions in the database

Alter system kill session'Sid, serial #'; -- Sid, serial # is the result of the above query;

 

3) Kill the corresponding application

Kill-9Spid

 

Step-by-Step Demonstration:

[1] % sqlplus "/As sysdba"

 

SQL * Plus: Release 11.1.0.6.0-production on Fri Nov 26 09:10:32 2010

 

Copyright (c) 1982,200 7, Oracle. All rights reserved.

 

 

Connected:

Oracle Database 11g Enterprise Edition Release 11.1.0.6.0-64bit Production

With the partitioning and real application testing options

 

SQL>Select object_name, O. owner, S. sid, S. serial #, P. spid from V $ locked_object L, dba_objects o, V $ session S, V $ PROCESS p where L. object_id = O. object_id and L. session_id = S. sid and S. paddr = P. ADDR;

 

Object_name owner Sid serial # spid

----------------------------------------------

Exttest lyj139 22126402

 

SQL>! PS-Ef | grep 26402

Oracle 27588 5389 1 10:29:37 pts/TC/usr/bin/CSH-c ps-Ef | grep 26402

Oracle 26402 26401 0 10:25:25? 0: 00 oracleora11g (description = (local = yes) (address = (Protocol = beq )))

Oracle 27590 27588 0 10:29:37 pts/TC grep 26402

 

Note: Based on the above query resultsSid, serial #To kill the session;

SQL>Alter system kill session '123 ';

 

System altered.

 

Note: The lock object cannot be found after the session is killed;

SQL>Select object_name, O. owner, S. sid, S. serial #, P. spid from V $ locked_object L, dba_objects o, V $ session S, V $ PROCESS p where L. object_id = O. object_id and L. session_id = S. sid and S. paddr = P. ADDR;

 

No rows selected

 

Note: after the session is killed, the process still exists;

SQL>! PS-Ef | grep 26402

Oracle 27951 27949 0 10:30:49 pts/TC grep 26402

Oracle 27949 5389 1 10:30:49 pts/TC/usr/bin/CSH-c ps-Ef | grep 26402

Oracle 26402 26401 0 10:25:25? 0: 00 oracleora11g (description = (local = yes) (address = (Protocol = beq )))

 

Description: processes are killed based on the process PID;

SQL>! Kill-9 26402

 

SQL>! PS-Ef | grep 26402

Oracle 28110 28108 0 10:31:25 pts/TC grep 26402

Oracle 28108 5389 1 10:31:25 pts/TC/usr/bin/CSH-c ps-Ef | grep 26402

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.