{"id":21357,"date":"2024-01-02T08:02:31","date_gmt":"2024-01-02T08:02:31","guid":{"rendered":"https:\/\/server.hk\/blog\/21357\/"},"modified":"2024-11-14T10:36:03","modified_gmt":"2024-11-14T02:36:03","slug":"how-to-fix-postgresql-error-code-25006-read_only_sql_transaction","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21357\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25006 &#8211; read_only_sql_transaction"},"content":{"rendered":"<h1 id=\"how-to-fix-postgresql-error-code-25006-read_only_sql_transaction-vDdNFAwGsl\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25006 &#8211; read_only_sql_transaction<\/h1>\n<p>PostgreSQL \u662f\u4e00\u500b\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u88ab\u5168\u7403\u7684\u958b\u767c\u8005\u548c\u4f01\u696d\u4f7f\u7528\u3002\u7136\u800c\uff0c\u8207\u6240\u6709\u8edf\u4ef6\u4e00\u6a23\uff0cPostgreSQL \u4e5f\u53ef\u80fd\u9047\u5230\u932f\u8aa4\uff0c\u5c0e\u81f4\u5176\u6b63\u5e38\u904b\u4f5c\u4e2d\u65b7\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25006 &#8211; read_only_sql_transaction\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u8a72\u932f\u8aa4\u7684\u6210\u56e0\uff0c\u4e26\u63d0\u4f9b\u9010\u6b65\u89e3\u6c7a\u65b9\u6848\u4f86\u4fee\u5fa9\u5b83\u3002<\/p>\n<h2 id=\"understanding-postgresql-error-code-25006-read_only_sql_transaction-vDdNFAwGsl\">\u4e86\u89e3 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25006 &#8211; read_only_sql_transaction<\/h2>\n<p>PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25006 &#8211; read_only_sql_transaction \u767c\u751f\u5728\u4e8b\u52d9\u5617\u8a66\u5728\u53ea\u8b80\u4e8b\u52d9\u4e2d\u4fee\u6539\u6578\u64da\u6642\u3002\u5728 PostgreSQL \u4e2d\uff0c\u53ea\u8b80\u4e8b\u52d9\u662f\u4e0d\u5141\u8a31\u4fee\u6539\u6578\u64da\u5eab\u4e2d\u4efb\u4f55\u6578\u64da\u7684\u4e8b\u52d9\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u51fa\u73fe\u5728\u7528\u6236\u6216\u61c9\u7528\u7a0b\u5f0f\u8a66\u5716\u5728\u53ea\u8b80\u4e8b\u52d9\u4e2d\u57f7\u884c\u5beb\u5165\u64cd\u4f5c\uff0c\u5982 INSERT\u3001UPDATE \u6216 DELETE \u8a9e\u53e5\u6642\u3002<\/p>\n<p>\u7576\u6b64\u932f\u8aa4\u767c\u751f\u6642\uff0cPostgreSQL \u5c07\u56de\u6efe\u8a72\u4e8b\u52d9\u4e26\u8fd4\u56de\u932f\u8aa4\u4fe1\u606f &#8220;read_only_sql_transaction&#8221;\u3002\u8a72\u932f\u8aa4\u4fe1\u606f\u8868\u660e\uff0c\u7531\u65bc\u53ea\u8b80\u6a21\u5f0f\uff0c\u4e8b\u52d9\u4e0d\u88ab\u5141\u8a31\u4fee\u6539\u6578\u64da\u3002<\/p>\n<h2 id=\"causes-of-postgresql-error-code-25006-read_only_sql_transaction-vDdNFAwGsl\">PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25006 &#8211; read_only_sql_transaction \u7684\u6210\u56e0<\/h2>\n<p>\u5c0e\u81f4 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25006 &#8211; read_only_sql_transaction \u7684\u53ef\u80fd\u539f\u56e0\u6709\u4ee5\u4e0b\u5e7e\u9ede\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u5eab\u914d\u7f6e\uff1a<\/strong>\u6578\u64da\u5eab\u53ef\u80fd\u88ab\u914d\u7f6e\u70ba\u53ea\u8b80\u6a21\u5f0f\uff0c\u7121\u8ad6\u662f\u6545\u610f\u9084\u662f\u7121\u610f\u3002\u9019\u53ef\u80fd\u767c\u751f\u5728\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u70ba\u7dad\u8b77\u6216\u5099\u4efd\u76ee\u7684\u5c07\u6578\u64da\u5eab\u8a2d\u7f6e\u70ba\u53ea\u8b80\u6a21\u5f0f\u6642\u3002<\/li>\n<li><strong>\u4e8b\u52d9\u9694\u96e2\u7d1a\u5225\uff1a<\/strong>\u4e8b\u52d9\u9694\u96e2\u7d1a\u5225\u53ef\u80fd\u8a2d\u7f6e\u70ba &#8220;SERIALIZABLE&#8221; \u6216 &#8220;REPEATABLE READ&#8221;\uff0c\u9019\u6703\u963b\u6b62\u4e8b\u52d9\u5167\u7684\u5beb\u5165\u64cd\u4f5c\u3002<\/li>\n<li><strong>\u61c9\u7528\u7a0b\u5f0f\u4ee3\u78bc\uff1a<\/strong>\u61c9\u7528\u7a0b\u5f0f\u4ee3\u78bc\u53ef\u80fd\u986f\u5f0f\u555f\u52d5\u4e86\u4e00\u500b\u53ea\u8b80\u4e8b\u52d9\uff0c\u7136\u5f8c\u5617\u8a66\u5728\u8a72\u4e8b\u52d9\u5167\u4fee\u6539\u6578\u64da\u3002<\/li>\n<\/ul>\n<h2 id=\"fixing-postgresql-error-code-25006-read_only_sql_transaction-vDdNFAwGsl\">\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25006 &#8211; read_only_sql_transaction<\/h2>\n<p>\u8981\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25006 &#8211; read_only_sql_transaction\uff0c\u8acb\u9075\u5faa\u4ee5\u4e0b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-check-database-configuration-vDdNFAwGsl\">\u6b65\u9a5f 1\uff1a\u6aa2\u67e5\u6578\u64da\u5eab\u914d\u7f6e<\/h3>\n<p>\u9996\u5148\uff0c\u6aa2\u67e5\u6578\u64da\u5eab\u662f\u5426\u6545\u610f\u8a2d\u7f6e\u70ba\u53ea\u8b80\u6a21\u5f0f\u3002\u4f7f\u7528\u6578\u64da\u5eab\u5ba2\u6236\u7aef\u6216\u547d\u4ee4\u884c\u5de5\u5177\u9023\u63a5\u5230\u6578\u64da\u5eab\uff0c\u4e26\u904b\u884c\u4ee5\u4e0b SQL \u547d\u4ee4\uff1a<\/p>\n<pre><code>SELECT pg_is_in_recovery();<\/code><\/pre>\n<p>\u5982\u679c\u7d50\u679c\u70ba &#8220;true&#8221;\uff0c\u9019\u610f\u5473\u8457\u6578\u64da\u5eab\u8655\u65bc\u6062\u5fa9\u6a21\u5f0f\u4e26\u4e14\u662f\u53ea\u8b80\u7684\u3002\u5728\u9019\u7a2e\u60c5\u6cc1\u4e0b\uff0c\u60a8\u9700\u8981\u7b49\u5230\u6062\u5fa9\u904e\u7a0b\u5b8c\u6210\uff0c\u6216\u8005\u806f\u7e6b\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u4ee5\u7372\u53d6\u9032\u4e00\u6b65\u7684\u6307\u793a\u3002<\/p>\n<h3 id=\"2-check-transaction-isolation-level-vDdNFAwGsl\">\u6b65\u9a5f 2\uff1a\u6aa2\u67e5\u4e8b\u52d9\u9694\u96e2\u7d1a\u5225<\/h3>\n<p>\u5982\u679c\u6578\u64da\u5eab\u4e0d\u5728\u53ea\u8b80\u6a21\u5f0f\uff0c\u8acb\u6aa2\u67e5\u4e8b\u52d9\u9694\u96e2\u7d1a\u5225\u3002\u9023\u63a5\u5230\u6578\u64da\u5eab\u4e26\u904b\u884c\u4ee5\u4e0b SQL \u547d\u4ee4\uff1a<\/p>\n<pre><code>SHOW transaction_isolation;<\/code><\/pre>\n<p>\u5982\u679c\u7d50\u679c\u70ba &#8220;SERIALIZABLE&#8221; \u6216 &#8220;REPEATABLE READ&#8221;\uff0c\u5247\u8868\u793a\u4e8b\u52d9\u9694\u96e2\u7d1a\u5225\u963b\u6b62\u4e86\u5beb\u5165\u64cd\u4f5c\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u904b\u884c\u4ee5\u4e0b SQL \u547d\u4ee4\u5c07\u9694\u96e2\u7d1a\u5225\u66f4\u6539\u70ba &#8220;READ COMMITTED&#8221;\uff1a<\/p>\n<pre><code>SET transaction_isolation = 'READ COMMITTED';<\/code><\/pre>\n<h3 id=\"3-check-application-code-vDdNFAwGsl\">\u6b65\u9a5f 3\uff1a\u6aa2\u67e5\u61c9\u7528\u7a0b\u5f0f\u4ee3\u78bc<\/h3>\n<p>\u5982\u679c\u6578\u64da\u5eab\u914d\u7f6e\u548c\u4e8b\u52d9\u9694\u96e2\u7d1a\u5225\u4e0d\u662f\u5c0e\u81f4\u932f\u8aa4\u7684\u539f\u56e0\uff0c\u8acb\u6aa2\u67e5\u60a8\u7684\u61c9\u7528\u7a0b\u5f0f\u4ee3\u78bc\u3002\u67e5\u770b\u662f\u5426\u6709\u4efb\u4f55\u4ee3\u78bc\u986f\u5f0f\u555f\u52d5\u4e86\u53ea\u8b80\u4e8b\u52d9\uff0c\u7136\u5f8c\u8a66\u5716\u5728\u8a72\u4e8b\u52d9\u5167\u4fee\u6539\u6578\u64da\u3002\u4fee\u6539\u4ee3\u78bc\u4ee5\u79fb\u9664\u53ea\u8b80\u4e8b\u52d9\uff0c\u6216\u5c07\u5beb\u5165\u64cd\u4f5c\u79fb\u81f3\u53ea\u8b80\u4e8b\u52d9\u4e4b\u5916\u3002<\/p>\n<p>\u6309\u7167\u9019\u4e9b\u6b65\u9a5f\uff0c\u60a8\u61c9\u8a72\u80fd\u5920\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25006 &#8211; read_only_sql_transaction\uff0c\u4e26\u6062\u5fa9\u6b63\u5e38\u7684\u6578\u64da\u5eab\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"summary-vDdNFAwGsl\">\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u7d50\u4f86\u8aaa\uff0cPostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a25006 &#8211; read_only_sql_transaction \u767c\u751f\u5728\u4e8b\u52d9\u5617\u8a66\u5728\u53ea\u8b80\u4e8b\u52d9\u4e2d\u4fee\u6539\u6578\u64da\u6642\u3002\u6b64\u932f\u8aa4\u53ef\u80fd\u7531\u6578\u64da\u5eab\u914d\u7f6e\u3001\u4e8b\u52d9\u9694\u96e2\u7d1a\u5225\u6216\u61c9\u7528\u7a0b\u5f0f\u4ee3\u78bc\u5f15\u8d77\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u8acb\u6aa2\u67e5\u6578\u64da\u5eab\u914d\u7f6e\uff0c\u5982\u6709\u5fc5\u8981\u8abf\u6574\u4e8b\u52d9\u9694\u96e2\u7d1a\u5225\uff0c\u4e26\u5be9\u67e5\u61c9\u7528\u7a0b\u5f0f\u4ee3\u78bc\u3002\u5982\u679c\u60a8\u9047\u5230\u6b64\u932f\u8aa4\uff0c\u8acb\u806f\u7e6b\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u6216\u53c3\u8003 PostgreSQL \u6587\u6a94\u4ee5\u7372\u53d6\u9032\u4e00\u6b65\u7684\u5e6b\u52a9\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\u63d0\u4f9b\u60a8\u6240\u9700\u7684\u9748\u6d3b\u6027\u548c\u64f4\u5c55\u6027\uff0c\u4ee5\u652f\u6301\u60a8\u7684 PostgreSQL \u6578\u64da\u5eab\u548c\u61c9\u7528\u7a0b\u5f0f\u3002\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u4e86\u89e3\u66f4\u591a\u95dc\u65bc\u6211\u5011\u7684\u7522\u54c1\u548c\u5982\u4f55\u5e6b\u52a9\u60a8\u6210\u529f\u7684\u4fe1\u606f\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-21357","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21357","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=21357"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21357\/revisions"}],"predecessor-version":[{"id":24141,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21357\/revisions\/24141"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}