Quick lock search and lock wait in Oracle

Source: Internet
Author: User

Database locks are resource-consuming. In particular, when a lock wait occurs, we must find the lock waiting to kill the process if possible.

You can useAlter system kill session 'sid, serial #'OrAlter system disconnect session 'sid, serial # 'immediate; To kill a session

The following statement finds the locks generated by all the DML statements in the database. It can also be found that any DML statement actually produces two locks: one is the table lock and the other is the row lock.

select/* + rule */s. username,
decode (L. type, 'Tm ', 'tablelock', '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 $ lockl, dba_objects o
where L. SID = S. sid
and L. id1 = O. object_id (+)
and S. username is not null

If a lock wait occurs, we may want to know who is waiting because the table is locked. The following statement can query who has locked the table and who is waiting.
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_objectl, dba_objects o, V $ session s
Where l. object_id = O. object_id
And l. session_id = S. Sid
Order by O. object_id, xidusndesc

The preceding query result is a tree structure. If a subnode exists, it indicates that a wait occurs. If you want to know which rollback segment the lock uses, you can also associate it with V $ rollname. xidusn is the USN of the rollback segment.

[Q] how to effectively delete a large table (with many extent tables)
[a] A table with many (100 k) extent tables, if you simply use drop table, it will consume a lot of CPU (Oracle needs to operate on the FET $ and uet $ data dictionary), and it may take several days, A better way is to delete extent multiple times to reduce this consumption:
1. truncate table big-Table reuse storage;
2. alter table big-tabledeallocate unused keep 2000 m (n-1/N of the original size);
3. alter table big-tabledeallocate unused keep 1500 m;
....
4. drop table big-table;

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.