PostgreSQL中新关系的权限如何工作?
步骤:
CREATE DATABASE test;
\c test
CREATE USER site NOCREATEDB NOINHERIT;
GRANT SELECT, UPDATE, INSERT, DELETE, TRUNCATE, REFERENCES ON ALL TABLES IN SCHEMA public TO site;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO site;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT, UPDATE, INSERT, DELETE, TRUNCATE, REFERENCES ON TABLES TO site;
CREATE USER migration NOCREATEDB NOINHERIT;
GRANT ALL PRIVILEGES ON DATABASE test TO migration;
CREATE TABLE test (id serial);
SELECT * FROM test;
ERROR: permission denied for relation test
但是如果我从用户 postgres 创建表格,那么一切正常!
为什么默认权限在这种情况下不起作用?如何为用户站点的新表授予权限?
答案 0 :(得分:1)
ALTER DEFAULT PRIVILEGES
仅影响FOR ROLE
子句中指定的用户创建的对象。如果省略此子句,它仅适用于运行命令的用户(在您的情况下, postgres )。
您想要ALTER DEFAULT PRIVILEGES FOR USER migration ...
。