我有一种情况让我摸不着头脑,但我是 postgresql 的新手,所以我可能会忽略一些明显的东西。
我设置了一个测试台服务器并在 pg_hba.conf 中设置了访问权限:
local all postgres peer
local all all md5
host all all 127.0.0.1/32 trust
host all all ::1/128 md5
Run Code Online (Sandbox Code Playgroud)
然后重新启动 postgresql 服务器,之后,作为我的普通用户,我可以使用
psql -h localhost -U postgres -l
Run Code Online (Sandbox Code Playgroud)
这给了我表格列表。
在第二个系统上 pg_hba.conf 匹配其他文件。我重新启动了数据库服务器进程,但是 psql -h localhost -U postgres -l 因为我的用户产生了这个错误:
2012-03-29 23:31:17 UTC LOG: could not receive data from client: Connection reset by peer
Password for user postgres:
psql: fe_sendauth: no password supplied
2012-03-29 23:31:29 UTC LOG: could not receive data from client: Connection reset by peer
Run Code Online (Sandbox Code Playgroud)
我没有为该用户配置密码。如果我
sudo su - postgres
Run Code Online (Sandbox Code Playgroud)
然后试试
psql -h localhost -U postgres -l
Run Code Online (Sandbox Code Playgroud)
...因为 postgres 不起作用,仍然提示输入密码,但如果我使用:
psql -l
Run Code Online (Sandbox Code Playgroud)
它给出了数据库列表。
这台服务器,即第二台服务器,上面有一个“生产”数据库,由另一位开发人员设置。但他不知道为什么它不让我在该服务器上使用 -h host -U postgres 参数将其列为我的用户名,而第一台服务器上的全新安装将列出它们(尽管第一个没有但默认安装就可以了。)
平台是 Ubuntu 11.10,postgres 是 9.1。知道我在俯瞰什么吗?
编辑 这是我尝试获取数据库列表时发生的情况:
user@testbed:/etc/postgresql/9.1/main$ grep listen_addresses *
grep: pg_hba.conf: Permission denied
grep: pg_ident.conf: Permission denied
postgresql.conf:#listen_addresses = 'localhost' # what IP address(es) to listen on;
user@testbed:/etc/postgresql/9.1/main$ psql -h localhost -U postgres -l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
user@testbed:/etc/postgresql/9.1/main$
Run Code Online (Sandbox Code Playgroud)
在另一个系统上:
user@production:/etc/postgresql/9.1/main$ grep listen_addresses *
grep: pg_hba.conf: Permission denied
grep: pg_hba.conf~: Permission denied
grep: pg_ident.conf: Permission denied
postgresql.conf:#listen_addresses = 'localhost' # what IP address(es) to listen on;
user@production:/etc/postgresql/9.1/main$ psql -h localhost -U postgres -l
Password for user postgres:
psql: fe_sendauth: no password supplied
user@production:/etc/postgresql/9.1/main$
Run Code Online (Sandbox Code Playgroud)
根据 pg_hba.conf 片段,如果您从 ::1 连接,则需要密码,这是 localhost 的 IPv6 地址。
可能是您遇到问题的机器配置了解析器,以便名称“localhost”同时指代 127.0.0.1 (IPv4) 和 ::1 (IPv6),以便命令psql -h localhost...可以连接到一个或其他地址。
我建议检查/etc/hosts文件中是否有不同的 localhost 条目,或者通过连接到 127.0.0.1 绕过解析器,或者使用 IPv6 本地连接的“信任”更新 pg_hba.conf。
| 归档时间: |
|
| 查看次数: |
2058 次 |
| 最近记录: |