我想有一个数据库的所有者,可以创建角色,并为该数据库的所有管理任务.由数据库所有者创建的所有角色必须对公共架构中的所有表具有SELECT权限,并且具有其自己的架构,在该架构中他们拥有所有权限. 所以我试着:

\connect postgres postgres;
create role db_owner with createrole password 'passwd' login;
create database db with owner db_owner;
\connect db db_owner;
grant select on all tables in schema public to public;
create table t (i int);
create role s1 with password 's1' login;
grant s1 to db_owner;
create schema authorization s1;

现在,当我try 以用户s1的身份登录select from public.t时,它被拒绝:

\connect db s1;
db=> select * from t;
ERROR:  permission denied for table t

如果grant select是由postgres发行的,它是有效的:

db=> \connect db postgres
You are now connected to database "db" as user "postgres".
db=# grant select on all tables in schema public to public;
GRANT
db=# \connect db s1
You are now connected to database "db" as user "s1".
db=> select * from t;
 i 
---
(0 rows)

为什么public架构中的数据库所有者不能是grant select?怎么做呢?

推荐答案

我认为问题在于授予权限只适用于现有项(调用GRANT时存在的所有公共表).您随后将创建测试表,该表继承 DEFAULT PRIVILEGES.

您可以编辑DEFAULT PRIVILEGES,如下所示:https://www.postgresql.org/docs/current/sql-alterdefaultprivileges.html

作为第一个测试,只需首先创建表,授予所有权限,try 使用db_owner帐户 Select 它,然后查看问题是否仍然存在.

Postgresql相关问答推荐

读取扩展坞合成中的UDP:IO/超时

Jsonb[]字段中的PostgreSQL否定&q;-0.0

如何删除Devtainer之前创建的PostgreSQL数据库?

执行准备好的语句不返回数据

错误:用户需要系统密码:postgres

我想优化查询SQL

gitlab在ubuntu上安装duplicate schema问题

PostgreSQL - 列出模式中的所有唯一约束

表或列名不能以数字开头?

升级到 OSX Mavericks 后修复 postgresql

使用 try/except 与 psycopg2 或with closing?

Postgresql SERIAL 的工作方式是否不同?

IntegrityError:postgres 从转储恢复后,所有具有 ForeignKey 的模型/字段的id列中的空值

为什么PostgresQL查询性能随时间下降,但在重建索引时恢复

是否可以在 PostgreSQL 中部分刷新materialized视图?

如何正确索引多对多关联表?

psql 致命角色不存在

如何为 postgres 编写 DELETE CASCADE?

Postgresql滚动删除旧行?

PostgreSQL - GROUP BY 子句或用于聚合函数