SlideShare a Scribd company logo
Oracle Diagnostics
Hemant K Chitale
Hemant K Chitale
• whoami ?
• Oracle 5 to Oracle 10gR2 : DOS, Xenix,8
flavours of Unix, Linux, Windows
• Financial Services, Govt/Not-for-Profit, ERP,
Custom
• Production Support, Consulting, Development
• A DBA, not a Developer
• Product Specialist, Standard Chartered Bank
• My Oracle Blog http://hemantoracledba.blogspot.com
Locks and Lock Trees
• Row Locks are Enqueues
• They serialise access to rows
• A transaction may hold Row Locks on multiple
rows – this is represented as a single entry in
V$TRANSACTION but single or multiple entries
in the ITL slots in various table / index blocks
• ITLs allow different transactions to lock different
rows in the same block concurrently.
• Lock Trees are multiple sessions waiting “in
order”, with potentially more than one session
waiting on the same row lock
A Lock Tree :
Script “utllockt.sql” (in $ORACLE_HOME/rdbms/admin) can provide a tree-like
diagram.
* This script prints the sessions in the system that are waiting for
* locks, and the locks that they are waiting for. The printout is tree
* structured. If a sessionid is printed immediately below and to the right
* of another session, then it is waiting for that session. The session ids
* printed at the left hand side of the page are the ones that everyone is
* waiting for.
*
* For example, in the following printout session 9 is waiting for
* session 8, 7 is waiting for 9, and 10 is waiting for 9.
*
* WAITING_SESSION TYPE MODE REQUESTED MODE HELD LOCK ID1 LOCK ID2
* ----------------- ---- ----------------- ----------------- -------- --------
* 8 NONE None None 0 0
* 9 TX Share (S) Exclusive (X) 65547 16
* 7 RW Exclusive (X) S/Row-X (SSX) 33554440 2
* 10 RW Exclusive (X) S/Row-X (SSX) 33554440 2
*
* The lock information to the right of the session id describes the lock
* that the session is waiting for (not the lock it is holding).
The script can be enhanced to provide more session information. The script
uses DDLs to drop and create temp tables – so another enhancement would
be to have those tables created in advance as GTTs and only populated and
queried by the script
Here is a query to list Lock Holders and Waiters:
select s.blocking_session, to_number(s.sid) Waiting_Session, s.event, s.seconds_in_wait,
p.pid,
p.spid "ServerPID", s.process "ClientPID",
s.username, s.program, s.machine, s.osuser, s.sql_id,
substr(sq.sql_text,1,75) SQL
from v$sql sq, v$session s, v$process p
where s.event like 'enq: TX%'
and s.paddr=p.addr
and s.sql_address=sq.address
and s.sql_hash_value=sq.hash_value
and s.sql_id=sq.sql_id
and s.sql_child_number=sq.child_number
union all
select s.blocking_session, to_number(s.sid) Waiting_Session, s.event, s.seconds_in_wait,
p.pid,
p.spid "ServerPID", s.process "ClientPID",
s.username, s.program, s.machine, s.osuser, s.sql_id,
substr(sq.sql_text,1,75) SQL
from v$sql sq, v$session s, v$process p
where s.sid in (select distinct blocking_session from v$session where event like 'enq:
TX%')
and s.paddr=p.addr
and s.sql_address=sq.address(+)
and s.sql_hash_value=sq.hash_value(+)
and s.sql_id=sq.sql_id(+)
and s.sql_child_number=sq.child_number(+)
order by 1 nulls first, 2
/
This method does NOT require any temporary tables !
Example 1 :
Two separate sessions attempting to update the same row :
SQL> connect ABC_DBA/ABC_DBA_123
Connected.
SQL> update hemant.test_row_lock set content = 'Another' where
pk=1;
1 row updated.
SQL>
SQL> connect hemant/hemant
Connected.
SQL> update test_row_lock set content = 'First' where pk=1;
….. now waiting …..
BLOCKING_SESSION WAITING_SESSION EVENT
SECONDS_IN_WAIT PID
---------------- --------------- --------------------------------------------------------
-------- --------------- ----------
ServerPID ClientPID USERNAME PROGRAM
------------------------ ------------------------ ------------------------------ --------
----------------------------------------
MACHINE OSUSER
SQL_ID
---------------------------------------------------------------- ------------------------
------ -------------
SQL
-----------------------------------------------------------------------------------------
-------------------------------------------
17 SQL*Net message from client
82 27
13788 13770 ABC_DBA
sqlplus@localhost.localdomain (TNS V1-V3)
localhost.localdomain oracle
17 26 enq: TX - row lock contention
52 19
13791 3449 HEMANT
sqlplus@localhost.localdomain (TNS V1-V3)
localhost.localdomain oracle
fuwn3bnuh2axg
update test_row_lock set content = 'First' where pk=1
SQL>
Findings for Ex. 1 :
Session 17 (ABC_DBA) has no „BLOCKING_SESSION‟. It isn‟t waiting. It is
the Blocker itself.
Session 26 (HEMANT) as a „WAITING_SESSION‟ presents Session 17 as
being the „BLOCKING_SESSION‟.
Session 26 is waiting on a Row Lock while currently running “update
test_row_lock set content = 'First' where pk=1”
Example 2 :
Table Definition :
SQL> create table test_unique_insert_row_lock
(col_1 number , col_2 varchar2(5));
Table created.
SQL> create unique index t_u_i_r_l_unq_ndx on
test_unique_insert_row_lock (col_1);
Index created.
SQL>
Example 2 (contd):
SQL> connect ABC_DBA/ABC_DBA_123
Connected.
SQL> insert into hemant.test_unique_insert_row_lock values
(1, 'Sn.1');
1 row created.
SQL>
SQL> connect hemant/hemant
Connected.
SQL> insert into hemant.test_unique_insert_row_lock values
(1,'Sn.2');
….. now waiting …..
BLOCKING_SESSION WAITING_SESSION EVENT
SECONDS_IN_WAIT PID
---------------- --------------- --------------------------------------------------
-------------- --------------- ----------
ServerPID ClientPID USERNAME
PROGRAM
------------------------ ------------------------ ------------------------------ --
----------------------------------------------
MACHINE OSUSER
SQL_ID
---------------------------------------------------------------- ------------------
------------ -------------
SQL
---------------------------------------------------------------------------
1 SQL*Net message from client
115 22
13007 12813 ABC_DBA
sqlplus@localhost.localdomain (TNS V1-V3)
localhost.localdomain oracle
1 36 enq: TX - row lock contention
80 25
13009 12971 HEMANT
sqlplus@localhost.localdomain (TNS V1-V3)
localhost.localdomain oracle
166dv336yhxua
insert into hemant.test_unique_insert_row_lock values (1,'Sn.2')
2 rows selected.
SQL>
Findings for Ex 2 :
Session 1 (ABC_DBA) has no blocker
Session 36 (HEMANT) is waiting on Session 1
So, even a Duplicate Value on INSERT actually “waits” on the INSERT that
has not committed. The row inserted by ABC_DBA is not visible to
HEMANT (because ABC_DBA has not yet committed) but HEMANT‟s
INSERT waits on the Row Lock !

More Related Content

What's hot

SQL injection: Not Only AND 1=1 (updated)
SQL injection: Not Only AND 1=1 (updated)SQL injection: Not Only AND 1=1 (updated)
SQL injection: Not Only AND 1=1 (updated)
Bernardo Damele A. G.
 
Oracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesOracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New Features
Alex Zaballa
 
Firebird
FirebirdFirebird
Firebird
Chinsan Huang
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
Alex Zaballa
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
Alex Zaballa
 
Sql Injection 0wning Enterprise
Sql Injection 0wning EnterpriseSql Injection 0wning Enterprise
Sql Injection 0wning Enterprise
n|u - The Open Security Community
 
Usertracing
UsertracingUsertracing
Usertracing
oracle documents
 
How to export import a mysql database via ssh in aws lightsail wordpress rizw...
How to export import a mysql database via ssh in aws lightsail wordpress rizw...How to export import a mysql database via ssh in aws lightsail wordpress rizw...
How to export import a mysql database via ssh in aws lightsail wordpress rizw...
AlexRobert25
 
Developing Information Schema Plugins
Developing Information Schema PluginsDeveloping Information Schema Plugins
Developing Information Schema Plugins
Mark Leith
 
Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)
Bernardo Damele A. G.
 
