PG::ConnectionBad: fe_sendauth: 没有提供密码 [英] PG::ConnectionBad: fe_sendauth: no password supplied
问题描述
当我尝试在本地 postgres 数据库上运行rake test"时,它抛出上述异常.
这是我的 pg_hba.conf 文件:# 通过 Unix 域套接字进行数据库管理登录本地所有 postgres 节点
# TYPE 数据库用户地址方法# "local" 仅用于 Unix 域套接字连接本地所有用户名对等体本地 myapp_dev myapp md5本地 myapp_test myapp md5本地 myapp_prod myapp md5#local 所有所有对等点# IPv4 本地连接:托管所有所有 127.0.0.1/32 md5# IPv6 本地连接:主持所有所有:: 1/128 md5# 允许来自本地主机的复制连接,由具有# 复制权限.#local 复制 postgres peer#host 复制 postgres 127.0.0.1/32 md5#host 复制 postgres ::1/128 md5
这里是我的 database.yml 中的相关部分
测试:适配器:postgresql数据库:myapp_test池:5超时:5000主机:本地主机用户名:用户名密码:
在真实的 database.yml 中,'username' 被替换为我登录时的实际用户名.由于身份验证方法定义为peer",因此不需要密码.
我也小心地重启了 Postgres
sudo -u postgres pg_ctlcluster 9.3 主重启
我还缺少什么?
localhost
as a host 指的是一个 TCP 连接,即 auth 方法是 md5
(密码必需)根据您的 pg_hba.conf
:
对于要采用的 peer
方法,您需要通过 Unix 域套接字进行连接,并且由于您似乎使用的是类似 debian 的操作系统,这意味着将 /var/run/postgresql
在 host
字段中,或者什么都不做(除非环境变量另有说明,否则这是默认值).
如果使用数据库 URI(自 Rails-4.1 起支持,如在http://weblog.rubyonrails.org/2014/4/8/Rails-4-1/),语法可以是:
对于本地主机:
test: "postgresql://localhost/myapp_test"
对于默认的 Unix 套接字域(主机字段留空):
test: "postgresql:///myapp_test"
When I attempt to run "rake test" on a local postgres database, it throws the above exception.
Here is my pg_hba.conf file: # Database administrative login by Unix domain socket local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all username peer
local myapp_dev myapp md5
local myapp_test myapp md5
local myapp_prod myapp md5
#local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres peer
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
and here is the relevant section from my database.yml
test:
adapter: postgresql
database: myapp_test
pool: 5
timeout: 5000
host: localhost
username: username
password:
In the real database.yml, 'username' is replaced with my actual user name that I am logged in as. Since the authentication method is defined as 'peer', no password should be required.
I have also taken care to restart Postgres
sudo -u postgres pg_ctlcluster 9.3 main restart
What else am I missing here?
localhost
as a host refers to a TCP connection, which means the auth method is md5
(password required) per your pg_hba.conf
:
# IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5
For the peer
method to be taken, you'd need to connect through Unix domain sockets, and since you seem to be using a debian-like OS, that means putting /var/run/postgresql
in the host
field, or nothing at all (it's the default unless environment variables say otherwise).
EDIT: if using database URIs (supported since Rails-4.1, as announced in http://weblog.rubyonrails.org/2014/4/8/Rails-4-1/), the syntax could be:
for localhost:
test: "postgresql://localhost/myapp_test"
for the default Unix socket domain (host field left empty):
test: "postgresql:///myapp_test"
这篇关于PG::ConnectionBad: fe_sendauth: 没有提供密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!