postgresql 使用一条语句对所有序列授予SELECT权限

nue99wik  于 2023-08-04  发布在  PostgreSQL
关注(0)|答案(6)|浏览(187)

如何使用一条语句将所有序列上的SELECT权限授予用户?Somthing like:

GRANT SELECT ON <ALL SEQUENCES???> TO myUser

字符串

nsc4cvqm

nsc4cvqm1#

在PostgreSQL 9.x中,您可以将一个模式中所有序列的权限授予一个角色。syntax

GRANT SELECT
ON ALL SEQUENCES IN SCHEMA schema_name
    TO role_name

字符串
角色可以是组角色或登录角色(用户名)。

1dkrff03

1dkrff032#

这在将来会非常有用:

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA schema_name TO your_user;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA schema_name TO your_user;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA schema_name TO your_user;

字符串

kuuvgm7e

kuuvgm7e3#

接受的答案对我不起作用9.1。下面的句子起作用了:

GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO user;

字符串

k7fdbhmy

k7fdbhmy4#

在Postgres 13中运行

GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO admin;

字符串

brc7rcf0

brc7rcf05#

对于Postgres版本低于9.0

psql -d DBNAME -qAt -c "SELECT 'GRANT SELECT ON ' || relname || ' TO USER;' FROM pg_statio_all_sequences WHERE schemaname = 'public'" | psql -d DBNAME

字符串
参考:http://gotochriswest.com/blog/2012/06/11/postgresql-granting-access-to-all-sequences/

vjhs03f7

vjhs03f76#

在Postgres 15+中,有预定义的角色,可以在设置数据库时更容易地授予有用的权限。
参见https://www.postgresql.org/docs/current/predefined-roles.html

GRANT pg_read_all_data TO USER;  
-- SELECT on all tables, views, and sequences. USAGE of all schemas.

GRANT pg_write_all_data TO USER;
-- INSERT, UPDATE, DELETE on all tables, views, and sequences. Usage of all schemas.

字符串

相关问题