postgresql 数据库所有者无法访问数据库 - “未找到关系。”

问题描述 投票:0回答:3

我有一个用户: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角色,这样user_x就可以再次看到关系和数据了。

但是 user_x 不需要具有 SUPERUSER 权限来访问该数据库。

这个导入的转储有什么问题? 现在有人怎么解决这个问题吗?

postgresql user-permissions
3个回答
78
投票

也许

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;

1
投票

没有找到任何关系。

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

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.

0
投票

我使用的是psql 16.0,服务器15.1。我在 DataGrip 中重命名了一个连接,现在我看不到任何表(即使在恢复到以前的名称之后)。知道如何显示表格吗?

postgres=# \dn+
                                       List of schemas
  Name  |       Owner       |           Access privileges            |      Description       
--------+-------------------+----------------------------------------+------------------------
 public | pg_database_owner | pg_database_owner=UC/pg_database_owner+| standard public schema
        |                   | =U/pg_database_owner                   | 
© www.soinside.com 2019 - 2024. All rights reserved.