{"id":195927,"date":"2024-11-13T19:04:28","date_gmt":"2024-11-13T11:04:28","guid":{"rendered":"https:\/\/server.hk\/cnblog\/195927\/"},"modified":"2024-11-13T19:04:29","modified_gmt":"2024-11-13T11:04:29","slug":"%e6%80%8e%e6%a8%a3%e8%a7%a3%e9%99%a4-oracle-%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e7%9a%84%e9%8e%96%e5%ae%9a-oracle-%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e8%a2%ab%e9%8e%96","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/195927\/","title":{"rendered":"\u600e\u6a23\u89e3\u9664 Oracle \u6578\u64da\u5eab\u8868\u7684\u9396\u5b9a (oracle \u6578\u64da\u5eab\u8868\u88ab\u9396)"},"content":{"rendered":"<h1 id=\"%e6%80%8e%e6%a8%a3%e8%a7%a3%e9%99%a4-oracle-%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e7%9a%84%e9%8e%96%e5%ae%9a-oracle-%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a1%a8%e8%a2%ab%e9%8e%96-oPOuncAGyV\">\u600e\u6a23\u89e3\u9664 Oracle \u6578\u64da\u5eab\u8868\u7684\u9396\u5b9a (oracle \u6578\u64da\u5eab\u8868\u88ab\u9396)<\/h1>\n<p>\u5728\u4f7f\u7528 Oracle \u6578\u64da\u5eab\u7684\u904e\u7a0b\u4e2d\uff0c\u8868\u7684\u9396\u5b9a\u662f\u4e00\u500b\u5e38\u898b\u7684\u554f\u984c\u3002\u7576\u591a\u500b\u7528\u6236\u6216\u61c9\u7528\u7a0b\u5e8f\u540c\u6642\u8a2a\u554f\u540c\u4e00\u6578\u64da\u8868\u6642\uff0c\u53ef\u80fd\u6703\u51fa\u73fe\u9396\u5b9a\u60c5\u6cc1\uff0c\u9019\u6703\u5c0e\u81f4\u6578\u64da\u5eab\u64cd\u4f5c\u7684\u5ef6\u9072\u6216\u5931\u6557\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u8b58\u5225\u548c\u89e3\u9664 Oracle \u6578\u64da\u5eab\u8868\u7684\u9396\u5b9a\uff0c\u5e6b\u52a9\u7528\u6236\u66f4\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af%e6%95%b8%e6%93%9a%e5%ba%ab%e9%8e%96%e5%ae%9a%ef%bc%9f-oPOuncAGyV\">\u4ec0\u9ebc\u662f\u6578\u64da\u5eab\u9396\u5b9a\uff1f<\/h2>\n<p>\u6578\u64da\u5eab\u9396\u5b9a\u662f\u6307\u5728\u6578\u64da\u5eab\u64cd\u4f5c\u904e\u7a0b\u4e2d\uff0c\u70ba\u4e86\u4fdd\u8b77\u6578\u64da\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\uff0c\u7cfb\u7d71\u5c0d\u67d0\u4e9b\u8cc7\u6e90\uff08\u5982\u8868\u3001\u884c\u6216\u9801\u9762\uff09\u65bd\u52a0\u7684\u9650\u5236\u3002\u7576\u4e00\u500b\u7528\u6236\u6b63\u5728\u5c0d\u67d0\u500b\u8868\u9032\u884c\u64cd\u4f5c\u6642\uff0c\u5176\u4ed6\u7528\u6236\u53ef\u80fd\u7121\u6cd5\u5c0d\u8a72\u8868\u9032\u884c\u4fee\u6539\uff0c\u9019\u5c31\u662f\u9396\u5b9a\u7684\u8868\u73fe\u3002<\/p>\n<h2 id=\"%e9%8e%96%e5%ae%9a%e7%9a%84%e9%a1%9e%e5%9e%8b-oPOuncAGyV\">\u9396\u5b9a\u7684\u985e\u578b<\/h2>\n<ul>\n<li><strong>\u884c\u9396\uff08Row Lock\uff09<\/strong>: \u53ea\u9396\u5b9a\u7279\u5b9a\u7684\u884c\uff0c\u5141\u8a31\u5176\u4ed6\u884c\u7684\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u8868\u9396\uff08Table Lock\uff09<\/strong>: \u9396\u5b9a\u6574\u500b\u8868\uff0c\u963b\u6b62\u5176\u4ed6\u7528\u6236\u5c0d\u8a72\u8868\u7684\u4efb\u4f55\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u610f\u5411\u9396\uff08Intent Lock\uff09<\/strong>: \u7528\u65bc\u6307\u793a\u4e00\u500b\u4e8b\u52d9\u6253\u7b97\u5728\u67d0\u500b\u5c64\u7d1a\u4e0a\u7372\u53d6\u9396\u5b9a\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e8%ad%98%e5%88%a5%e9%8e%96%e5%ae%9a-oPOuncAGyV\">\u5982\u4f55\u8b58\u5225\u9396\u5b9a<\/h2>\n<p>\u5728 Oracle \u6578\u64da\u5eab\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u67e5\u8a62\u4f86\u8b58\u5225\u7576\u524d\u7684\u9396\u5b9a\u60c5\u6cc1\uff1a<\/p>\n<pre><code>SELECT \n    object_name, \n    session_id, \n    type, \n    lmode, \n    request \nFROM \n    v$locked_object \nJOIN \n    dba_objects \nON \n    object_id = object_id;<\/code><\/pre>\n<p>\u9019\u500b\u67e5\u8a62\u5c07\u8fd4\u56de\u7576\u524d\u88ab\u9396\u5b9a\u7684\u5c0d\u8c61\u53ca\u5176\u76f8\u95dc\u7684\u6703\u8a71 ID\uff0c\u5e6b\u52a9\u7528\u6236\u4e86\u89e3\u54ea\u4e9b\u6703\u8a71\u6b63\u5728\u6301\u6709\u9396\u5b9a\u3002<\/p>\n<h2 id=\"%e8%a7%a3%e9%99%a4%e9%8e%96%e5%ae%9a%e7%9a%84%e6%96%b9%e6%b3%95-oPOuncAGyV\">\u89e3\u9664\u9396\u5b9a\u7684\u65b9\u6cd5<\/h2>\n<p>\u4e00\u65e6\u8b58\u5225\u51fa\u9396\u5b9a\u7684\u6703\u8a71\uff0c\u53ef\u4ee5\u63a1\u53d6\u4ee5\u4e0b\u5e7e\u7a2e\u65b9\u6cd5\u4f86\u89e3\u9664\u9396\u5b9a\uff1a<\/p>\n<h3 id=\"1-%e7%b5%82%e6%ad%a2%e6%9c%83%e8%a9%b1-oPOuncAGyV\">1. \u7d42\u6b62\u6703\u8a71<\/h3>\n<p>\u5982\u679c\u67d0\u500b\u6703\u8a71\u9577\u6642\u9593\u6301\u6709\u9396\u5b9a\uff0c\u53ef\u4ee5\u8003\u616e\u7d42\u6b62\u8a72\u6703\u8a71\u3002\u4f7f\u7528\u4ee5\u4e0b SQL \u547d\u4ee4\uff1a<\/p>\n<pre><code>ALTER SYSTEM KILL SESSION 'sid,serial#';<\/code><\/pre>\n<p>\u5176\u4e2d\uff0c<code>sid<\/code> \u548c <code>serial#<\/code> \u662f\u5f9e\u4e0a\u9762\u7684\u67e5\u8a62\u4e2d\u7372\u5f97\u7684\u6703\u8a71 ID \u548c\u5e8f\u5217\u865f\u3002<\/p>\n<h3 id=\"2-%e7%ad%89%e5%be%85%e9%8e%96%e5%ae%9a%e8%a7%a3%e9%99%a4-oPOuncAGyV\">2. \u7b49\u5f85\u9396\u5b9a\u89e3\u9664<\/h3>\n<p>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u9396\u5b9a\u53ef\u80fd\u662f\u66ab\u6642\u7684\uff0c\u7b49\u5f85\u4e00\u6bb5\u6642\u9593\u5f8c\uff0c\u9396\u5b9a\u53ef\u80fd\u6703\u81ea\u52d5\u89e3\u9664\u3002\u9019\u7a2e\u65b9\u6cd5\u9069\u5408\u65bc\u4e0d\u6025\u65bc\u9032\u884c\u64cd\u4f5c\u7684\u60c5\u6cc1\u3002<\/p>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8-dbms_lock-%e5%8c%85-oPOuncAGyV\">3. \u4f7f\u7528 DBMS_LOCK \u5305<\/h3>\n<p>Oracle \u63d0\u4f9b\u4e86 <code>DBMS_LOCK<\/code> \u5305\u4f86\u7ba1\u7406\u9396\u5b9a\u3002\u7528\u6236\u53ef\u4ee5\u4f7f\u7528\u9019\u500b\u5305\u4f86\u8acb\u6c42\u548c\u91cb\u653e\u9396\u5b9a\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 <code>DBMS_LOCK<\/code> \u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>DECLARE\n    lock_handle VARCHAR2(128);\n    lock_result INTEGER;\nBEGIN\n    DBMS_LOCK.ALLOCATE_UNIQUE('my_lock', lock_handle);\n    lock_result := DBMS_LOCK.REQUEST(lock_handle, DBMS_LOCK.X_MODE, timeout =&gt; 10, release_on_commit =&gt; TRUE);\n    IF lock_result = 0 THEN\n        -- \u7372\u5f97\u9396\u5b9a\uff0c\u57f7\u884c\u64cd\u4f5c\n        DBMS_LOCK.RELEASE(lock_handle);\n    ELSE\n        -- \u9396\u5b9a\u5931\u6557\uff0c\u8655\u7406\u76f8\u61c9\u908f\u8f2f\n    END IF;\nEND;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-oPOuncAGyV\">\u7e3d\u7d50<\/h2>\n<p>\u89e3\u9664 Oracle \u6578\u64da\u5eab\u8868\u7684\u9396\u5b9a\u662f\u4e00\u9805\u91cd\u8981\u7684\u7ba1\u7406\u4efb\u52d9\uff0c\u80fd\u5920\u78ba\u4fdd\u6578\u64da\u5eab\u7684\u9ad8\u6548\u904b\u884c\u3002\u901a\u904e\u8b58\u5225\u9396\u5b9a\u3001\u7d42\u6b62\u6703\u8a71\u6216\u4f7f\u7528 DBMS_LOCK \u5305\u7b49\u65b9\u6cd5\uff0c\u7528\u6236\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\u5eab\u7684\u9396\u5b9a\u554f\u984c\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u904b\u884c\u7684\u61c9\u7528\u7a0b\u5e8f\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4e5f\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u4e86\u89e3\u5982\u4f55\u8655\u7406\u6578\u64da\u5eab\u9396\u5b9a\u554f\u984c\uff0c\u5c07\u6709\u52a9\u65bc\u63d0\u5347\u6574\u9ad4\u7684\u6578\u64da\u5eab\u6027\u80fd\u548c\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u89e3\u9664 Oracle \u6578\u64da\u5eab\u8868\u7684\u9396\u5b9a\uff0c\u89e3\u6c7a\u8868\u88ab\u9396\u554f\u984c\uff0c\u78ba\u4fdd\u6578\u64da\u5eab\u64cd\u4f5c\u9806\u5229\u9032\u884c\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-195927","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/195927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=195927"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/195927\/revisions"}],"predecessor-version":[{"id":195928,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/195927\/revisions\/195928"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=195927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=195927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=195927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}