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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7758533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:08:07  来源:igfitidea点击:

postgresql database owner can't access database - "No relations found."

postgresqluser-permissions

提问by AndreDurao

I've got an user: user_x that owns a database on postgresql and does not have any ROLE attribute like (CREATE_DB, SUPERUSER,...)

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

This user_x can access the whole DB, create tables (on his database), select, insert and update data.

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

I've got this list of databases:

我有这个数据库列表:

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)

and the following roles:

以及以下角色:

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

 ...

All right, till I dump data and restore it on another postgresql server.

好的,直到我转储数据并在另一个 postgresql 服务器上恢复它。

After import the data with on another server (with same database name and user) and logged on psql the \dcommand reply with: "No relations found."

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

So I added SUPERUSERrole to user_x on the imported database server and tad? user_x can see the relations and data again.

所以我在导入的数据库服务器上向 user_x添加了SUPERUSER角色?user_x 可以再次看到关系和数据。

But user_x don't need to have SUPERUSER privilege to access this database.

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

What's wrong with this imported dump? Does anyone now how to solve this?

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

回答by A.H.

Perhaps the schema permissions for the publicschema got mangled. What is the output of \dn+on both sites?

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

The output should look like this:

输出应如下所示:

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

If the =UC/postgrespart is missing, you can restore it with

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

grant all on schema public to public;