Barun_Practical_and_Efficient_SQL_Performance_Tuning
Barun_Practical_and_Efficient_SQL_Performance_TuningBarun_Practical_and_Efficient_SQL_Performance_Tuning
Barun_Practical_and_Efficient_SQL_Performance_Tuning
Vlado Barun
 
Pl sql-ch2
Pl sql-ch2Pl sql-ch2
Pl sql-ch2
Mukesh Tekwani
 
Introduction to embedded sql for NonStop SQL
Introduction to embedded sql for NonStop SQLIntroduction to embedded sql for NonStop SQL
Introduction to embedded sql for NonStop SQL
Frans Jongma
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - Thaipt
Framgia Vietnam
 
Database security
Database securityDatabase security
Database security
Javed Khan
 
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Oracle Data redaction - GUOB - OTN TOUR LA - 2015Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Alex Zaballa
 
Sql injection with sqlmap
Sql injection with sqlmapSql injection with sqlmap
Sql injection with sqlmap
Herman Duarte
 
Basic - Oracle Edition Based Redefinition Presentation
Basic - Oracle Edition Based Redefinition PresentationBasic - Oracle Edition Based Redefinition Presentation
Basic - Oracle Edition Based Redefinition Presentation
N/A
 
Advanced SQL injection to operating system full control (whitepaper)
Advanced SQL injection to operating system full control (whitepaper)Advanced SQL injection to operating system full control (whitepaper)
Advanced SQL injection to operating system full control (whitepaper)
Bernardo Damele A. G.
 
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Alex Zaballa
 

