在Postgres中,我在一个名为testing的db里创build了下面的表格:
CREATE TABLE category_google_taxonomy ( category_id integer references category ON UPDATE CASCADE ON DELETE CASCADE, google_taxonomy_id integer references google_taxonomy ON UPDATE CASCADE ON DELETE CASCADE );
当我尝试填充表格时:
INSERT INTO category_google_taxonomy (category_id, google_taxonomy_id) VALUES (1,7), (2,12);
我得到以下错误:
ERROR: permission denied for schema public LINE 1: SELECT 1 FROM ONLY "public"."category" x WHERE "category_id"... ^ QUERY: SELECT 1 FROM ONLY "public"."category" x WHERE "category_id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x
我读了一下,并最终授予ALL PRIVILEGES出于愤怒,但它仍然不起作用:
testing=# GRANT ALL PRIVILEGES ON public.category TO testing; GRANT testing=# \dp category_google_taxonomy Access privileges Schema | Name | Type | Access privileges | Column access privileges --------+--------------------------+-------+-------------------------+-------------------------- public | category_google_taxonomy | table | testing=arwdDxt/testing | : super=arwdDxt/testing testing=# \dp category Access privileges Schema | Name | Type | Access privileges | Column access privileges --------+----------+-------+------------------------+-------------------------- public | category | table | testing=arwdDxt/super | category_id: : testing=arwx/super (1 row)
在@丹尼尔的build议,我试图GRANT USAGE ON schema public TO super;用GRANT USAGE ON schema public TO super; ,现在当我运行INSERT命令时,我得到:
ERROR: permission denied for relation category CONTEXT: SQL statement "SELECT 1 FROM ONLY "public"."category" x WHERE "category_id" OPERATOR(pg_catalog.=) $1 FOR SHARE OF x"
这里是\d的相关部分:
public | category | table | super public | category_google_taxonomy | table | testing
假设用户名正在testing ,你可能想要做的:
GRANT ALL ON schema public TO testing;
关于授予ALL PRIVILEGES注意事项:您不要说这个GRANT命令应用了什么。 假设它是ON DATABASE... ,它只是意味着CONNECT , CREATE和TEMP权限,没有关于公共模式或任何其他包含的对象,这就是为什么它“不起作用”。
编辑:当这是不够的
如果外键引用的表不属于testing所有者,则它们的所有者还需要在模式上拥有USAGE特权才能查找引用的表。
从\dp的结果( \d的结果肯定会告诉我们)的结果中并不明显,但是如果category属于super拥有且该用户对模式没有特权,则需要将其赋值为:
GRANT USAGE ON schema public TO super;
我设法通过这样做来解决这个问题:
ALTER TABLE category OWNER TO testing;
之后INSERT进行顺利。 我担心我可能通过把所有者从超级变成另外的东西来破坏其他的东西,但是还有待观察。