【问题标题】:GRANT SELECT Simply not workingGRANT SELECT 根本不工作
【发布时间】:2013-11-18 00:55:26
【问题描述】:

我需要允许SELECT 访问数据库的用户。我已经按照我发现分散在 SO 各处的所有说明进行操作,但我什么也做不了。

我已经尝试了以下所有链接的所有建议解决方案:

How do you create a read-only user in PostgreSQL?

ERROR: permission denied for relation tablename on Postgres while trying a SELECT as a readonly user

Permission denied for relation

...以及更多对 PSQL 文档、博客和用户组的引用。什么都没有。

以下是我最近作为 postgres 用户用来授予权限的命令:

postgres@dev:~$ psql
psql (9.1.9)
Type "help" for help.

postgres=# grant usage on SCHEMA public to proton_read;
GRANT
postgres=# grant select on all tables in schema public to proton_read;
GRANT
postgres=# alter default privileges in schema public grant select on tables to proton_read;
ALTER DEFAULT PRIVILEGES

以下是作为只读用户使用的命令:

proton_read@dev:~$ psql proton
psql (9.1.9)
Type "help" for help.

proton=> select * from leads_lead limit 1;
ERROR:  permission denied for relation leads_lead

这是踢球者,我曾经有过这个工作。我有一个示例数据库转储,用于向业务同事教授基本 SQL。我们涵盖了简单的命令,例如SELECTORDER BYLIMITJOIN。我有一个旧转储,并且能够授予只读访问权限。我删除了数据库并使用更新版本的数据库执行了 pg_restore,现在我无法重新授予 SELECT 访问权限。

任何帮助将不胜感激。

【问题讨论】:

    标签: sql postgresql


    【解决方案1】:

    在 PostgreSQL 中,每个连接都指向一个特定的数据库,并且您运行的几乎所有操作都只在该数据库中有效。 (一个例外是用户/角色本身的创建对于整个“集群”是全局的,即运行 Postgres 服务器。)

    在您显示的psql 命令中,您第一次连接时没有指定数据库 (psql),它将您连接到以当前系统用户命名的数据库,即 postgres。这显示在psql 提示符的开头:postgres=## 表明您以超级用户身份连接)。

    因此,您的GRANT 语句只会更改此数据库。

    您的第二个示例使用正确的命令连接到特定数据库psql proton,您可以看到提示反映了这一点:proton=>(用> 替换了#,因为您不是以超级用户身份连接)。

    所以您需要做的就是以您的postgres 用户身份运行psql proton,并在该特定数据库上以超级用户身份运行您的GRANT 语句。您的提示将显示为proton=#,以表明您来对了地方。

    【讨论】:

      猜你喜欢
      • 2017-12-17
      • 1970-01-01
      • 1970-01-01
      • 2019-11-26
      • 2016-10-29
      • 2018-02-10
      • 2017-03-19
      • 2013-09-20
      • 2013-11-08
      相关资源
      最近更新 更多