What's hot (20)

SQL injection: Not Only AND 1=1 (updated)
SQL injection: Not Only AND 1=1 (updated)SQL injection: Not Only AND 1=1 (updated)
SQL injection: Not Only AND 1=1 (updated)
 
Oracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesOracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New Features
 
Firebird
FirebirdFirebird
Firebird
 
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
OOW16 - Oracle Database 12c - The Best Oracle Database 12c New Features for D...
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
Sql Injection 0wning Enterprise
Sql Injection 0wning EnterpriseSql Injection 0wning Enterprise
Sql Injection 0wning Enterprise
 
Usertracing
UsertracingUsertracing
Usertracing
 
How to export import a mysql database via ssh in aws lightsail wordpress rizw...
How to export import a mysql database via ssh in aws lightsail wordpress rizw...How to export import a mysql database via ssh in aws lightsail wordpress rizw...
How to export import a mysql database via ssh in aws lightsail wordpress rizw...
 
Developing Information Schema Plugins
Developing Information Schema PluginsDeveloping Information Schema Plugins
Developing Information Schema Plugins
 
Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)Advanced SQL injection to operating system full control (slides)
Advanced SQL injection to operating system full control (slides)
 
Barun_Practical_and_Efficient_SQL_Performance_Tuning
Barun_Practical_and_Efficient_SQL_Performance_TuningBarun_Practical_and_Efficient_SQL_Performance_Tuning
Barun_Practical_and_Efficient_SQL_Performance_Tuning
 
Pl sql-ch2
Pl sql-ch2Pl sql-ch2
Pl sql-ch2
 
Introduction to embedded sql for NonStop SQL
Introduction to embedded sql for NonStop SQLIntroduction to embedded sql for NonStop SQL
Introduction to embedded sql for NonStop SQL
 
View, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - ThaiptView, Store Procedure & Function and Trigger in MySQL - Thaipt
View, Store Procedure & Function and Trigger in MySQL - Thaipt
 
Database security
Database securityDatabase security
Database security
 
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Oracle Data redaction - GUOB - OTN TOUR LA - 2015Oracle Data redaction - GUOB - OTN TOUR LA - 2015
Oracle Data redaction - GUOB - OTN TOUR LA - 2015
 
Sql injection with sqlmap
Sql injection with sqlmapSql injection with sqlmap
Sql injection with sqlmap
 
Basic - Oracle Edition Based Redefinition Presentation
Basic - Oracle Edition Based Redefinition PresentationBasic - Oracle Edition Based Redefinition Presentation
Basic - Oracle Edition Based Redefinition Presentation
 
Advanced SQL injection to operating system full control (whitepaper)
Advanced SQL injection to operating system full control (whitepaper)Advanced SQL injection to operating system full control (whitepaper)
Advanced SQL injection to operating system full control (whitepaper)
 
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
Oracle Database 12c Release 2 - New Features On Oracle Database Exadata Expre...
 

Similar to Oracle Diagnostics : Locks and Lock Trees

11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01
Karam Abuataya
 
11 Things About11g
11 Things About11g11 Things About11g
11 Things About11g
fcamachob
 
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contentionTroubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Tanel Poder
 
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and AdvisorsYour tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
John Kanagaraj
 
MySQL 5.5 Guide to InnoDB Status
MySQL 5.5 Guide to InnoDB StatusMySQL 5.5 Guide to InnoDB Status
MySQL 5.5 Guide to InnoDB Status
Karwin Software Solutions LLC
 
Rmoug ashmaster
Rmoug ashmasterRmoug ashmaster
Rmoug ashmaster
Kyle Hailey
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Guatemala User Group
 
Odv oracle customer_demo
Odv oracle customer_demoOdv oracle customer_demo
Odv oracle customer_demo
Viaggio Italia
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)
Hemant K Chitale
 
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
MySQL Without the SQL -- Oh My!  Longhorn PHP ConferenceMySQL Without the SQL -- Oh My!  Longhorn PHP Conference
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
Dave Stokes
 
Security Best Practice: Oracle passwords, but secure!
Security Best Practice: Oracle passwords, but secure!Security Best Practice: Oracle passwords, but secure!
Security Best Practice: Oracle passwords, but secure!
Stefan Oehrli
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developers
Connor McDonald
 
My sql 5.6&MySQL Cluster 7.3
My sql 5.6&MySQL Cluster 7.3My sql 5.6&MySQL Cluster 7.3
My sql 5.6&MySQL Cluster 7.3
Oleksii(Alexey) Porytskyi
 
Percona Live UK 2014 Part III
Percona Live UK 2014  Part IIIPercona Live UK 2014  Part III
Percona Live UK 2014 Part III
Alkin Tezuysal
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
Sveta Smirnova
 
My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)
Gustavo Rene Antunez
 
UKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction LocksUKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction Locks
Kyle Hailey
 
HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)
akirahiguchi
 
Being HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeBeing HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on Purpose
Aman Kohli
 
Curso de MySQL 5.7
Curso de MySQL 5.7Curso de MySQL 5.7
Curso de MySQL 5.7
Eduardo Legatti
 

Similar to Oracle Diagnostics : Locks and Lock Trees (20)

11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01
 
11 Things About11g
11 Things About11g11 Things About11g
11 Things About11g
 
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contentionTroubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contention
 
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and AdvisorsYour tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
Your tuning arsenal: AWR, ADDM, ASH, Metrics and Advisors
 
MySQL 5.5 Guide to InnoDB Status
MySQL 5.5 Guide to InnoDB StatusMySQL 5.5 Guide to InnoDB Status
MySQL 5.5 Guide to InnoDB Status
 
