{"id":21459,"date":"2024-01-02T09:44:23","date_gmt":"2024-01-02T09:44:23","guid":{"rendered":"https:\/\/server.hk\/blog\/21459\/"},"modified":"2024-11-14T10:33:58","modified_gmt":"2024-11-14T02:33:58","slug":"how-to-fix-postgresql-error-code-57p04-database_dropped","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21459\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u78bc\uff1a57P04 &#8211; database_dropped"},"content":{"rendered":"<h1 id=\"how-to-fix-postgresql-error-code-57p04-database_dropped-MGntjvDxRi\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u78bc\uff1a57P04 &#8211; database_dropped<\/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\u958b\u767c\u8005\u548c\u7d44\u7e54\u6240\u4f7f\u7528\u3002\u7136\u800c\uff0c\u8207\u4efb\u4f55\u8edf\u4ef6\u4e00\u6a23\uff0cPostgreSQL \u4e5f\u53ef\u80fd\u6703\u9047\u5230\u932f\u8aa4\uff0c\u9019\u4e9b\u932f\u8aa4\u53ef\u80fd\u6703\u5e72\u64fe\u5176\u6b63\u5e38\u904b\u4f5c\u3002\u5176\u4e2d\u4e4b\u4e00\u4fbf\u662f &#8220;57P04 &#8211; database_dropped&#8221; \u932f\u8aa4\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u6b64\u932f\u8aa4\u7684\u610f\u7fa9\u4ee5\u53ca\u5982\u4f55\u4fee\u5fa9\u5b83\u3002<\/p>\n<h2 id=\"understanding-the-error-MGntjvDxRi\">\u4e86\u89e3\u932f\u8aa4<\/h2>\n<p>&#8220;57P04 &#8211; database_dropped&#8221; \u932f\u8aa4\u767c\u751f\u65bc PostgreSQL \u6578\u64da\u5eab\u5df2\u88ab\u522a\u9664\uff0c\u4f46\u4ecd\u6709\u6d3b\u8e8d\u7684\u9023\u63a5\u6216\u4ea4\u6613\u6b63\u5728\u5f15\u7528\u8a72\u6578\u64da\u5eab\u3002\u6b64\u932f\u8aa4\u901a\u5e38\u767c\u751f\u5728\u7528\u6236\u6216\u81ea\u52d5\u904e\u7a0b\u5617\u8a66\u8a2a\u554f\u5df2\u4e0d\u5b58\u5728\u7684\u6578\u64da\u5eab\u6642\u3002<\/p>\n<p>\u7576\u6b64\u932f\u8aa4\u767c\u751f\u6642\uff0cPostgreSQL \u5c07\u986f\u793a\u985e\u4f3c\u4ee5\u4e0b\u7684\u932f\u8aa4\u8a0a\u606f\uff1a<\/p>\n<p><code>FATAL:  database \"database_name\" does not exist<\/code><\/p>\n<p>\u9019\u689d\u932f\u8aa4\u8a0a\u606f\u8868\u660e\u6307\u5b9a\u540d\u7a31\u7684\u6578\u64da\u5eab\u5728 PostgreSQL \u4f3a\u670d\u5668\u4e0a\u4e0d\u5b58\u5728\u3002<\/p>\n<h2 id=\"resolving-the-error-MGntjvDxRi\">\u89e3\u6c7a\u932f\u8aa4<\/h2>\n<p>\u8981\u4fee\u5fa9 &#8220;57P04 &#8211; database_dropped&#8221; \u932f\u8aa4\uff0c\u60a8\u9700\u8981\u8b58\u5225\u4e26\u7d42\u6b62\u4ecd\u7136\u5f15\u7528\u5df2\u522a\u9664\u6578\u64da\u5eab\u7684\u4efb\u4f55\u6d3b\u8e8d\u9023\u63a5\u6216\u4ea4\u6613\u3002\u4ee5\u4e0b\u662f\u89e3\u6c7a\u6b64\u932f\u8aa4\u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"step-1-identify-active-connections-MGntjvDxRi\">\u6b65\u9a5f 1\uff1a\u8b58\u5225\u6d3b\u8e8d\u9023\u63a5<\/h3>\n<p>\u7b2c\u4e00\u6b65\u662f\u8b58\u5225\u4ecd\u5728\u4f7f\u7528\u5df2\u522a\u9664\u6578\u64da\u5eab\u7684\u6d3b\u8e8d\u9023\u63a5\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u67e5\u8a62\u4f86\u5217\u51fa\u6240\u6709\u6d3b\u8e8d\u7684\u9023\u63a5\uff1a<\/p>\n<pre><code>SELECT * FROM pg_stat_activity;<\/code><\/pre>\n<p>\u6b64\u67e5\u8a62\u5c07\u8fd4\u56de\u6240\u6709\u6d3b\u8e8d\u9023\u63a5\u7684\u6e05\u55ae\uff0c\u9023\u540c\u5176\u9032\u7a0b ID\u3001\u7528\u6236\u540d\u548c\u5176\u4ed6\u76f8\u95dc\u4fe1\u606f\u3002<\/p>\n<h3 id=\"step-2-terminate-active-connections-MGntjvDxRi\">\u6b65\u9a5f 2\uff1a\u7d42\u6b62\u6d3b\u8e8d\u9023\u63a5<\/h3>\n<p>\u4e00\u65e6\u8b58\u5225\u4e86\u6d3b\u8e8d\u9023\u63a5\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u547d\u4ee4\u4ee5\u7d42\u6b62\u5b83\u5011\uff1a<\/p>\n<pre><code>SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = 'database_name';<\/code><\/pre>\n<p>\u5c07 &#8216;database_name&#8217; \u66ff\u63db\u70ba\u5df2\u522a\u9664\u6578\u64da\u5eab\u7684\u540d\u7a31\u3002\u6b64\u547d\u4ee4\u5c07\u7d42\u6b62\u6240\u6709\u4ecd\u7136\u5f15\u7528\u5df2\u522a\u9664\u6578\u64da\u5eab\u7684\u6d3b\u8e8d\u9023\u63a5\u3002<\/p>\n<h3 id=\"step-3-verify-the-fix-MGntjvDxRi\">\u6b65\u9a5f 3\uff1a\u9a57\u8b49\u4fee\u5fa9<\/h3>\n<p>\u5728\u7d42\u6b62\u6d3b\u8e8d\u9023\u63a5\u5f8c\uff0c\u60a8\u53ef\u4ee5\u5617\u8a66\u518d\u6b21\u8a2a\u554f\u6578\u64da\u5eab\u4ee5\u6aa2\u67e5\u932f\u8aa4\u662f\u5426\u5df2\u88ab\u89e3\u6c7a\u3002\u5982\u679c\u932f\u8aa4\u4e0d\u518d\u767c\u751f\uff0c\u5247\u8868\u793a\u9023\u63a5\u5df2\u6210\u529f\u7d42\u6b62\uff0c\u60a8\u53ef\u4ee5\u7167\u5e38\u4f7f\u7528\u8a72\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"conclusion-MGntjvDxRi\">\u7d50\u8ad6<\/h2>\n<p>PostgreSQL \u4e2d\u7684 &#8220;57P04 &#8211; database_dropped&#8221; \u932f\u8aa4\u53ef\u4ee5\u901a\u904e\u8b58\u5225\u4e26\u7d42\u6b62\u4ecd\u7136\u5f15\u7528\u5df2\u522a\u9664\u6578\u64da\u5eab\u7684\u6d3b\u8e8d\u9023\u63a5\u6216\u4ea4\u6613\u4f86\u89e3\u6c7a\u3002\u9075\u5faa\u672c\u6587\u6240\u8ff0\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u78ba\u4fdd PostgreSQL \u4f3a\u670d\u5668\u7684\u9806\u5229\u904b\u884c\u3002<\/p>\n<h2 id=\"summary-MGntjvDxRi\">\u7e3d\u7d50<\/h2>\n<p>\u5982\u679c\u60a8\u5728 PostgreSQL \u4e2d\u9047\u5230 &#8220;57P04 &#8211; database_dropped&#8221; \u932f\u8aa4\uff0c\u9019\u610f\u5473\u8457\u67d0\u500b\u6578\u64da\u5eab\u5df2\u88ab\u522a\u9664\uff0c\u4f46\u4f9d\u7136\u6709\u6d3b\u8e8d\u7684\u9023\u63a5\u6216\u4ea4\u6613\u5728\u5f15\u7528\u8a72\u6578\u64da\u5eab\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u60a8\u9700\u8981\u5229\u7528\u6240\u63d0\u4f9b\u7684 SQL \u547d\u4ee4\u8b58\u5225\u4e26\u7d42\u6b62\u6d3b\u8e8d\u9023\u63a5\u3002\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc PostgreSQL \u548c VPS \u4e3b\u6a5f\u89e3\u6c7a\u65b9\u6848\u7684\u4fe1\u606f\uff0c\u8acb\u8a2a\u554f <a href=\"https:\/\/server.hk\">Server.HK<\/a>\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-21459","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21459","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=21459"}],"version-history":[{"count":2,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21459\/revisions"}],"predecessor-version":[{"id":24019,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21459\/revisions\/24019"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}