PG::ConnectionBad: fe_sendauth: no password supplied

后端 未结 6 868
再見小時候
再見小時候 2020-12-04 18:59

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

6条回答
  •  暖寄归人
    2020-12-04 19:44

    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"

提交回复
热议问题