【发布时间】:2020-11-29 10:21:26
【问题描述】:
(select version() PostgreSQL 11.6, Visual C++ build 1800, 64-bit编译)
我创建了一个新用户:
create user bob with password 'some_password_string';
我在一个名为“GoogleData”的数据库中:
grant all privileges on GoogleData to bob;
SQL Error [42P01]: ERROR: relation "googledata" does not exist
我可以通过指定 schema.table 将 bob 添加到 GoogleData 中的特定表中,例如
grant all privileges on reporting.ecom_dashboard to bob;
这行得通,只是表太多,无法逐一授予访问权限。我也无法授予公众访问权限。
试过了:
grant all privileges on public to bob;
SQL Error [42P01]: ERROR: relation "public" does not exist
尝试像这样迭代特定架构:
grant all privileges on reporting.* to bob;
SQL Error [42601]: ERROR: syntax error at or near "to"
Position: 46
- 如何在数据库级别向 Bob 授予所有权限?当我尝试时出现错误“错误:关系“googledata”不存在”(其中 googledata 是有问题的数据库)
- 鉴于我似乎无法在 db 级别授予访问权限,如何在架构级别授予 bob 权限
grant all privileges on schema_name.* to bob;?
【问题讨论】:
-
Database-level grants need to explicitly use the
DATABASEkeyword:grant all privileges on database GoogleData to bob;。如果您不指定对象的类型,它会退回到TABLE(该关键字是可选的)并导致您收到错误。 -
@Bergi 感谢您的建议。我确实尝试过:
select current_database(); returns GoogleData。然后grant all privileges on database GoogleData to bob;导致错误SQL Error [3D000]: ERROR: database "googledata" does not exist -
如果您的数据库名称中确实包含大写字母,则需要使用
database "GoogleData"。
标签: postgresql privileges grant