32

我有一个用户: user_x 在 postgresql 上拥有一个数据库,并且没有任何 ROLE 属性,例如 (CREATE_DB, SUPERUSER,...)

这个 user_x 可以访问整个数据库、创建表(在他的数据库上)、选择、插入和更新数据。

我有这个数据库列表:

mydatabase=> \l
                                     List of databases
          Name           |  Owner   | Encoding  | Collation | Ctype |   Access privileges   
-------------------------+----------+-----------+-----------+-------+-----------------------
 postgres                | postgres | SQL_ASCII | C         | C     | 
 mydatabase              | user_x   | UTF8      | C         | C     | 
 template0               | postgres | SQL_ASCII | C         | C     | =c/postgres          +
                         |          |           |           |       | postgres=CTc/postgres
 template1               | postgres | SQL_ASCII | C         | C     | =c/postgres          +
                         |          |           |           |       | postgres=CTc/postgres
 whoami                  | postgres | SQL_ASCII | C         | C     | 
(6 rows)

以及以下角色:

mydatabase=> \du
                       List of roles
 Role name |            Attributes             | Member of 
-----------+-----------------------------------+-----------
 postgres  | Superuser, Create role, Create DB | {}
 user_x    |                                   | {}

mydatabase=> \d
                        List of relations
 Schema |               Name                |   Type   |  Owner   
--------+-----------------------------------+----------+----------
 public | addresses                         | table    | user_x
 public | addresses_id_seq                  | sequence | user_x
 public | assignments                       | table    | user_x
 public | assignments_id_seq                | sequence | user_x

 ...

好吧,直到我转储数据并将其恢复到另一个 postgresql 服务器上。

在另一台服务器(具有相同的数据库名称和用户)上导入数据并登录 psql 后,\d命令回复:“未找到关系”。

所以我在导入的数据库服务器上为 user_x添加了SUPERUSER角色,然后用户_x 可以再次看到关系和数据。

但是 user_x 不需要拥有 SUPERUSER 权限来访问这个数据库。

这个导入的转储有什么问题?有谁现在如何解决这个问题?

4

2 回答 2

77

也许架构的架构权限public被破坏了。\dn+两个站点的输出是什么?

输出应如下所示:

                          List of schemas
  Name  |  Owner   |  Access privileges   |      Description       
--------+----------+----------------------+------------------------
 public | postgres | postgres=UC/postgres | standard public schema
                   : =UC/postgres           
(1 row)

如果=UC/postgres零件丢失,您可以使用

grant all on schema public to public;
于 2011-10-13T18:40:00.037 回答
0

没有发现任何关系。

如果您的数据库没有表,您也会得到这个。

iripmu=# select * from testtable;
 id |    Name
----+------------
  1 | Bear
  2 | Tiger
(2 rows)

iripmu=# drop table if exists testtable;
DROP TABLE
iripmu=# \dt
Did not find any relations.
于 2022-02-21T09:39:14.710 回答