如何将PostgreSQL“全部放在所有表格上”应用于新表?

如何将PostgreSQL“全部放在所有表格上”应用于新表?,第1张

概述正如在 GRANT SELECT to all tables in postgresql的问题中所讨论的那样,从PG 9.0开始,您可以使用如下命令将所有现有表的权限批量授予用户u: GRANT ALL ON ALL TABLES IN SCHEMA public TO u; 以u身份登录,您现在可以对预先存在的表a执行此 *** 作: SELECT * FROM a; 但是如果你现在创建表b并执行: S 正如在 GRANT SELECT to all tables in postgresql的问题中所讨论的那样,从PG 9.0开始,您可以使用如下命令将所有现有表的权限批量授予用户u:
GRANT ALL ON ALL tableS IN SCHEMA public TO u;

以u身份登录,您现在可以对预先存在的表a执行此 *** 作:

SELECT * FROM a;

但是如果你现在创建表b并执行:

SELECT * FROM b;

你得到:

ERROR: permission denIEd for relation bsql state: 42501

这可以通过重新执行来解决

GRANT ALL ON ALL tableS IN SCHEMA public TO u;

但是每次创建表格之后必须记住这样做是个问题.

有没有办法让Postgresql自动将这些全局授权应用于新创建的表?

〜提前谢谢
〜肯

一个可行的解决方案是改变u用户的默认权限:

例如:

alter default privileges in schema public grant all on tables to u;alter default privileges in schema public grant all on sequences to u;

Description@H_419_37@

ALTER DEFAulT PRIVILEGES allows you to set the privileges that will
be applIEd to objects created in the future. (It does not affect
privileges assigned to already-existing objects.) Currently,only the
privileges for tables (including vIEws),sequences,and functions can
be altered.

You can change default privileges only for objects that will be
created by yourself or by roles that you are a member of. The
privileges can be set globally (i.e.,for all objects created in the
current database),or just for objects created in specifIEd schemas.
Default privileges that are specifIEd per-schema are added to whatever
the global default privileges are for the particular object type.

As explained under GRANT,the default privileges for any object type
normally grant all grantable permissions to the object owner,and may
grant some privileges to PUBliC as well. However,this behavior can
be changed by altering the global default privileges with ALTER DEFAulT PRIVILEGES.

见:ALTER DEFAULT PRIVILEGES

总结

以上是内存溢出为你收集整理的如何将PostgreSQL“全部放在所有表格上”应用于新表?全部内容,希望文章能够帮你解决如何将PostgreSQL“全部放在所有表格上”应用于新表?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1168735.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-01
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存