{"id":20820,"date":"2024-01-02T06:29:22","date_gmt":"2024-01-02T06:29:22","guid":{"rendered":"https:\/\/server.hk\/blog\/20820\/"},"modified":"2024-11-14T10:38:00","modified_gmt":"2024-11-14T02:38:00","slug":"how-to-fix-postgresql-error-code-0b000-invalid_transaction_initiation","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/20820\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a0B000 &#8211; invalid_transaction_initiation"},"content":{"rendered":"<h1 id=\"how-to-fix-postgresql-error-code-0b000-invalid_transaction_initiation-QdQxRGARFj\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a0B000 &#8211; invalid_transaction_initiation<\/h1>\n<p>PostgreSQL \u662f\u4e00\u6b3e\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u5f0f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u985e\u61c9\u7528\u7a0b\u5e8f\u3002\u7136\u800c\uff0c\u8207\u5176\u4ed6\u8edf\u9ad4\u76f8\u6bd4\uff0c\u5b83\u4e5f\u53ef\u80fd\u9047\u5230\u932f\u8aa4\uff0c\u5f9e\u800c\u5f71\u97ff\u5176\u6b63\u5e38\u904b\u4f5c\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a0B000 &#8211; invalid_transaction_initiation\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u6b64\u932f\u8aa4\u7684\u6210\u56e0\u4e26\u63d0\u4f9b\u76f8\u61c9\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"understanding-the-error-QdQxRGARFj\">\u7406\u89e3\u932f\u8aa4<\/h2>\n<p>\u7576\u5617\u8a66\u555f\u52d5\u4e00\u500b\u7121\u6548\u7684\u4e8b\u52d9\u6642\uff0c\u6703\u51fa\u73fe PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a0B000 &#8211; invalid_transaction_initiation\u3002\u6b64\u932f\u8aa4\u901a\u5e38\u8868\u660e PostgreSQL \u4e2d\u7684\u4e8b\u52d9\u7ba1\u7406\u5b58\u5728\u554f\u984c\u3002<\/p>\n<h2 id=\"possible-causes-QdQxRGARFj\">\u53ef\u80fd\u7684\u6210\u56e0<\/h2>\n<p>\u9019\u500b\u932f\u8aa4\u53ef\u80fd\u6709\u5e7e\u500b\u6f5b\u5728\u7684\u539f\u56e0\uff1a<\/p>\n<ul>\n<li><strong>\u7121\u6548\u7684\u4e8b\u52d9\u72c0\u614b\uff1a<\/strong> \u5982\u679c\u4e8b\u52d9\u8655\u65bc\u7121\u6548\u72c0\u614b\uff0c\u4f8b\u5982\u5df2\u5931\u6557\u6216\u4e2d\u6b62\uff0c\u5247\u53ef\u80fd\u6703\u51fa\u73fe\u6b64\u932f\u8aa4\u3002<\/li>\n<li><strong>\u4f75\u767c\u554f\u984c\uff1a<\/strong> \u82e5\u591a\u500b\u4e8b\u52d9\u540c\u6642\u5617\u8a66\u8a2a\u554f\u76f8\u540c\u8cc7\u6e90\uff0c\u5247\u53ef\u80fd\u5c0e\u81f4\u885d\u7a81\u4e26\u89f8\u767c\u6b64\u932f\u8aa4\u3002<\/li>\n<li><strong>\u8edf\u9ad4\u932f\u8aa4\uff1a<\/strong> \u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u8a72\u932f\u8aa4\u53ef\u80fd\u662f\u7531\u65bc PostgreSQL \u8edf\u9ad4\u672c\u8eab\u7684\u932f\u8aa4\u6216\u554f\u984c\u5f15\u8d77\u7684\u3002<\/li>\n<\/ul>\n<h2 id=\"fixing-the-error-QdQxRGARFj\">\u4fee\u5fa9\u932f\u8aa4<\/h2>\n<p>\u4ee5\u4e0b\u662f\u5e7e\u500b\u53ef\u4ee5\u7528\u65bc\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a0B000 &#8211; invalid_transaction_initiation \u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-check-transaction-state-QdQxRGARFj\">1. \u6aa2\u67e5\u4e8b\u52d9\u72c0\u614b<\/h3>\n<p>\u9996\u5148\uff0c\u78ba\u8a8d\u4e8b\u52d9\u7684\u72c0\u614b\u3002\u5982\u679c\u5b83\u5df2\u7d93\u5931\u6557\u6216\u4e2d\u6b62\uff0c\u60a8\u9700\u8981\u5728\u555f\u52d5\u65b0\u4e8b\u52d9\u4e4b\u524d\u56de\u6efe\u6216\u63d0\u4ea4\u5b83\u3002\u4f7f\u7528\u9069\u7576\u7684 SQL \u547d\u4ee4\u5982 ROLLBACK \u6216 COMMIT \u4f86\u8655\u7406\u4e8b\u52d9\u72c0\u614b\u3002<\/p>\n<h3 id=\"2-resolve-concurrency-issues-QdQxRGARFj\">2. \u89e3\u6c7a\u4f75\u767c\u554f\u984c<\/h3>\n<p>\u5982\u679c\u932f\u8aa4\u662f\u7531\u4f75\u767c\u554f\u984c\u5f15\u8d77\u7684\uff0c\u60a8\u53ef\u4ee5\u5617\u8a66\u5be6\u65bd\u9396\u5b9a\u6a5f\u5236\u6216\u4f7f\u7528\u4e8b\u52d9\u9694\u96e2\u7d1a\u5225\u4f86\u9632\u6b62\u885d\u7a81\u3002PostgreSQL \u63d0\u4f9b\u591a\u7a2e\u9694\u96e2\u7d1a\u5225\uff0c\u5982\u5df2\u63d0\u4ea4\u8b80\u53d6\u3001\u53ef\u91cd\u8907\u8b80\u53d6\u548c\u53ef\u5e8f\u5217\u5316\uff0c\u9019\u4e9b\u90fd\u53ef\u4ee5\u5e6b\u52a9\u7ba1\u7406\u5c0d\u8cc7\u6e90\u7684\u4e26\u767c\u8a2a\u554f\u3002<\/p>\n<h3 id=\"3-update-postgresql-QdQxRGARFj\">3. \u66f4\u65b0 PostgreSQL<\/h3>\n<p>\u5982\u679c\u60a8\u61f7\u7591\u8a72\u932f\u8aa4\u662f\u7531\u65bc PostgreSQL \u8edf\u9ad4\u4e2d\u7684\u932f\u8aa4\u6216\u554f\u984c\u9020\u6210\u7684\uff0c\u8acb\u78ba\u4fdd\u60a8\u4f7f\u7528\u7684\u662f\u6700\u65b0\u7248\u672c\u3002\u6aa2\u67e5 PostgreSQL \u5b98\u7db2\u6216\u793e\u7fa4\u8ad6\u58c7\uff0c\u67e5\u770b\u662f\u5426\u6709\u95dc\u65bc\u4e8b\u52d9\u7ba1\u7406\u7684\u5831\u544a\u932f\u8aa4\uff0c\u4e26\u78ba\u8a8d\u662f\u5426\u6709\u53ef\u7528\u7684\u66f4\u65b0\u3002<\/p>\n<h3 id=\"4-review-application-code-QdQxRGARFj\">4. \u6aa2\u67e5\u61c9\u7528\u7a0b\u5f0f\u4ee3\u78bc<\/h3>\n<p>\u6aa2\u67e5\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\u4ee3\u78bc\uff0c\u4ee5\u78ba\u4fdd\u4e8b\u52d9\u7684\u555f\u52d5\u6b63\u78ba\u7121\u8aa4\u3002\u6aa2\u67e5\u662f\u5426\u5b58\u5728\u908f\u8f2f\u932f\u8aa4\u6216\u4e0d\u6b63\u78ba\u4f7f\u7528\u4e8b\u52d9\u76f8\u95dc\u7684\u51fd\u6578\u6216\u8a9e\u53e5\u3002\u540c\u6642\uff0c\u59a5\u5584\u8655\u7406\u7570\u5e38\u548c\u932f\u8aa4\u4e5f\u662f\u4e00\u500b\u826f\u597d\u7684\u5be6\u8e10\uff0c\u4ee5\u9632\u6b62\u7121\u6548\u7684\u4e8b\u52d9\u555f\u52d5\u3002<\/p>\n<h3 id=\"5-consult-postgresql-community-QdQxRGARFj\">5. \u8aee\u8a62 PostgreSQL \u793e\u7fa4<\/h3>\n<p>\u5982\u679c\u60a8\u5df2\u5617\u8a66\u4e0a\u8ff0\u6b65\u9a5f\u4f46\u4ecd\u7121\u6cd5\u89e3\u6c7a\u932f\u8aa4\uff0c\u53ef\u4ee5\u8003\u616e\u5c0b\u6c42 PostgreSQL \u793e\u7fa4\u7684\u5e6b\u52a9\u3002\u793e\u7fa4\u8ad6\u58c7\u548c\u90f5\u4ef6\u5217\u8868\u662f\u7372\u5f97\u7d93\u9a57\u8c50\u5bcc\u7684\u7528\u6236\u548c\u958b\u767c\u8005\u5354\u52a9\u7684\u6975\u4f73\u8cc7\u6e90\u3002<\/p>\n<h2 id=\"summary-QdQxRGARFj\">\u6458\u8981<\/h2>\n<p>\u7e3d\u4e4b\uff0cPostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a0B000 &#8211; invalid_transaction_initiation \u53ef\u80fd\u7531\u591a\u7a2e\u56e0\u7d20\u9020\u6210\uff0c\u5982\u7121\u6548\u7684\u4e8b\u52d9\u72c0\u614b\u3001\u4f75\u767c\u554f\u984c\u6216\u8edf\u4ef6\u932f\u8aa4\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u60a8\u61c9\u8a72\u6aa2\u67e5\u4e8b\u52d9\u72c0\u614b\uff0c\u89e3\u6c7a\u4f75\u767c\u554f\u984c\uff0c\u66f4\u65b0 PostgreSQL\uff0c\u6aa2\u67e5\u61c9\u7528\u7a0b\u5f0f\u4ee3\u78bc\uff0c\u4e26\u5728\u9700\u8981\u6642\u5411 PostgreSQL \u793e\u7fa4\u5c0b\u6c42\u5e6b\u52a9\u3002<\/p>\n<p>\u5982\u9700\u53ef\u9760\u4e14\u9ad8\u6027\u80fd\u7684 VPS \u8a17\u7ba1\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u6211\u5011\u7684\u9999\u6e2f VPS \u8a17\u7ba1\u670d\u52d9\u70ba\u60a8\u7684 PostgreSQL \u548c\u5176\u4ed6\u6578\u64da\u5eab\u9700\u6c42\u63d0\u4f9b\u9802\u7d1a\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4fee\u5fa9 PostgreSQL &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-20820","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20820","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=20820"}],"version-history":[{"count":2,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20820\/revisions"}],"predecessor-version":[{"id":24259,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/20820\/revisions\/24259"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=20820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=20820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=20820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}