Rmoug ashmaster
Rmoug ashmasterRmoug ashmaster
Rmoug ashmaster
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
 
Odv oracle customer_demo
Odv oracle customer_demoOdv oracle customer_demo
Odv oracle customer_demo
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)
 
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
MySQL Without the SQL -- Oh My!  Longhorn PHP ConferenceMySQL Without the SQL -- Oh My!  Longhorn PHP Conference
MySQL Without the SQL -- Oh My! Longhorn PHP Conference
 
Security Best Practice: Oracle passwords, but secure!
Security Best Practice: Oracle passwords, but secure!Security Best Practice: Oracle passwords, but secure!
Security Best Practice: Oracle passwords, but secure!
 
OpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developersOpenWorld Sep14 12c for_developers
OpenWorld Sep14 12c for_developers
 
My sql 5.6&MySQL Cluster 7.3
My sql 5.6&MySQL Cluster 7.3My sql 5.6&MySQL Cluster 7.3
My sql 5.6&MySQL Cluster 7.3
 
Percona Live UK 2014 Part III
Percona Live UK 2014  Part IIIPercona Live UK 2014  Part III
Percona Live UK 2014 Part III
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
 
My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)My First 100 days with an Exadata (PPT)
My First 100 days with an Exadata (PPT)
 
UKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction LocksUKOUG, Oracle Transaction Locks
UKOUG, Oracle Transaction Locks
 
HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)
 
Being HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeBeing HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on Purpose
 
Curso de MySQL 5.7
Curso de MySQL 5.7Curso de MySQL 5.7
Curso de MySQL 5.7
 

More from Hemant K Chitale

SQL Tracing
SQL TracingSQL Tracing
SQL Tracing
Hemant K Chitale
 
Oracle Diagnostics : Latches and Enqueues
Oracle Diagnostics : Latches and EnqueuesOracle Diagnostics : Latches and Enqueues
Oracle Diagnostics : Latches and Enqueues
Hemant K Chitale
 
Oracle Diagnostics : Joins - 1
Oracle Diagnostics : Joins - 1Oracle Diagnostics : Joins - 1
Oracle Diagnostics : Joins - 1
Hemant K Chitale
 
Partitioning Tables and Indexing Them --- Article
Partitioning Tables and Indexing Them --- ArticlePartitioning Tables and Indexing Them --- Article
Partitioning Tables and Indexing Them --- Article
Hemant K Chitale
 
Oracle database performance diagnostics - before your begin
Oracle database performance diagnostics  - before your beginOracle database performance diagnostics  - before your begin
Oracle database performance diagnostics - before your begin
Hemant K Chitale
 
The role of the dba
The role of the dba The role of the dba
The role of the dba
Hemant K Chitale
 
Partitioning tables and indexing them
Partitioning tables and indexing them Partitioning tables and indexing them
Partitioning tables and indexing them
Hemant K Chitale
 

More from Hemant K Chitale (7)

SQL Tracing
SQL TracingSQL Tracing
SQL Tracing
 
Oracle Diagnostics : Latches and Enqueues
Oracle Diagnostics : Latches and EnqueuesOracle Diagnostics : Latches and Enqueues
Oracle Diagnostics : Latches and Enqueues
 
Oracle Diagnostics : Joins - 1
Oracle Diagnostics : Joins - 1Oracle Diagnostics : Joins - 1
Oracle Diagnostics : Joins - 1
 
Partitioning Tables and Indexing Them --- Article
Partitioning Tables and Indexing Them --- ArticlePartitioning Tables and Indexing Them --- Article
Partitioning Tables and Indexing Them --- Article
 
Oracle database performance diagnostics - before your begin
Oracle database performance diagnostics  - before your beginOracle database performance diagnostics  - before your begin
Oracle database performance diagnostics - before your begin
 
The role of the dba
The role of the dba The role of the dba
The role of the dba
 
Partitioning tables and indexing them
Partitioning tables and indexing them Partitioning tables and indexing them
Partitioning tables and indexing them
 

