Confio oracle enq tm contention wait

10
Solving Oracle enq: TM Contention Wait Events: A Case Study Dean Richards, Sr. DBA Confio Software 08/25/2022 1

description

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.

Transcript of Confio oracle enq tm contention wait

Page 1: Confio oracle enq tm contention wait

04/13/2023 1

Solving Oracle enq: TM Contention Wait Events: A Case Study

Dean Richards, Sr. DBA Confio Software

Page 2: Confio oracle enq tm contention wait

04/13/2023 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);

Page 3: Confio oracle enq tm contention wait

04/13/2023 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

Page 4: Confio oracle enq tm contention wait

04/13/2023 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

Page 5: Confio oracle enq tm contention wait

04/13/2023 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

Page 6: Confio oracle enq tm contention wait

04/13/2023 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

Page 7: Confio oracle enq tm contention wait

04/13/2023 7

What’s really happening under the covers?

• Reviewed V$SESSION:

Page 8: Confio oracle enq tm contention wait

04/13/2023 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!

Page 9: Confio oracle enq tm contention wait

04/13/2023 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 ccWHERE c.constraint_name = cc.constraint_nameAND 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;

Page 10: Confio oracle enq tm contention wait

04/13/2023 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 freewww.confio.com/freetrial