Oracle Lock Table Solution

Source: Internet
Author: User

--View the Locked object

Select A.session_id,a.object_id,a.oracle_username,b.object_type,b.object_name from V$locked_object a,all_objects b

where a.object_id = b.object_id;

--Unlocking method

1 Find SID, serial#

Select c.sid,c.serial# from v$session C where c.sid into (select a.session_id from V$locked_object a,all_objects b where a. object_id = b.object_id);

2) Unlock

Alter system kill session ' sid,serial# ';

For the above method kill session is invalid, when the report ora error, use the following method to resolve:

1) 、--Find the SPID

Select spid, Osuser, S.program

From V$session s,v$process p

where s.paddr=p.addr and s.sid = ' xxx '-can be obtained by the above lock SQL

2, with the root user login to the Oracle database server, kill the process immediately unlock

kill-9 spid;

Attach 2 section automatic unlock sql:

--Only a single SID is available

Declare

V_SID number;

V_serial number;

Vv_sql varchar2 (4000);

Begin

Select c.sid,c.serial# into v_sid,v_serial from v$session C

where C.sid in

(select a.session_id from V$locked_object a,all _objects b where a.object_id = b.object_id);

Dbms_output.put_line (v_sid| | ', ' | | V_serial);

Vv_sql: = ' alter system kill session ' | | v_sid| | ', ' | | v_serial| | ';

Execute immediate vv_sql;

End

--cursor traversal applies to multiple SIDs

Declare

Begin

For cur in

(select c.sid,c.serial# from v$session C

where C.sid in

(select a.session_id from V$locked_object a,all_objects b where a.object_id = b.object_id)) Loop

Execute immediate ' alter system kill session ' | | cur.sid| | ', ' | | cur.serial#| | ';

End Loop;

End

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/database/Oracle/

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.