How to use a built-in script to query congestion in Oracle

Source: Internet
Author: User

When diagnosing the lock issue, you need to find the owner and the blocked person. It is often very troublesome. If you have no accumulated scripts, You need to manually query many tables, such as v $ lock, v $ process p, v $ session s, and v $ latchholder. Now there is a simple way to use Oracle's built-in scripts to generate two views dba_waiters and dba_blockers to check for blocking. Execute the built-in script in SYS as follows:

C: \ Documents ents and Settings \ guogang> sqlplus/as sysdba;

SQL * Plus: Release 10.2.0.1.0-Production on Friday January 24 08:26:42 2014
Copyright (c) 1982,200 5, Oracle. All rights reserved.
Connect:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-Production
With the Partitioning, OLAP and Data Mining options
SQL> @? /Rdbms/admin/catblock. SQL
The view has been created.

You have created a synonym.

.........................

Lab:

Simulate DML locks

Session1:

Select * from test for update;

Session2:

Select * from test for update;

Session3:

SQL> select * from dba_waiters;

WAITING_SESSION HOLDING_SESSION LOCK_TYPE MODE_HELD MODE_REQUESTED LOCK_ID1 LOCK_ID2
------------------------------------------------------------------------------------------------------------------------------------------------
142 150 Transaction Exclusive 131099 2550

SQL> select * from dba_blockers;

HOLDING_SESSION
---------------
150

We can clearly see that the lock holder is session 150, and the waiting person is 142.

Simulate DDL lock

Session1:

Select * from obj $ for update

Session2:

Create index ind_t_id on test (object_id );

Session3:

SQL> select * from dba_waiters;

WAITING_SESSION HOLDING_SESSION LOCK_TYPE MODE_HELD MODE_REQUESTED LOCK_ID1 LOCK_ID2
------------------------------------------------------------------------------------------------------------------------------------------------------------
150 145 Transaction Exclusive 1310729 1391

SQL> select * from dba_blockers;

HOLDING_SESSION
---------------
145

We can clearly see that the lock holder is session 145, and the waiting person is 150.

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.