{"id":3958,"date":"2014-10-26T19:20:45","date_gmt":"2014-10-26T18:20:45","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/"},"modified":"2024-03-13T09:59:28","modified_gmt":"2024-03-13T08:59:28","slug":"oracle-an-unexpected-lock-behaviour-with-rollback","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/","title":{"rendered":"Oracle: an unexpected lock behavior with rollback"},"content":{"rendered":"<h2>By Franck Pachot<\/h2>\n<p>.<br \/>\nHere is an odd Oracle behavior I observed when a transaction that acquired a lock is rolled back. Note that this is related to a specific combination of locks that should not be encountered in production. So it&#8217;s not a bug. Just something unexpected.<\/p>\n<p>&nbsp;<\/p>\n<h3>First session<\/h3>\n<p>In my first session I lock the DEPT table in share mode (RS)<br \/>\n<code>20:56:56 SQL1&gt; lock table dept in row share mode;<br \/>\nTable(s) Locked.<br \/>\n<\/code><br \/>\nMy first session (SID=53) has acquired a TM lock in mode 2 (row share):<br \/>\n<code>20:56:56 SQL1&gt; select object_name,session_id,LOCKED_MODE from v$locked_object join dba_objects using(object_id);<br \/>\n&nbsp;<br \/>\nOBJECT_NAME SESSION_ID LOCKED_MODE<br \/>\n----------- ---------- -----------<br \/>\nDEPT                53           2<br \/>\n<\/code><br \/>\n&nbsp;<\/p>\n<h3>Second session<\/h3>\n<p>In my second session I lock the DEPT table in share + row exclusive mode (SRX). This is compatible with the RS.<br \/>\n<code>20:56:59 SQL2&gt; lock table dept in share row exclusive mode;<br \/>\nTable(s) Locked.<br \/>\n<\/code><br \/>\nMy second session (SID=59) has acquired a TM lock in mode 5 (share + row exclusive):<br \/>\n<code>20:56:59 SQL2&gt; select object_name,session_id,LOCKED_MODE from v$locked_object join dba_objects using(object_id);<br \/>\n&nbsp;<br \/>\nOBJECT_NAME SESSION_ID LOCKED_MODE<br \/>\n----------- ---------- -----------<br \/>\nDEPT                59           5<br \/>\nDEPT                53           2<br \/>\n<\/code><br \/>\nThen I rollback my transaction<br \/>\n<code>20:56:59 SQL2&gt; rollback;<br \/>\n<\/code><br \/>\nMy lock was released and I&#8217;ve only the one from Session 1 (SID=53):<br \/>\n<code>OBJECT_NAME SESSION_ID LOCKED_MODE<br \/>\n----------- ---------- -----------<br \/>\nDEPT                53           2<br \/>\n<\/code><br \/>\nNow comes the funny part. I run exactly the same SSX lock, which was immediately acquired before:<br \/>\n<code>21:14:30 SQL2&gt; lock table dept in share row exclusive mode wait 5 ;<br \/>\n<\/code><br \/>\nBut now it hangs. Let&#8217;s see the blocking tree with utllockt.sql:<br \/>\n<code>WAITING_SESSION   LOCK_TYPE         MODE_REQUESTED MODE_HELD      LOCK_ID1          LOCK_ID2<br \/>\n----------------- ----------------- -------------- -------------- ----------------- -----------------<br \/>\n53                None<br \/>\n   59             DML               Exclusive      Row-S (SS)     94228             0<br \/>\n<\/code><br \/>\nWhat? My session wants to acquire an Exclusive lock? I&#8217;ve never requested that.<br \/>\nAnd finally it fails because my Session 1 has a RS lock which prevents exclusive locks.<br \/>\n<code>lock table dept in share row exclusive mode wait 5<br \/>\n*<br \/>\nERROR at line 1:<br \/>\nORA-00054: resource busy and acquire with NOWAIT specified or timeout expired<br \/>\n<\/code><br \/>\n&nbsp;<\/p>\n<h3>Third session<\/h3>\n<p>But there is worse. I disconnect my second session and try to do the same from a third one. And I even try only a RS lock:<br \/>\n<code>21:15:20 SQL3&gt; lock table dept in row share mode wait 5 ;<br \/>\n<\/code><br \/>\nAnd I&#8217;m blocked again. It seems that because a session had acquired a SRX lock and has rolled back, while another session held a RS one, then any new transaction that wants to acquire any lock must acquire temporarily an exclusive one before.<\/p>\n<p>&nbsp;<\/p>\n<h3>Event 10704 &#8220;Print out information about what enqueues are being obtained&#8221;<\/h3>\n<p>In order to get further I traced the locks with event 10704 (see how in a previous <a href=\"\/blog\/investigating-oracle-lock-issues-with-event-10704\/\">post<\/a>).<\/p>\n<p>Here is the trace when it failed, filtering on &#8216;00017014&#8217; which is the object_id of DEPT in hexadecimal:<br \/>\n<code>ksqgtl *** TM-00017014-00000000-00000000-00000000 mode=2 flags=0x400 timeout=5 ***<br \/>\nksqrcl: TM-00017014-00000000-00000000-00000000<br \/>\nksqgtl *** TM-00017014-00000000-00000000-00000000 <strong>mode=6<\/strong> flags=0x400 timeout=5 ***<br \/>\nksqcmi: TM-00017014-00000000-00000000-00000000 mode=6 timeout=5<br \/>\nksqcmi: returns 51<br \/>\nksqgtl: <strong>RETURNS 51<\/strong><br \/>\nksqrcl: returns 0<br \/>\n<\/code><br \/>\nMy &#8216;lock table dept in row share mode&#8217; acquires a mode 2 (which is the &#8216;row share&#8217; mode) but then released it and tried to acquire a mode 6 (which is exclusive)<\/p>\n<p>And then here is a trace when it was successful, after the transaction in Session 1 has been committed:<br \/>\n<code>ksqgtl *** TM-00017014-00000000-00000000-00000000 mode=2 flags=0x400 timeout=5 ***<br \/>\nksqrcl: TM-00017014-00000000-00000000-00000000<br \/>\nksqgtl *** TM-00017014-00000000-00000000-00000000 <strong>mode=6<\/strong> flags=0x400 timeout=5 ***<br \/>\nksqcmi: TM-00017014-00000000-00000000-00000000 mode=6 timeout=5<br \/>\nksqcmi: returns 0<br \/>\nksqgtl: <strong>RETURNS 0<\/strong><br \/>\nksqgtl *** TM-00017014-00000001-00000000-00000000 mode=3 flags=0x400 timeout=5 ***<br \/>\nksqgtl: RETURNS 0<br \/>\nksqcnv: TM-00017014-00000000-00000000-00000000 <strong>mode=2<\/strong> timeout=5<br \/>\nksqcmi: TM-00017014-00000000-00000000-00000000 mode=2 timeout=5<br \/>\nksqcmi: returns 0<br \/>\nksqrcl: TM-00017014-00000001-00000000-00000000<br \/>\nksqrcl: returns 0<br \/>\n<\/code><br \/>\nSo it it did the same, but that time the mode 6 can be acquired. Then we see a conversion to mode 2 which is the RS we wanted.<\/p>\n<p>Finally I tried with all other combinations of locks, but it seems that only that one (RS then rolled back SRX) show that behavior. I tried also with DML instead of &#8216;lock table&#8217; statement but the Share lock acquired by DML (the non-indexed foreign key case) is released immediately so I cannot rollback it. And a failure in the statement do not trigger the same behaviour.<\/p>\n<p>Final note: the only reference I&#8217;ve find for that behavior is <a href=\"http:\/\/www.freelists.org\/post\/oracle-l\/Lock-Table-Oddity\">this<\/a> post on oracle-l<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Franck Pachot . Here is an odd Oracle behavior I observed when a transaction that acquired a lock is rolled back. Note that this is related to a specific combination of locks that should not be encountered in production. So it&#8217;s not a bug. Just something unexpected. &nbsp; First session In my first session [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229,59],"tags":[481,96],"type_dbi":[],"class_list":["post-3958","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","category-oracle","tag-lock","tag-oracle"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Oracle: an unexpected lock behavior with rollback - dbi Blog<\/title>\n<meta name=\"description\" content=\"A weird Oracle behavior when acquired lock is rolled back.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oracle: an unexpected lock behavior with rollback\" \/>\n<meta property=\"og:description\" content=\"A weird Oracle behavior when acquired lock is rolled back.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-10-26T18:20:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-13T08:59:28+00:00\" \/>\n<meta name=\"author\" content=\"Oracle Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Oracle Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/\"},\"author\":{\"name\":\"Oracle Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"headline\":\"Oracle: an unexpected lock behavior with rollback\",\"datePublished\":\"2014-10-26T18:20:45+00:00\",\"dateModified\":\"2024-03-13T08:59:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/\"},\"wordCount\":476,\"commentCount\":2,\"keywords\":[\"lock\",\"Oracle\"],\"articleSection\":[\"Database Administration &amp; Monitoring\",\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/\",\"name\":\"Oracle: an unexpected lock behavior with rollback - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2014-10-26T18:20:45+00:00\",\"dateModified\":\"2024-03-13T08:59:28+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\"},\"description\":\"A weird Oracle behavior when acquired lock is rolled back.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Oracle: an unexpected lock behavior with rollback\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee\",\"name\":\"Oracle Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g\",\"caption\":\"Oracle Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Oracle: an unexpected lock behavior with rollback - dbi Blog","description":"A weird Oracle behavior when acquired lock is rolled back.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/","og_locale":"en_US","og_type":"article","og_title":"Oracle: an unexpected lock behavior with rollback","og_description":"A weird Oracle behavior when acquired lock is rolled back.","og_url":"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/","og_site_name":"dbi Blog","article_published_time":"2014-10-26T18:20:45+00:00","article_modified_time":"2024-03-13T08:59:28+00:00","author":"Oracle Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Oracle Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/"},"author":{"name":"Oracle Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"headline":"Oracle: an unexpected lock behavior with rollback","datePublished":"2014-10-26T18:20:45+00:00","dateModified":"2024-03-13T08:59:28+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/"},"wordCount":476,"commentCount":2,"keywords":["lock","Oracle"],"articleSection":["Database Administration &amp; Monitoring","Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/","url":"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/","name":"Oracle: an unexpected lock behavior with rollback - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2014-10-26T18:20:45+00:00","dateModified":"2024-03-13T08:59:28+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee"},"description":"A weird Oracle behavior when acquired lock is rolled back.","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/oracle-an-unexpected-lock-behaviour-with-rollback\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Oracle: an unexpected lock behavior with rollback"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/66ab87129f2d357f09971bc7936a77ee","name":"Oracle Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f711f7cd2c9b09bf2627133755b569fb5be0694810cfd33033bdd095fedba86d?s=96&d=mm&r=g","caption":"Oracle Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/oracle-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/3958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=3958"}],"version-history":[{"count":1,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/3958\/revisions"}],"predecessor-version":[{"id":31749,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/3958\/revisions\/31749"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=3958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=3958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=3958"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=3958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}