Recently uploaded

Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
Yara Milbes
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
Grant Fritchey
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
devvsandy
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
Patrick Weigel
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
mz5nrf0n
 

Recently uploaded (20)

Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
SMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API ServiceSMS API Integration in Saudi Arabia| Best SMS API Service
SMS API Integration in Saudi Arabia| Best SMS API Service
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Using Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query PerformanceUsing Query Store in Azure PostgreSQL to Understand Query Performance
Using Query Store in Azure PostgreSQL to Understand Query Performance
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
WWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders AustinWWDC 2024 Keynote Review: For CocoaCoders Austin
WWDC 2024 Keynote Review: For CocoaCoders Austin
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
原版定制美国纽约州立大学奥尔巴尼分校毕业证学位证书原版一模一样
 

Oracle Diagnostics : Locks and Lock Trees

  • 2. Hemant K Chitale • whoami ? • Oracle 5 to Oracle 10gR2 : DOS, Xenix,8 flavours of Unix, Linux, Windows • Financial Services, Govt/Not-for-Profit, ERP, Custom • Production Support, Consulting, Development • A DBA, not a Developer • Product Specialist, Standard Chartered Bank • My Oracle Blog http://hemantoracledba.blogspot.com
  • 3. Locks and Lock Trees • Row Locks are Enqueues • They serialise access to rows • A transaction may hold Row Locks on multiple rows – this is represented as a single entry in V$TRANSACTION but single or multiple entries in the ITL slots in various table / index blocks • ITLs allow different transactions to lock different rows in the same block concurrently. • Lock Trees are multiple sessions waiting “in order”, with potentially more than one session waiting on the same row lock
  • 4. A Lock Tree : Script “utllockt.sql” (in $ORACLE_HOME/rdbms/admin) can provide a tree-like diagram. * This script prints the sessions in the system that are waiting for * locks, and the locks that they are waiting for. The printout is tree * structured. If a sessionid is printed immediately below and to the right * of another session, then it is waiting for that session. The session ids * printed at the left hand side of the page are the ones that everyone is * waiting for. * * For example, in the following printout session 9 is waiting for * session 8, 7 is waiting for 9, and 10 is waiting for 9. * * WAITING_SESSION TYPE MODE REQUESTED MODE HELD LOCK ID1 LOCK ID2 * ----------------- ---- ----------------- ----------------- -------- -------- * 8 NONE None None 0 0 * 9 TX Share (S) Exclusive (X) 65547 16 * 7 RW Exclusive (X) S/Row-X (SSX) 33554440 2 * 10 RW Exclusive (X) S/Row-X (SSX) 33554440 2 * * The lock information to the right of the session id describes the lock * that the session is waiting for (not the lock it is holding). The script can be enhanced to provide more session information. The script uses DDLs to drop and create temp tables – so another enhancement would be to have those tables created in advance as GTTs and only populated and queried by the script
  • 5. Here is a query to list Lock Holders and Waiters: select s.blocking_session, to_number(s.sid) Waiting_Session, s.event, s.seconds_in_wait, p.pid, p.spid "ServerPID", s.process "ClientPID", s.username, s.program, s.machine, s.osuser, s.sql_id, substr(sq.sql_text,1,75) SQL from v$sql sq, v$session s, v$process p where s.event like 'enq: TX%' and s.paddr=p.addr and s.sql_address=sq.address and s.sql_hash_value=sq.hash_value and s.sql_id=sq.sql_id and s.sql_child_number=sq.child_number union all select s.blocking_session, to_number(s.sid) Waiting_Session, s.event, s.seconds_in_wait, p.pid, p.spid "ServerPID", s.process "ClientPID", s.username, s.program, s.machine, s.osuser, s.sql_id, substr(sq.sql_text,1,75) SQL from v$sql sq, v$session s, v$process p where s.sid in (select distinct blocking_session from v$session where event like 'enq: TX%') and s.paddr=p.addr and s.sql_address=sq.address(+) and s.sql_hash_value=sq.hash_value(+) and s.sql_id=sq.sql_id(+) and s.sql_child_number=sq.child_number(+) order by 1 nulls first, 2 / This method does NOT require any temporary tables !
  • 6. Example 1 : Two separate sessions attempting to update the same row : SQL> connect ABC_DBA/ABC_DBA_123 Connected. SQL> update hemant.test_row_lock set content = 'Another' where pk=1; 1 row updated. SQL> SQL> connect hemant/hemant Connected. SQL> update test_row_lock set content = 'First' where pk=1; ….. now waiting …..
  • 7. BLOCKING_SESSION WAITING_SESSION EVENT SECONDS_IN_WAIT PID ---------------- --------------- -------------------------------------------------------- -------- --------------- ---------- ServerPID ClientPID USERNAME PROGRAM ------------------------ ------------------------ ------------------------------ -------- ---------------------------------------- MACHINE OSUSER SQL_ID ---------------------------------------------------------------- ------------------------ ------ ------------- SQL ----------------------------------------------------------------------------------------- ------------------------------------------- 17 SQL*Net message from client 82 27 13788 13770 ABC_DBA sqlplus@localhost.localdomain (TNS V1-V3) localhost.localdomain oracle 17 26 enq: TX - row lock contention 52 19 13791 3449 HEMANT sqlplus@localhost.localdomain (TNS V1-V3) localhost.localdomain oracle fuwn3bnuh2axg update test_row_lock set content = 'First' where pk=1 SQL>
  • 8. Findings for Ex. 1 : Session 17 (ABC_DBA) has no „BLOCKING_SESSION‟. It isn‟t waiting. It is the Blocker itself. Session 26 (HEMANT) as a „WAITING_SESSION‟ presents Session 17 as being the „BLOCKING_SESSION‟. Session 26 is waiting on a Row Lock while currently running “update test_row_lock set content = 'First' where pk=1”
  • 9. Example 2 : Table Definition : SQL> create table test_unique_insert_row_lock (col_1 number , col_2 varchar2(5)); Table created. SQL> create unique index t_u_i_r_l_unq_ndx on test_unique_insert_row_lock (col_1); Index created. SQL>
  • 10. Example 2 (contd): SQL> connect ABC_DBA/ABC_DBA_123 Connected. SQL> insert into hemant.test_unique_insert_row_lock values (1, 'Sn.1'); 1 row created. SQL> SQL> connect hemant/hemant Connected. SQL> insert into hemant.test_unique_insert_row_lock values (1,'Sn.2'); ….. now waiting …..
  • 11. BLOCKING_SESSION WAITING_SESSION EVENT SECONDS_IN_WAIT PID ---------------- --------------- -------------------------------------------------- -------------- --------------- ---------- ServerPID ClientPID USERNAME PROGRAM ------------------------ ------------------------ ------------------------------ -- ---------------------------------------------- MACHINE OSUSER SQL_ID ---------------------------------------------------------------- ------------------ ------------ ------------- SQL --------------------------------------------------------------------------- 1 SQL*Net message from client 115 22 13007 12813 ABC_DBA sqlplus@localhost.localdomain (TNS V1-V3) localhost.localdomain oracle 1 36 enq: TX - row lock contention 80 25 13009 12971 HEMANT sqlplus@localhost.localdomain (TNS V1-V3) localhost.localdomain oracle 166dv336yhxua insert into hemant.test_unique_insert_row_lock values (1,'Sn.2') 2 rows selected. SQL>
  • 12. Findings for Ex 2 : Session 1 (ABC_DBA) has no blocker Session 36 (HEMANT) is waiting on Session 1 So, even a Duplicate Value on INSERT actually “waits” on the INSERT that has not committed. The row inserted by ABC_DBA is not visible to HEMANT (because ABC_DBA has not yet committed) but HEMANT‟s INSERT waits on the Row Lock !