Postgres用户无法从公共表中选择

时间:2019-06-28 08:10:00

标签: postgresql schema public rights

您好,我的Postgresql数据库中有一个用户 \ dt为用户输出:

 test=> \dt
                  List of relations
 Schema |           Name           | Type  |  Owner
--------+--------------------------+-------+----------
 public | code                     | table | postgres
 public | code_to_indicator        | table | postgres
 public | indicator                | table | postgres

如您所见,表的所有者是postgres 但是,如果为postgres用户运行\ dt命令,则会显示:

postgres=# \dt
Did not find any relations.

怎么可能?另外,如果我尝试由postgres用户选择,也会失败:

postgres=# select * from indicator;
ERROR:  relation "indicator" does not exist
LINE 1: select * from indicator;

有人可以帮助吗?直到今天一切都很好,出了点问题我什至都不知道。 PostgreSQL版本:11.4

2 个答案:

答案 0 :(得分:0)

当表名不合格时,在public或任何模式中查看表的能力取决于search_path设置。

如果您没有永久修改search_path,请在会话中发出RESET search_path;,然后重试。

如果search_path不是您直接修改的,该如何修改?播放由pg_dump获得的SQL文件,具有从搜索路径中删除public的效果,这似乎就是这个问题的答案。

如果通过ALTER USER postgres SET search_path TO ...或每个数据库或全局进行了永久性修改,则需要使用等效的ALTER命令撤消该操作。

有关更多信息,请参见How does the search_path influence identifier resolution and the "current schema"PostgreSQL documentation

答案 1 :(得分:0)

postgres=#提示符开始处的psql意味着您已连接到postgres数据库,该数据库是作为管理员连接的占位符创建的,通常没有里面的任何东西。如果未在命令行上指定数据库,则psql将查找与用户同名的数据库,因此postgres用户将默认连接到该数据库。

要连接到test数据库,可以在\c test提示符下键入psql,或使用psql -d test启动它。

相关问题