暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PostgreSQL 16:进一步减少需要超级用户的任务

原创 小小亮 2022-12-15
525

在之前的一篇文章中,我们已经看到从 PostgreSQL 16 开始,可以将vacuum和analyze操作授予非超级用户的用户。进一步减少需要超级用户权限的维护任务的工作仍在进行中。今天提交了另一个补丁,为维护操作带来了更多授权。

还有一个简单的设置来演示已经完成的工作:

postgres=# select version();
                                               version                                                
------------------------------------------------------------------------------------------------------
 PostgreSQL 16devel on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
(1 row)
 
postgres=# create user u with password 'u' login;
CREATE ROLE
postgres=# create user v with password 'v' login;
CREATE ROLE
postgres=# create schema su authorization u;
CREATE SCHEMA
postgres=# \c postgres u
You are now connected to database "postgres" as user "u".
postgres=> create table su.t ( a int, b text );
postgres=> create unique index i on su.t(a);
CREATE INDEX
postgres=> create materialized view su.mv as select * from su.t;
SELECT 0

两个用户,一个具有包含表、唯一索引和物化视图的模式。我们已经看到我们可以将 vacuum 和 analyze 对象授予另一个用户:

postgres=# grant analyze on su.t to v;
ERROR:  syntax error at or near "analyze"

这不再起作用了。现在不再为维护操作授予单独的权限,而是将它们组合在一个权限下:

postgres=# grant maintain on su.t to v;
GRANT
postgres=# grant maintain on su.mv to v;
GRANT
postgres=# grant usage on schema su to v;
GRANT

维护特权包括以下特权:

  • VACUUM
  • ANALYZE
  • REINDEX
  • REFRESH MATERIALIZED VIEW
  • CLUSTER
  • LOCK TABLE

拥有该特权,所有这些操作都被委托:

postgres=> analyze su.t;
ANALYZE
postgres=> refresh materialized view su.mv;
REFRESH MATERIALIZED VIEW
postgres=> reindex index su.i;
REINDEX

还添加了一个新角色,默认情况下授予所有这些操作:

postgres=# \c postgres u
You are now connected to database "postgres" as user "u".
postgres=> create table su.x ( a int );
CREATE TABLE
postgres=> \c postgres postgres
You are now connected to database "postgres" as user "postgres".
postgres=# grant pg_maintain to v;
GRANT ROLE
postgres=# \c postgres v
You are now connected to database "postgres" as user "v".
postgres=> analyze su.x;
ANALYZE
postgres=>

这很好,因为它进一步减少了需要超级用户权限的任务。

原文标题:PostgreSQL 16: Further reducing tasks that require superuser
原文作者:Daniel Westermann
原文链接:https://www.dbi-services.com/blog/postgresql-16-further-reducing-tasks-that-require-superuser/

最后修改时间:2022-12-15 11:18:42
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论