{"id":21442,"date":"2024-01-02T09:27:23","date_gmt":"2024-01-02T09:27:23","guid":{"rendered":"https:\/\/server.hk\/blog\/21442\/"},"modified":"2024-11-14T10:34:18","modified_gmt":"2024-11-14T02:34:18","slug":"how-to-fix-postgresql-error-code-53200-out_of_memory","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21442\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a53200 &#8211; out_of_memory"},"content":{"rendered":"<h1 id=\"how-to-fix-postgresql-error-code-53200-out_of_memory-KtosmdUGHm\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a53200 &#8211; out_of_memory<\/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\u4e16\u754c\u5404\u5730\u7684\u4f01\u696d\u548c\u6a5f\u69cb\u4f7f\u7528\u3002\u7136\u800c\uff0c\u548c\u5176\u4ed6\u8edf\u4ef6\u4e00\u6a23\uff0cPostgreSQL \u4e5f\u53ef\u80fd\u6703\u9047\u5230\u932f\u8aa4\uff0c\u5c0e\u81f4\u5176\u6b63\u5e38\u64cd\u4f5c\u4e2d\u65b7\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a53200 &#8211; out_of_memory\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u6b64\u932f\u8aa4\u7684\u539f\u56e0\u4e26\u63d0\u4f9b\u89e3\u6c7a\u65b9\u6848\u4f86\u4fee\u5fa9\u5b83\u3002<\/p>\n<h2 id=\"understanding-postgresql-error-code-53200-out_of_memory-KtosmdUGHm\">\u7406\u89e3 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a53200 &#8211; out_of_memory<\/h2>\n<p>PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a53200 &#8211; out_of_memory \u767c\u751f\u5728\u6578\u64da\u5eab\u7cfb\u7d71\u7121\u6cd5\u63d0\u4f9b\u8db3\u5920\u7684\u8a18\u61b6\u9ad4\u4f86\u57f7\u884c\u7279\u5b9a\u64cd\u4f5c\u6642\u3002\u9019\u500b\u932f\u8aa4\u53ef\u80fd\u7531\u4ee5\u4e0b\u5e7e\u500b\u56e0\u7d20\u89f8\u767c\uff1a<\/p>\n<ul>\n<li>PostgreSQL \u4f3a\u670d\u5668\u7684\u8a18\u61b6\u9ad4\u5206\u914d\u4e0d\u8db3<\/li>\n<li>\u9700\u8981\u7684\u8a18\u61b6\u9ad4\u8d85\u904e\u53ef\u7528\u91cf\u7684\u5927\u578b\u8907\u96dc\u67e5\u8a62<\/li>\n<li>\u6578\u64da\u5eab\u7cfb\u7d71\u7684\u8a18\u61b6\u9ad4\u4f7f\u7528\u6548\u7387\u4e0d\u4f73<\/li>\n<\/ul>\n<h2 id=\"fixing-postgresql-error-code-53200-out_of_memory-KtosmdUGHm\">\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a53200 &#8211; out_of_memory<\/h2>\n<p>\u8981\u89e3\u6c7a PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a53200 &#8211; out_of_memory\uff0c\u60a8\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\uff1a<\/p>\n<h3 id=\"1-increase-memory-allocation-KtosmdUGHm\">1. \u589e\u52a0\u8a18\u61b6\u9ad4\u5206\u914d<\/h3>\n<p>\u7b2c\u4e00\u6b65\u662f\u78ba\u4fdd\u60a8\u7684 PostgreSQL \u4f3a\u670d\u5668\u5206\u914d\u4e86\u8db3\u5920\u7684\u8a18\u61b6\u9ad4\u4f86\u61c9\u5c0d\u5de5\u4f5c\u8ca0\u8f09\u3002\u60a8\u53ef\u4ee5\u901a\u904e\u4fee\u6539 PostgreSQL \u7684\u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u70ba <code>postgresql.conf<\/code>\uff09\u4f86\u589e\u52a0\u8a18\u61b6\u9ad4\u5206\u914d\u3002\u67e5\u627e <code>shared_buffers<\/code> \u53c3\u6578\uff0c\u4e26\u5c07\u5176\u8a2d\u7f6e\u70ba\u66f4\u9ad8\u7684\u503c\u3002\u6b64\u5916\uff0c\u60a8\u4e5f\u53ef\u4ee5\u589e\u52a0 <code>work_mem<\/code> \u548c <code>maintenance_work_mem<\/code> \u53c3\u6578\uff0c\u4ee5\u70ba\u55ae\u500b\u67e5\u8a62\u548c\u7dad\u8b77\u64cd\u4f5c\u5206\u914d\u66f4\u591a\u7684\u8a18\u61b6\u9ad4\u3002<\/p>\n<pre><code># shared_buffers \u7684\u914d\u7f6e\u7bc4\u4f8b\r\nshared_buffers = 4GB\r\n\r\n# work_mem \u7684\u914d\u7f6e\u7bc4\u4f8b\r\nwork_mem = 64MB\r\n\r\n# maintenance_work_mem \u7684\u914d\u7f6e\u7bc4\u4f8b\r\nmaintenance_work_mem = 1GB\r\n<\/code><\/pre>\n<h3 id=\"2-optimize-queries-KtosmdUGHm\">2. \u512a\u5316\u67e5\u8a62<\/h3>\n<p>\u5982\u679c\u662f\u56e0\u70ba\u5927\u578b\u6216\u8907\u96dc\u67e5\u8a62\u5f15\u767c\u7684 out_of_memory \u932f\u8aa4\uff0c\u60a8\u53ef\u4ee5\u512a\u5316\u9019\u4e9b\u67e5\u8a62\u4ee5\u6e1b\u5c11\u8a18\u61b6\u9ad4\u4f7f\u7528\u3002\u8003\u616e\u5c07\u8907\u96dc\u7684\u67e5\u8a62\u5206\u89e3\u6210\u8f03\u5c0f\u3001\u66f4\u6613\u7ba1\u7406\u7684\u90e8\u5206\u3002\u4f7f\u7528\u9069\u7576\u7684\u7d22\u5f15\u4e26\u5206\u6790\u67e5\u8a62\u57f7\u884c\u8a08\u5283\uff0c\u4ee5\u8b58\u5225\u4efb\u4f55\u6027\u80fd\u74f6\u9838\u3002\u6b64\u5916\uff0c\u60a8\u4e5f\u53ef\u4ee5\u8abf\u6574 <code>max_connections<\/code> \u53c3\u6578\uff0c\u4ee5\u9650\u5236\u540c\u6642\u9023\u63a5\u6578\uff0c\u5f9e\u800c\u6e1b\u5c11\u8a18\u61b6\u9ad4\u4f7f\u7528\u3002<\/p>\n<h3 id=\"3-monitor-and-tune-memory-usage-KtosmdUGHm\">3. \u76e3\u63a7\u4e26\u8abf\u6574\u8a18\u61b6\u9ad4\u4f7f\u7528<\/h3>\n<p>\u5b9a\u671f\u76e3\u63a7\u60a8\u7684 PostgreSQL \u4f3a\u670d\u5668\u7684\u8a18\u61b6\u9ad4\u4f7f\u7528\u60c5\u6cc1\uff0c\u8b58\u5225\u4efb\u4f55\u7570\u5e38\u6a21\u5f0f\u6216\u5cf0\u503c\u3002\u4f7f\u7528 <code>pg_stat_activity<\/code> \u548c <code>pg_stat_bgwriter<\/code> \u7b49\u5de5\u5177\u4f86\u6536\u96c6\u6709\u95dc\u6d3b\u52d5\u9023\u63a5\u548c\u80cc\u666f\u5beb\u5165\u7a0b\u5e8f\u7684\u4fe1\u606f\u3002\u5206\u6790\u8a18\u61b6\u9ad4\u4f7f\u7528\u6a21\u5f0f\uff0c\u4e26\u76f8\u61c9\u5730\u8abf\u6574\u914d\u7f6e\u53c3\u6578\u3002\u6b64\u5916\uff0c\u8003\u616e\u555f\u7528 autovacuum \u81ea\u52d5\u56de\u6536\u7531\u6b7b\u5143\u7d44\u4f54\u7528\u7684\u8a18\u61b6\u9ad4\u3002<\/p>\n<h3 id=\"4-upgrade-hardware-KtosmdUGHm\">4. \u5347\u7d1a\u786c\u4ef6<\/h3>\n<p>\u5982\u679c\u5df2\u7d93\u5617\u8a66\u4e86\u6240\u6709\u57fa\u65bc\u8edf\u4ef6\u7684\u89e3\u6c7a\u65b9\u6848\u4f46\u4ecd\u7136\u9047\u5230 out_of_memory \u932f\u8aa4\uff0c\u53ef\u80fd\u9700\u8981\u5347\u7d1a\u60a8\u7684\u786c\u4ef6\u3002\u8003\u616e\u589e\u52a0\u4f3a\u670d\u5668\u7684 RAM\uff0c\u6216\u9077\u79fb\u5230\u5177\u5099\u66f4\u9ad8\u8a18\u61b6\u9ad4\u5bb9\u91cf\u7684\u66f4\u5f37\u5927\u6a5f\u5668\u3002\u5347\u7d1a\u786c\u4ef6\u53ef\u4ee5\u986f\u8457\u63d0\u5347\u6027\u80fd\u4e26\u6d88\u9664\u8207\u8a18\u61b6\u9ad4\u76f8\u95dc\u7684\u554f\u984c\u3002<\/p>\n<h2 id=\"summary-KtosmdUGHm\">\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u4e4b\uff0cPostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a53200 &#8211; out_of_memory \u53ef\u4ee5\u901a\u904e\u589e\u52a0\u8a18\u61b6\u9ad4\u5206\u914d\u3001\u512a\u5316\u67e5\u8a62\u3001\u76e3\u63a7\u548c\u8abf\u6574\u8a18\u61b6\u9ad4\u4f7f\u7528\uff0c\u4ee5\u53ca\u5728\u5fc5\u8981\u6642\u5347\u7d1a\u786c\u4ef6\u4f86\u89e3\u6c7a\u3002\u901a\u904e\u9075\u5faa\u9019\u4e9b\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u78ba\u4fdd\u60a8\u7684 PostgreSQL \u6578\u64da\u5eab\u904b\u884c\u9806\u66a2\uff0c\u907f\u514d\u8207\u8a18\u61b6\u9ad4\u76f8\u95dc\u7684\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\u63d0\u4f9b\u9802\u7d1a\u7684 VPS \u8a17\u7ba1\u670d\u52d9\uff0c\u8b93\u60a8\u5728\u652f\u6301 PostgreSQL \u548c\u5176\u4ed6\u6578\u64da\u5eab\u9700\u6c42\u6642\u4eab\u53d7\u865b\u64ec\u79c1\u4eba\u4f3a\u670d\u5668\u7684\u5f37\u5927\u548c\u9748\u6d3b\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":[4925],"tags":[],"class_list":["post-21442","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21442","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=21442"}],"version-history":[{"count":2,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21442\/revisions"}],"predecessor-version":[{"id":24044,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21442\/revisions\/24044"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21442"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21442"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21442"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}