{"id":21361,"date":"2024-01-02T08:06:27","date_gmt":"2024-01-02T08:06:27","guid":{"rendered":"https:\/\/server.hk\/blog\/21361\/"},"modified":"2024-11-14T10:35:58","modified_gmt":"2024-11-14T02:35:58","slug":"how-to-fix-postgresql-error-code-25p03-idle_in_transaction_session_timeout","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21361\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25P03 &#8211; idle_in_transaction_session_timeout"},"content":{"rendered":"<h1 id=\"how-to-fix-postgresql-error-code-25p03-idle_in_transaction_session_timeout-zrjtHGHVsq\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25P03 &#8211; idle_in_transaction_session_timeout<\/h1>\n<p>PostgreSQL \u662f\u4e00\u500b\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u5f0f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u88ab\u5168\u7403\u7684\u4f01\u696d\u548c\u6a5f\u69cb\u4f7f\u7528\u3002\u7136\u800c\uff0c\u8207\u4efb\u4f55\u8edf\u4ef6\u4e00\u6a23\uff0c\u5b83\u53ef\u80fd\u6703\u9047\u5230\u932f\u8aa4\u548c\u554f\u984c\uff0c\u9700\u8981\u89e3\u6c7a\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25P03 &#8211; idle_in_transaction_session_timeout\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u6b64\u932f\u8aa4\u7684\u542b\u7fa9\u4ee5\u53ca\u5982\u4f55\u4fee\u5fa9\u5b83\u3002<\/p>\n<h2 id=\"understanding-the-error-zrjtHGHVsq\">\u7406\u89e3\u932f\u8aa4<\/h2>\n<p>\u7576\u4e00\u500b\u4e8b\u52d9\u9592\u7f6e\u6642\u9593\u8d85\u904e\u8a2d\u5b9a\u7684\u8d85\u6642\u503c\u6642\uff0c\u4fbf\u6703\u51fa\u73fe PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25P03 &#8211; idle_in_transaction_session_timeout\u3002\u9ed8\u8a8d\u60c5\u6cc1\u4e0b\uff0cPostgreSQL \u5c07\u8d85\u6642\u503c\u8a2d\u70ba\u96f6\uff0c\u9019\u610f\u5473\u8457\u6c92\u6709\u8d85\u6642\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u5982\u679c\u660e\u78ba\u8a2d\u5b9a\u4e86\u8d85\u6642\u503c\u6216\u7531\u65bc\u914d\u7f6e\u932f\u8aa4\uff0c\u9019\u500b\u932f\u8aa4\u53ef\u80fd\u6703\u767c\u751f\u3002<\/p>\n<h2 id=\"identifying-the-cause-zrjtHGHVsq\">\u8b58\u5225\u932f\u8aa4\u539f\u56e0<\/h2>\n<p>\u5728\u6df1\u5165\u89e3\u6c7a\u65b9\u6848\u4e4b\u524d\uff0c\u5fc5\u9808\u78ba\u5b9a\u932f\u8aa4\u7684\u539f\u56e0\u3002\u8a72\u932f\u8aa4\u53ef\u80fd\u7531\u591a\u7a2e\u539f\u56e0\u5f15\u8d77\uff1a<\/p>\n<ul>\n<li><strong>\u9577\u6642\u9593\u904b\u884c\u7684\u4e8b\u52d9\uff1a<\/strong>\u5982\u679c\u4e00\u500b\u4e8b\u52d9\u9592\u7f6e\u6642\u9593\u904e\u9577\uff0c\u4fbf\u53ef\u80fd\u89f8\u767c idle_in_transaction_session_timeout \u932f\u8aa4\u3002<\/li>\n<li><strong>\u7db2\u7d61\u554f\u984c\uff1a<\/strong>\u5ba2\u6236\u7aef\u8207 PostgreSQL \u4f3a\u670d\u5668\u4e4b\u9593\u7684\u7db2\u7d61\u4e2d\u65b7\u6216\u9023\u63a5\u554f\u984c\u4e5f\u53ef\u80fd\u5c0e\u81f4\u8a72\u932f\u8aa4\u3002<\/li>\n<li><strong>\u8cc7\u6e90\u9650\u5236\uff1a<\/strong>\u7cfb\u7d71\u8cc7\u6e90\u4e0d\u8db3\uff0c\u4f8b\u5982\u5167\u5b58\u6216\u78c1\u789f\u7a7a\u9593\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u4e8b\u52d9\u9592\u7f6e\uff0c\u6700\u7d42\u8d85\u6642\u3002<\/li>\n<\/ul>\n<h2 id=\"fixing-the-error-zrjtHGHVsq\">\u89e3\u6c7a\u932f\u8aa4\u7684\u65b9\u6cd5<\/h2>\n<p>\u73fe\u5728\u6211\u5011\u5df2\u7d93\u4e86\u89e3\u4e86\u53ef\u80fd\u7684\u539f\u56e0\uff0c\u8b93\u6211\u5011\u4f86\u63a2\u8a0e\u4e00\u4e9b\u89e3\u6c7a\u65b9\u6848\uff0c\u4ee5\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25P03 &#8211; idle_in_transaction_session_timeout\uff1a<\/p>\n<h3 id=\"1-adjusting-the-timeout-value-zrjtHGHVsq\">1. \u8abf\u6574\u8d85\u6642\u503c<\/h3>\n<p>\u7b2c\u4e00\u6b65\u662f\u6aa2\u67e5 PostgreSQL \u914d\u7f6e\u4e2d\u8a2d\u5b9a\u7684\u8d85\u6642\u503c\u3002\u4f60\u53ef\u4ee5\u901a\u904e\u8a2a\u554f <code>postgresql.conf<\/code> \u6587\u4ef6\u4f86\u57f7\u884c\u6b64\u64cd\u4f5c\u3002\u67e5\u627e <code>idle_in_transaction_session_timeout<\/code> \u53c3\u6578\uff0c\u4e26\u6839\u64da\u4f60\u7684\u9700\u6c42\u9032\u884c\u8abf\u6574\u3002\u5c07\u5176\u8a2d\u70ba\u96f6\u5c07\u7981\u7528\u8d85\u6642\uff0c\u4f46\u8acb\u6ce8\u610f\uff0c\u9019\u53ef\u80fd\u5c0e\u81f4\u9577\u6642\u9593\u904b\u884c\u7684\u9592\u7f6e\u4e8b\u52d9\u3002<\/p>\n<pre><code># postgresql.conf\r\n\r\n# \u8abf\u6574\u8d85\u6642\u503c\uff08\u4ee5\u6beb\u79d2\u70ba\u55ae\u4f4d\uff09\r\nidle_in_transaction_session_timeout = 60000\r\n<\/code><\/pre>\n<h3 id=\"2-optimizing-transactions-zrjtHGHVsq\">2. \u512a\u5316\u4e8b\u52d9<\/h3>\n<p>\u5982\u679c\u4f60\u6709\u9577\u6642\u9593\u904b\u884c\u7684\u4e8b\u52d9\uff0c\u5efa\u8b70\u5c0d\u5b83\u5011\u9032\u884c\u512a\u5316\uff0c\u4ee5\u6e1b\u5c11\u9047\u5230 idle_in_transaction_session_timeout \u932f\u8aa4\u7684\u53ef\u80fd\u6027\u3002\u6aa2\u67e5\u4f60\u7684\u61c9\u7528\u7a0b\u5f0f\u4ee3\u78bc\uff0c\u78ba\u4fdd\u4e8b\u52d9\u53ca\u6642\u63d0\u4ea4\u6216\u56de\u6efe\u3002\u907f\u514d\u5728\u6c92\u6709\u6d3b\u52d5\u7684\u60c5\u6cc1\u4e0b\u4fdd\u6301\u4e8b\u52d9\u9577\u6642\u9593\u6253\u958b\u3002<\/p>\n<h3 id=\"3-checking-network-connectivity-zrjtHGHVsq\">3. \u6aa2\u67e5\u7db2\u7d61\u9023\u63a5<\/h3>\n<p>\u5982\u679c\u662f\u7db2\u7d61\u554f\u984c\u5c0e\u81f4\u4e86\u932f\u8aa4\uff0c\u8acb\u6aa2\u67e5\u5ba2\u6236\u7aef\u8207 PostgreSQL \u4f3a\u670d\u5668\u4e4b\u9593\u7684\u9023\u63a5\u3002\u78ba\u4fdd\u6c92\u6709\u9632\u706b\u7246\u9650\u5236\u6216\u7db2\u7d61\u4e2d\u65b7\u53ef\u80fd\u5c0e\u81f4\u4e8b\u52d9\u9592\u7f6e\u3002\u76e3\u63a7\u7db2\u7d61\u65e5\u8a8c\u4e26\u9032\u884c\u7db2\u7d61\u8a3a\u65b7\uff0c\u53ef\u4ee5\u5e6b\u52a9\u8b58\u5225\u548c\u89e3\u6c7a\u4efb\u4f55\u9023\u63a5\u554f\u984c\u3002<\/p>\n<h3 id=\"4-monitoring-system-resources-zrjtHGHVsq\">4. \u76e3\u63a7\u7cfb\u7d71\u8cc7\u6e90<\/h3>\n<p>\u8cc7\u6e90\u9650\u5236\u4e5f\u53ef\u80fd\u5c0e\u81f4\u4e8b\u52d9\u9592\u7f6e\u4e26\u96a8\u5f8c\u5f15\u767c\u8d85\u6642\u932f\u8aa4\u3002\u76e3\u63a7\u4f60\u7684\u7cfb\u7d71\u8cc7\u6e90\uff0c\u4f8b\u5982\u5167\u5b58\u548c\u78c1\u789f\u7a7a\u9593\uff0c\u78ba\u4fdd\u5b83\u5011\u8db3\u4ee5\u652f\u6301\u5de5\u4f5c\u8ca0\u8f09\u3002\u8003\u616e\u512a\u5316\u4f60\u7684\u6578\u64da\u5eab\u67e5\u8a62\u548c\u7d22\u5f15\uff0c\u4ee5\u6e1b\u5c11\u8cc7\u6e90\u4f7f\u7528\u4e26\u63d0\u9ad8\u6574\u9ad4\u6027\u80fd\u3002<\/p>\n<h2 id=\"summary-zrjtHGHVsq\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u8abf\u6574\u8d85\u6642\u503c\u3001\u512a\u5316\u4e8b\u52d9\u3001\u6aa2\u67e5\u7db2\u7d61\u9023\u63a5\u548c\u76e3\u63a7\u7cfb\u7d71\u8cc7\u6e90\uff0c\u53ef\u4ee5\u89e3\u6c7a PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25P03 &#8211; idle_in_transaction_session_timeout\u3002\u6309\u7167\u9019\u4e9b\u6b65\u9a5f\u64cd\u4f5c\uff0c\u4f60\u53ef\u4ee5\u78ba\u4fdd\u4f60\u7684 PostgreSQL \u6578\u64da\u5eab\u5e73\u7a69\u904b\u884c\uff0c\u4e0d\u6703\u9047\u5230\u6b64\u932f\u8aa4\u3002<\/p>\n<p>\u5982\u9700\u53ef\u9760\u4e14\u9ad8\u6548\u80fd\u7684 VPS \u8a17\u7ba1\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u6211\u5011\u7684 VPS \u8a17\u7ba1\u670d\u52d9\u65e8\u5728\u6eff\u8db3\u5404\u7a2e\u898f\u6a21\u7684\u4f01\u696d\u9700\u6c42\uff0c\u63d0\u4f9b\u51fa\u8272\u7684\u6027\u80fd\u3001\u5b89\u5168\u6027\u548c\u652f\u63f4\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":[4925],"tags":[],"class_list":["post-21361","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21361","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=21361"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21361\/revisions"}],"predecessor-version":[{"id":24136,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21361\/revisions\/24136"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}