{"id":21376,"date":"2024-01-02T08:21:24","date_gmt":"2024-01-02T08:21:24","guid":{"rendered":"https:\/\/server.hk\/blog\/21376\/"},"modified":"2024-11-14T10:35:38","modified_gmt":"2024-11-14T02:35:38","slug":"how-to-fix-postgresql-error-code-38001-containing_sql_not_permitted","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21376\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38001 &#8211; containing_sql_not_permitted"},"content":{"rendered":"<h1 id=\"how-to-fix-postgresql-error-code-38001-containing_sql_not_permitted-URGsmCJTWW\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38001 &#8211; containing_sql_not_permitted<\/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\u61c9\u7528\u65bc\u5168\u7403\u958b\u767c\u4eba\u54e1\u548c\u4f01\u696d\u3002\u7136\u800c\uff0c\u50cf\u4efb\u4f55\u8edf\u4ef6\u4e00\u6a23\uff0cPostgreSQL \u4e5f\u6703\u9047\u5230\u4e00\u4e9b\u53ef\u80fd\u5f71\u97ff\u6b63\u5e38\u904b\u884c\u7684\u932f\u8aa4\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u5c31\u662f PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38001 &#8211; containing_sql_not_permitted\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u6b64\u932f\u8aa4\u7684\u6210\u56e0\u4e26\u63d0\u4f9b\u9010\u6b65\u89e3\u6c7a\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"understanding-postgresql-error-code-38001-containing_sql_not_permitted-URGsmCJTWW\">\u7406\u89e3 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38001 &#8211; containing_sql_not_permitted<\/h2>\n<p>PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38001 &#8211; containing_sql_not_permitted \u767c\u751f\u5728\u4f7f\u7528\u8005\u5617\u8a66\u57f7\u884c\u67d0\u4e9b\u7576\u524d\u4e0a\u4e0b\u6587\u4e2d\u4e0d\u5141\u8a31\u7684 SQL \u8a9e\u53e5\u6642\u3002\u6b64\u932f\u8aa4\u901a\u5e38\u51fa\u73fe\u5728\u7528\u6236\u5617\u8a66\u57f7\u884c\u88ab\u8cc7\u6599\u5eab\u7ba1\u7406\u54e1\u6216\u8cc7\u6599\u5eab\u81ea\u8eab\u9650\u5236\u7684 SQL \u8a9e\u53e5\u6642\u3002<\/p>\n<p>\u7576\u6b64\u932f\u8aa4\u767c\u751f\u6642\uff0cPostgreSQL \u5c07\u986f\u793a\u985e\u4f3c\u5982\u4e0b\u7684\u932f\u8aa4\u8a0a\u606f\uff1a<\/p>\n<p><code>ERROR:  permission denied for language c<br \/>\nHINT:  Use GRANT to give permission.<\/code><\/p>\n<p>\u6b64\u932f\u8aa4\u8a0a\u606f\u8868\u793a\u4f7f\u7528\u8005\u6c92\u6709\u57f7\u884c\u5305\u542b\u7279\u5b9a\u8a9e\u8a00\u7684 SQL \u8a9e\u53e5\uff08\u4f8b\u5982 &#8220;c&#8221; \u8a9e\u8a00\uff09\u7684\u5fc5\u8981\u8a31\u53ef\u3002<\/p>\n<h2 id=\"fixing-postgresql-error-code-38001-containing_sql_not_permitted-URGsmCJTWW\">\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38001 &#8211; containing_sql_not_permitted<\/h2>\n<p>\u8981\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38001 &#8211; containing_sql_not_permitted\uff0c\u8acb\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\uff1a<\/p>\n<h3 id=\"step-1-identify-the-restricted-sql-statement-URGsmCJTWW\">\u6b65\u9a5f 1\uff1a\u8b58\u5225\u88ab\u9650\u5236\u7684 SQL \u8a9e\u53e5<\/h3>\n<p>\u9996\u5148\u8981\u8b58\u5225\u5c0e\u81f4\u932f\u8aa4\u7684 SQL \u8a9e\u53e5\u3002\u67e5\u770b PostgreSQL \u986f\u793a\u7684\u932f\u8aa4\u8a0a\u606f\uff0c\u78ba\u5b9a\u54ea\u500b SQL \u8a9e\u53e5\u88ab\u62d2\u7d55\u57f7\u884c\u3002\u5728\u4e0a\u9762\u7684\u932f\u8aa4\u8a0a\u606f\u4e2d\uff0c\u88ab\u9650\u5236\u7684 SQL \u8a9e\u53e5\u662f\u4f7f\u7528 &#8220;c&#8221; \u8a9e\u8a00\u64b0\u5beb\u7684\u3002<\/p>\n<h3 id=\"step-2-grant-permission-URGsmCJTWW\">\u6b65\u9a5f 2\uff1a\u6388\u4e88\u8a31\u53ef<\/h3>\n<p>\u8b58\u5225\u51fa\u88ab\u9650\u5236\u7684 SQL \u8a9e\u53e5\u5f8c\uff0c\u60a8\u9700\u8981\u6388\u4e88\u4f7f\u7528\u8005\u57f7\u884c\u8a72\u8a9e\u53e5\u7684\u8a31\u53ef\u3002\u70ba\u6b64\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528 PostgreSQL \u7684 GRANT \u8a9e\u53e5\u3002GRANT \u8a9e\u53e5\u5141\u8a31\u60a8\u5411\u67d0\u500b\u4f7f\u7528\u8005\u6216\u4f7f\u7528\u8005\u7fa4\u7d44\u6388\u4e88\u7279\u5b9a\u8a31\u53ef\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u6388\u4e88\u4f7f\u7528\u8005\u57f7\u884c &#8220;c&#8221; \u8a9e\u8a00 SQL \u8a9e\u53e5\u7684\u8a31\u53ef\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6307\u4ee4\uff1a<\/p>\n<p><code>GRANT USAGE ON LANGUAGE c TO username;<\/code><\/p>\n<p>\u5c07 &#8220;username&#8221; \u66ff\u63db\u70ba\u9700\u8981\u8a31\u53ef\u4ee5\u57f7\u884c\u88ab\u9650\u5236 SQL \u8a9e\u53e5\u7684\u5be6\u969b\u4f7f\u7528\u8005\u540d\u7a31\u3002<\/p>\n<h3 id=\"step-3-test-the-sql-statement-URGsmCJTWW\">\u6b65\u9a5f 3\uff1a\u6e2c\u8a66 SQL \u8a9e\u53e5<\/h3>\n<p>\u6388\u4e88\u5fc5\u8981\u7684\u8a31\u53ef\u5f8c\uff0c\u8acb\u518d\u6b21\u6e2c\u8a66\u8a72 SQL \u8a9e\u53e5\uff0c\u78ba\u4fdd\u932f\u8aa4\u5df2\u7d93\u89e3\u6c7a\u3002\u57f7\u884c\u8a72 SQL \u8a9e\u53e5\uff0c\u4e26\u9a57\u8b49\u662f\u5426\u4e0d\u518d\u9047\u5230 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38001 &#8211; containing_sql_not_permitted\u3002<\/p>\n<h2 id=\"summary-URGsmCJTWW\">\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u7684\u4f86\u8aaa\uff0cPostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38001 &#8211; containing_sql_not_permitted \u662f\u7576\u4f7f\u7528\u8005\u5617\u8a66\u57f7\u884c\u7576\u524d\u4e0a\u4e0b\u6587\u4e2d\u4e0d\u5141\u8a31\u7684 SQL \u8a9e\u53e5\u6642\u767c\u751f\u7684\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u60a8\u9700\u8981\u8b58\u5225\u88ab\u9650\u5236\u7684 SQL \u8a9e\u53e5\uff0c\u901a\u904e GRANT \u8a9e\u53e5\u6388\u4e88\u4f7f\u7528\u8005\u8a31\u53ef\uff0c\u7136\u5f8c\u518d\u6b21\u6e2c\u8a66\u8a72 SQL \u8a9e\u53e5\uff0c\u78ba\u4fdd\u932f\u8aa4\u5df2\u89e3\u6c7a\u3002<\/p>\n<p>\u5982\u679c\u60a8\u9047\u5230 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a38001 &#8211; containing_sql_not_permitted \u6216\u5176\u4ed6\u8207 PostgreSQL \u76f8\u95dc\u7684\u554f\u984c\uff0c\u8acb\u8003\u616e\u4f7f\u7528\u53ef\u9760\u7684 VPS \u8a17\u7ba1\u670d\u52d9\u4f9b\u61c9\u5546\uff0c\u4f8b\u5982 <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u4ed6\u5011\u5728 PostgreSQL \u548c VPS \u8a17\u7ba1\u65b9\u9762\u64c1\u6709\u8c50\u5bcc\u7684\u5c08\u696d\u77e5\u8b58\uff0c\u80fd\u5e6b\u52a9\u60a8\u89e3\u6c7a\u4efb\u4f55\u8207\u6578\u64da\u5eab\u76f8\u95dc\u7684\u554f\u984c\uff0c\u4e26\u63d0\u4f9b\u53ef\u9760\u4e14\u5b89\u5168\u7684\u8a17\u7ba1\u74b0\u5883\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-21376","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21376","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=21376"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21376\/revisions"}],"predecessor-version":[{"id":24118,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21376\/revisions\/24118"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}