{"id":5742,"date":"2024-11-14T12:17:53","date_gmt":"2024-11-14T04:17:53","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5742\/"},"modified":"2024-11-14T12:17:53","modified_gmt":"2024-11-14T04:17:53","slug":"oracle%e9%94%81%e8%a1%a8%e6%80%8e%e4%b9%88%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5742\/","title":{"rendered":"oracle\u9501\u8868\u600e\u4e48\u89e3"},"content":{"rendered":"<blockquote><p>\n  \u89e3\u9664 oracle \u9501\u8868\u95ee\u9898\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 ddl \u8bed\u53e5\u91cd\u65b0\u5b9a\u4e49\u53d7\u5f71\u54cd\u7684\u8868\uff0c\u4f46\u4f1a\u4e22\u5f03\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\u3002\u4f7f\u7528 unlock \u8bed\u53e5\u91ca\u653e\u4f1a\u8bdd\u7684\u9501\u3002\u7ec8\u6b62\u5bfc\u81f4\u9501\u5b9a\u7684\u4f1a\u8bdd\uff0c\u4f46\u53ef\u80fd\u5bfc\u81f4\u6570\u636e\u4e22\u5931\u3002\u4f7f\u7528 dbms_lock \u5305\u4ee5\u7f16\u7a0b\u65b9\u5f0f\u7ba1\u7406\u9501\uff0c\u53ef\u4ee5\u901a\u8fc7\u5f3a\u5236\u91ca\u653e\u9501\u3001\u8bf7\u6c42\u6216\u91ca\u653e\u6392\u5b83\u9501\u6765\u5b9e\u73b0\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/30\/2024053021490088455.jpg\" class=\"aligncenter\" title=\"oracle\u9501\u8868\u600e\u4e48\u89e3\u63d2\u56fe\" alt=\"oracle\u9501\u8868\u600e\u4e48\u89e3\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u89e3\u9664 Oracle \u9501\u8868<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong>\u5982\u4f55\u89e3\u9664 Oracle \u9501\u8868\uff1f<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 DDL \u8bed\u53e5<\/strong><\/p>\n<ul>\n<li>\u53ef\u4ee5\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u91cd\u65b0\u5b9a\u4e49\u53d7\u5f71\u54cd\u7684\u8868\uff0c\u4f46\u8fd9\u4f1a\u4e22\u5f03\u6240\u6709\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\u3002<\/li>\n<\/ul>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 UNLOCK \u8bed\u53e5<\/strong><\/p>\n<ul>\n<li>UNLOCK \u8bed\u53e5\u53ef\u7528\u4e8e\u91ca\u653e\u9501\u5b9a\u67d0\u8868\u7684\u4f1a\u8bdd\u7684\u9501\u3002<\/li>\n<\/ul>\n<p><strong>\u65b9\u6cd5 3\uff1a\u7ec8\u6b62\u4f1a\u8bdd<\/strong><\/p>\n<ul>\n<li>\u53ef\u4ee5\u7ec8\u6b62\u5bfc\u81f4\u9501\u5b9a\u7684\u4f1a\u8bdd\uff0c\u4f46\u53ef\u80fd\u4f1a\u5bfc\u81f4\u3002<\/li>\n<\/ul>\n<p><strong>\u65b9\u6cd5 4\uff1a\u4f7f\u7528 DBMS_LOCK \u5305<\/strong><\/p>\n<ul>\n<li>DBMS_LOCK \u5305\u63d0\u4f9b\u4e86\u4e00\u79cd\u4ee5\u7f16\u7a0b\u65b9\u5f0f\u7ba1\u7406\u9501\u7684\u673a\u5236\u3002<\/li>\n<\/ul>\n<p><strong>\u8be6\u7ec6\u8bf4\u660e<\/strong><\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 DDL \u8bed\u53e5<\/strong><\/p>\n<pre>ALTER TABLE table_name REBUILD;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 UNLOCK \u8bed\u53e5<\/strong><\/p>\n<pre>UNLOCK TABLES table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 3\uff1a\u7ec8\u6b62\u4f1a\u8bdd<\/strong><\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u7ec8\u6b62\u4f1a\u8bdd\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 ALTER SYSTEM KILL SESSION \u8bed\u53e5\u3002<\/li>\n<li>\u4f7f\u7528 svrmgrl \u5de5\u5177\u3002<\/li>\n<\/ul>\n<p><strong>\u65b9\u6cd5 4\uff1a\u4f7f\u7528 DBMS_LOCK \u5305<\/strong><\/p>\n<p>DBMS_LOCK \u5305\u63d0\u4f9b\u4ee5\u4e0b\u8fc7\u7a0b\u6765\u7ba1\u7406\u9501\uff1a<\/p>\n<ul>\n<li>DBMS_LOCK.FORCE_RELEASE()\uff1a\u5f3a\u5236\u91ca\u653e\u4e00\u4e2a\u6216\u591a\u4e2a\u4f1a\u8bdd\u7684\u9501\u3002<\/li>\n<li>DBMS_LOCK.REQUEST_LOCK()\uff1a\u8bf7\u6c42\u4e00\u4e2a\u6216\u591a\u4e2a\u6392\u5b83\u9501\u3002<\/li>\n<li>DBMS_LOCK.RELEASE_LOCK()\uff1a\u91ca\u653e\u4e00\u4e2a\u6216\u591a\u4e2a\u4f1a\u8bdd\u7684\u9501\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>DECLARE\n  l_locked_session_id NUMBER;\nBEGIN\n  -- \u83b7\u53d6\u9501\u5b9a\u4f1a\u8bdd\u7684\u4f1a\u8bdd ID\n  SELECT session_id INTO l_locked_session_id\n  FROM v$locked_object\n  WHERE object_type = 'TABLE' AND object_name = 'table_name';\n\n  -- \u5f3a\u5236\u91ca\u653e\u9501\u5b9a\u4f1a\u8bdd\u7684\u9501\n  DBMS_LOCK.FORCE_RELEASE(l_locked_session_id);\nEND;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u9501\u8868\u600e\u4e48\u89e3\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u9664 oracle \u9501\u8868\u95ee\u9898\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 ddl \u8bed\u53e5\u91cd\u65b0\u5b9a\u4e49\u53d7\u5f71\u54cd\u7684\u8868\uff0c\u4f46\u4f1a\u4e22\u5f03\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\u3002\u4f7f\u7528 unlock \u8bed\u53e5\u91ca\u653e\u4f1a\u8bdd\u7684\u9501\u3002\u7ec8\u6b62\u5bfc\u81f4\u9501\u5b9a\u7684\u4f1a\u8bdd\uff0c\u4f46\u53ef\u80fd\u5bfc\u81f4\u6570\u636e\u4e22\u5931\u3002\u4f7f\u7528 dbms_lock \u5305\u4ee5\u7f16\u7a0b\u65b9\u5f0f\u7ba1\u7406\u9501\uff0c\u53ef\u4ee5\u901a\u8fc7\u5f3a\u5236\u91ca\u653e\u9501\u3001\u8bf7\u6c42\u6216\u91ca\u653e\u6392\u5b83\u9501\u6765\u5b9e\u73b0\u3002 \u5982\u4f55\u89e3\u9664 Oracle \u9501\u8868 \u95ee\u9898\uff1a\u5982\u4f55\u89e3\u9664 Oracle \u9501\u8868\uff1f \u89e3\u7b54\uff1a \u65b9\u6cd5 1\uff1a\u4f7f\u7528 DDL \u8bed\u53e5 \u53ef\u4ee5\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u91cd\u65b0\u5b9a\u4e49\u53d7\u5f71\u54cd\u7684\u8868\uff0c\u4f46\u8fd9\u4f1a\u4e22\u5f03\u6240\u6709\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\u3002 \u65b9\u6cd5 2\uff1a\u4f7f\u7528 UNLOCK \u8bed\u53e5 UNLOCK \u8bed\u53e5\u53ef\u7528\u4e8e\u91ca\u653e\u9501\u5b9a\u67d0\u8868\u7684\u4f1a\u8bdd\u7684\u9501\u3002 \u65b9\u6cd5 3\uff1a\u7ec8\u6b62\u4f1a\u8bdd \u53ef\u4ee5\u7ec8\u6b62\u5bfc\u81f4\u9501\u5b9a\u7684\u4f1a\u8bdd\uff0c\u4f46\u53ef\u80fd\u4f1a\u5bfc\u81f4\u3002 \u65b9\u6cd5 4\uff1a\u4f7f\u7528 DBMS_LOCK \u5305 DBMS_LOCK \u5305\u63d0\u4f9b\u4e86\u4e00\u79cd\u4ee5\u7f16\u7a0b\u65b9\u5f0f\u7ba1\u7406\u9501\u7684\u673a\u5236\u3002 \u8be6\u7ec6\u8bf4\u660e \u65b9\u6cd5 1\uff1a\u4f7f\u7528 DDL \u8bed\u53e5 ALTER TABLE table_name REBUILD; \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5 2\uff1a\u4f7f\u7528 UNLOCK \u8bed\u53e5 UNLOCK TABLES [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5742","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5742","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=5742"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5742\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}