Waits on enq: TM - contention in Oracle indicate there are unindexed foreign key constraints. Learn how foreign key constraints can lead to this wait event and how to tune for it.
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Confio oracle enq tm contention wait
1. Solving Oracle enq: TM Contention
Wait Events: A Case Study
Dean Richards, Sr. DBA
Confio Software
11/22/2013
1
2. Case study: Customer
experienceing enq: TM waits
• Sessions blocked on customer’s database
• enq: TM – contention wait events
• Executing simple INSERT statements similar
to:
INSERT INTO supplier VALUES (:1, :2, :3);
11/22/2013
2
3. What’s going on?
• Reviewed the SUPPLIER table
– Found a foreign key constraint referencing the
PRODUCT table that didn’t have an associated
index
• Confirmed by reviewing Top Objects in Ignite
– All the wait time was associated with the
PRODUCT table
11/22/2013
3
4. How did we fix it?
• Added index on the column referencing the
PRODUCT table
• Found the blocking sessions using Ignite—
what was happening?
– Periodically, the company reviewed its vendor list
and "cleaned up” SUPPLIER table
– As a result, rows from SUPPLIER table were
deleted
– Those DELETE statements then cascaded to the
PRODUCT table and took out TM locks on it
11/22/2013
4
5. What’s really happening under
the covers?
• Reproduced customer’s issue to see what happens under the
covers
– Created a subset of the tables from this customer and loaded them
with sample data
11/22/2013
5
6. What’s really happening under
the covers?
• Reproduced statements similar to original situation:
• User 1 and User 2 hung with enq: TM – contention wait
events
11/22/2013
6
8. Reproducing the solution
• Added an index for the foreign key constraint on the
SUPPLIER table back to the PRODUCT table
• Re-ran the test case and everything worked fine
– No exclusive locks acquired, no hanging
– Oracle takes out exclusive locks on the child table (the
PRODUCT table in our example) when a foreign key
constraint is not indexed
• Conclusion: unindexed foreign key constraints can
cause severe problems!
11/22/2013
8
9. Sample query to find unindexed
foreign key constraints
SELECT *
FROM ( SELECT c.table_name, cc.column_name, cc.position
column_position
FROM user_constraints c, user_cons_columns cc
WHERE c.constraint_name = cc.constraint_name
AND c.constraint_type = 'R'
MINUS
SELECT i.table_name, ic.column_name, ic.column_position
FROM user_indexes i, user_ind_columns ic
WHERE i.index_name = ic.index_name )
ORDER BY table_name, column_position;
11/22/2013
9
10. With Confio Ignite, You Find
Blocks Quickly
• Improve database performance by 65% with
Confio Ignite
– Installs in minutes
– Puts no load on monitored servers
– Identify bottlenecks and root causes of blocks like
these in minutes
Download Ignite trial for free
www.confio.com/freetrial
11/22/2013
10