postgresql 数据库所有者无法访问数据库 - “未找到关系。”
我有一个用户: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 权限即可访问该数据库。
这个导入的转储有什么问题? 现在有人如何解决这个问题吗?
I've got an user: user_x that owns a database on postgresql and does not have any ROLE attribute like (CREATE_DB, SUPERUSER,...)
This user_x can access the whole DB, create tables (on his database), select, insert and update data.
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.
After import the data with on another server (with same database name and user) and logged on psql the \d command reply with: "No relations found."
So I added SUPERUSER role to user_x on the imported database server and tadã user_x can see the relations and data again.
But user_x don't need to have SUPERUSER privilege to access this database.
What's wrong with this imported dump?
Does anyone now how to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许
public
模式的模式权限被破坏了。两个站点上\dn+
的输出是什么?输出应如下所示:
如果
=UC/postgres
部分丢失,您可以使用以下命令恢复它Perhaps the schema permissions for the
public
schema got mangled. What is the output of\dn+
on both sites?The output should look like this:
If the
=UC/postgres
part is missing, you can restore it with没找到什么关系。
如果您的数据库没有表,您也会得到这个。
Did not find any relations.
You will also get this if your database has no tables.
我正在使用 psql 16.0,服务器 15.1。我在 DataGrip 中重命名了一个连接,现在我看不到任何表(即使在恢复到以前的名称之后)。知道如何显示表格吗?
I am using psql 16.0, server 15.1. I renamed a connection in DataGrip and now I can't see any of the tables (even after reverting back to the previous name). Any idea how can I show the tables?