postgres只读用户不工作

时间:2015-03-13 16:49:34

标签: postgresql configuration permissions readonly postgresql-9.2

我有运行数据库的Postgresql 9.2,现在尝试创建一个只读用户。我按照这些描述:

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

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

基本上我做了以下事情:

jbossmanager=# CREATE USER jbcust  WITH ENCRYPTED PASSWORD '#######';
CREATE ROLE
jbossmanager=# GRANT USAGE ON SCHEMA jbossmanager to jbcust;
GRANT
jbossmanager=# ALTER DEFAULT PRIVILEGES IN SCHEMA jbossmanager GRANT SELECT ON TABLES TO jbcust;
ALTER DEFAULT PRIVILEGES
jbossmanager=# GRANT CONNECT ON DATABASE jbossmanager to jbcust;
GRANT
jbossmanager=# GRANT SELECT ON ALL SEQUENCES IN SCHEMA jbossmanager TO jbcust;
GRANT
jbossmanager=# GRANT SELECT ON ALL TABLES IN SCHEMA jbossmanager TO jbcust;
GRANT

在此之后" \ l"显示以下内容:

jbossmanager=# \l
                                     List of databases
 Name     |    Owner     | Encoding |   Collate   |    Ctype    |       Access privileges
--------------+--------------+----------+-------------+-------------+-------------------------------
 jbossmanager | jbossmanager | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/jbossmanager             +
          |              |          |             |             | jbossmanager=CTc/jbossmanager+
          |              |          |             |             | jbcust=c/jbossmanager

对我来说看起来不错,也是db / schema中的表列表lokks fine:

jbossmanager=# \dp+
                                                   Access privileges
    Schema    |             Name              |   Type   |         Access privileges         | Column access privileges
--------------+-------------------------------+----------+-----------------------------------+--------------------------
 jbossmanager | env_server_standalone_info    | table    | jbossmanager=arwdDxt/jbossmanager+|
              |                               |          | jbcust=r/jbossmanager             |

但现在当我将这个jbcust用户连接到数据库并尝试:

#psql -d jbossmanager -U jbcust -h 127.0.0.1
Password for user jbcust:
psql (9.2.4)
Type "help" for help.

jbossmanager=> \dp+
                          Access privileges
 Schema | Name | Type | Access privileges | Column access privileges
--------+------+------+-------------------+--------------------------
(0 rows)

我不知道出了什么问题或遗漏了什么。

非常感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

在与只读用户连接时,我没有看到任何架构的原因是该用户的默认架构未设置。

之后:

ALTER USER jbcust SET search_path = jbossmanager;

它完美无缺。