{"id":21379,"date":"2024-01-02T08:24:27","date_gmt":"2024-01-02T08:24:27","guid":{"rendered":"https:\/\/server.hk\/blog\/21379\/"},"modified":"2024-11-14T10:35:34","modified_gmt":"2024-11-14T02:35:34","slug":"how-to-fix-postgresql-error-code-38004-reading_sql_data_not_permitted","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21379\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38004 &#8211; reading_sql_data_not_permitted"},"content":{"rendered":"<h1 id=\"how-to-fix-postgresql-error-code-38004-reading_sql_data_not_permitted-IuhvAHbXFp\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38004 &#8211; reading_sql_data_not_permitted<\/h1>\n<p>PostgreSQL \u662f\u4e00\u6b3e\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u5f0f\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5f0f\u3002\u7136\u800c\uff0c\u8207\u6240\u6709\u8edf\u9ad4\u4e00\u6a23\uff0c\u5b83\u53ef\u80fd\u6703\u9047\u5230\u932f\u8aa4\uff0c\u5c0e\u81f4\u5176\u6b63\u5e38\u64cd\u4f5c\u53d7\u5230\u5e72\u64fe\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u4fbf\u662f PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38004 &#8211; reading_sql_data_not_permitted\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u6b64\u932f\u8aa4\u7684\u6210\u56e0\u4e26\u63d0\u4f9b\u9010\u6b65\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"understanding-the-postgresql-error-code-38004-reading_sql_data_not_permitted-IuhvAHbXFp\">\u7406\u89e3 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38004 &#8211; reading_sql_data_not_permitted<\/h2>\n<p>\u7576\u7528\u6236\u5617\u8a66\u5728\u6c92\u6709\u5fc5\u8981\u6b0a\u9650\u7684\u60c5\u6cc1\u4e0b\u8b80\u53d6 SQL \u6578\u64da\u6642\uff0c\u4fbf\u6703\u51fa\u73fe PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38004 &#8211; reading_sql_data_not_permitted\u3002\u901a\u5e38\u5728\u7528\u6236\u5617\u8a66\u8a2a\u554f\u8868\u683c\u6216\u57f7\u884c\u67e5\u8a62\u6642\u51fa\u73fe\u6b64\u932f\u8aa4\uff0c\u4f46\u4ed6\u5011\u7f3a\u4e4f\u76f8\u61c9\u7684\u6b0a\u9650\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>ERROR: permission denied for relation table_name<\/code><\/p>\n<p>\u6216<\/p>\n<p><code>ERROR: permission denied for schema schema_name<\/code><\/p>\n<p>\u9019\u4e9b\u932f\u8aa4\u8a0a\u606f\u8868\u660e\u7528\u6236\u6c92\u6709\u8db3\u5920\u7684\u6b0a\u9650\u5f9e\u6307\u5b9a\u7684\u8868\u683c\u6216\u6a21\u5f0f\u4e2d\u8b80\u53d6\u6578\u64da\u3002<\/p>\n<h2 id=\"causes-of-the-postgresql-error-code-38004-reading_sql_data_not_permitted-IuhvAHbXFp\">PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38004 &#8211; reading_sql_data_not_permitted \u7684\u6210\u56e0<\/h2>\n<p>\u5c0e\u81f4\u6b64\u932f\u8aa4\u7684\u53ef\u80fd\u539f\u56e0\u6709\u5e7e\u500b\uff1a<\/p>\n<ul>\n<li><strong>\u6b0a\u9650\u4e0d\u8db3\uff1a<\/strong> \u5617\u8a66\u8b80\u53d6\u6578\u64da\u7684\u7528\u6236\u6c92\u6709\u8a2a\u554f\u8868\u683c\u6216\u6a21\u5f0f\u6240\u9700\u7684\u6b0a\u9650\u3002<\/li>\n<li><strong>\u914d\u7f6e\u4e0d\u6b63\u78ba\uff1a<\/strong> PostgreSQL \u4f3a\u670d\u5668\u672a\u6b63\u78ba\u914d\u7f6e\u4ee5\u8ce6\u4e88\u7528\u6236\u6240\u9700\u7684\u6b0a\u9650\u3002<\/li>\n<li><strong>\u6b0a\u9650\u66f4\u6539\uff1a<\/strong> \u8868\u683c\u6216\u6a21\u5f0f\u7684\u6b0a\u9650\u5df2\u88ab\u4fee\u6539\uff0c\u7528\u6236\u4e0d\u518d\u5177\u6709\u5fc5\u8981\u7684\u6b0a\u9650\u3002<\/li>\n<\/ul>\n<h2 id=\"fixing-the-postgresql-error-code-38004-reading_sql_data_not_permitted-IuhvAHbXFp\">\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38004 &#8211; reading_sql_data_not_permitted<\/h2>\n<p>\u8981\u89e3\u6c7a PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38004 &#8211; reading_sql_data_not_permitted\uff0c\u8acb\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\uff1a<\/p>\n<h3 id=\"step-1-check-user-privileges-IuhvAHbXFp\">\u6b65\u9a5f\u4e00\uff1a\u6aa2\u67e5\u7528\u6236\u6b0a\u9650<\/h3>\n<p>\u78ba\u4fdd\u5617\u8a66\u8b80\u53d6\u6578\u64da\u7684\u7528\u6236\u5177\u6709\u5fc5\u8981\u7684\u6b0a\u9650\u3002\u60a8\u53ef\u4ee5\u57f7\u884c\u4ee5\u4e0b SQL \u67e5\u8a62\u4f86\u505a\u5230\u9019\u4e00\u9ede\uff1a<\/p>\n<pre><code>GRANT SELECT ON table_name TO username;<\/code><\/pre>\n<p>\u5c07<code>table_name<\/code>\u66ff\u63db\u70ba\u60a8\u5e0c\u671b\u6388\u4e88\u8a2a\u554f\u6b0a\u9650\u7684\u8868\u683c\u540d\u7a31\uff0c\u5c07<code>username<\/code>\u66ff\u63db\u70ba\u9700\u8981\u8a2a\u554f\u6b0a\u9650\u7684\u7528\u6236\u540d\u7a31\u3002<\/p>\n<h3 id=\"step-2-verify-schema-permissions-IuhvAHbXFp\">\u6b65\u9a5f\u4e8c\uff1a\u9a57\u8b49\u6a21\u5f0f\u6b0a\u9650<\/h3>\n<p>\u5982\u679c\u932f\u8aa4\u8a0a\u606f\u6307\u793a\u6a21\u5f0f\u6b0a\u9650\u554f\u984c\uff0c\u60a8\u9700\u8981\u5411\u7528\u6236\u6388\u4e88\u6240\u9700\u7684\u6b0a\u9650\u3002\u57f7\u884c\u4ee5\u4e0b SQL \u67e5\u8a62\uff1a<\/p>\n<pre><code>GRANT USAGE ON SCHEMA schema_name TO username;<\/code><\/pre>\n<p>\u5c07<code>schema_name<\/code>\u66ff\u63db\u70ba\u60a8\u5e0c\u671b\u6388\u4e88\u8a2a\u554f\u6b0a\u9650\u7684\u6a21\u5f0f\u540d\u7a31\uff0c\u5c07<code>username<\/code>\u66ff\u63db\u70ba\u9700\u8981\u8a2a\u554f\u6b0a\u9650\u7684\u7528\u6236\u540d\u7a31\u3002<\/p>\n<h3 id=\"step-3-reload-configuration-IuhvAHbXFp\">\u6b65\u9a5f\u4e09\uff1a\u91cd\u65b0\u52a0\u8f09\u914d\u7f6e<\/h3>\n<p>\u5982\u679c\u4e0a\u8ff0\u6b65\u9a5f\u7121\u6cd5\u89e3\u6c7a\u554f\u984c\uff0c\u8acb\u5617\u8a66\u91cd\u65b0\u52a0\u8f09 PostgreSQL \u914d\u7f6e\u3002\u53ef\u4ee5\u901a\u904e\u91cd\u65b0\u555f\u52d5 PostgreSQL \u670d\u52d9\u6216\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b8c\u6210\uff1a<\/p>\n<pre><code>SELECT pg_reload_conf();<\/code><\/pre>\n<p>\u6b64\u547d\u4ee4\u5c07\u91cd\u65b0\u52a0\u8f09\u914d\u7f6e\u6587\u4ef6\u4e26\u61c9\u7528\u53ef\u80fd\u5df2\u505a\u7684\u4efb\u4f55\u66f4\u6539\u3002<\/p>\n<h2 id=\"summary-IuhvAHbXFp\">\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u800c\u8a00\u4e4b\uff0c\u7576\u7528\u6236\u8a66\u5716\u5728\u6c92\u6709\u5fc5\u8981\u6b0a\u9650\u7684\u60c5\u6cc1\u4e0b\u8b80\u53d6 SQL \u6578\u64da\u6642\uff0c\u4fbf\u6703\u51fa\u73fe PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38004 &#8211; reading_sql_data_not_permitted\u3002\u8981\u89e3\u6c7a\u6b64\u932f\u8aa4\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u7528\u6236\u64c1\u6709\u9069\u7576\u7684\u6b0a\u9650\u4e26\u4e14 PostgreSQL \u4f3a\u670d\u5668\u5df2\u6b63\u78ba\u914d\u7f6e\u3002\u901a\u904e\u672c\u6587\u4e2d\u6982\u8ff0\u7684\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u89e3\u6c7a\u6b64\u932f\u8aa4\u4e26\u91cd\u65b0\u7372\u5f97\u5c0d\u6240\u9700\u6578\u64da\u7684\u8a2a\u554f\u6b0a\u9650\u3002<\/p>\n<p>\u5982\u9700\u66f4\u591a\u6709\u95dc VPS \u8a17\u7ba1\u4ee5\u53ca\u5b83\u5c0d\u60a8\u696d\u52d9\u7684\u76ca\u8655\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-21379","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21379","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=21379"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21379\/revisions"}],"predecessor-version":[{"id":24115,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21379\/revisions\/24115"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}