PG::ConnectionBad: fe_sendauth: no password supplied

后端 未结 6 865
再見小時候
再見小時候 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:42

    I had this problem, solved by a coworker: You need to set a local user and password in postgres

    createuser --interactive --pwprompt
    

    It will ask you for the name of the role (the user) and the password you want to have.

    Then you have to add this username and password to your database.yml file

    0 讨论(0)
  • 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"

    0 讨论(0)
  • 2020-12-04 19:45

    I met this question, too. I checked my database config, /var/www/myproject/shared/config/database.yml:

    production: 
    adapter: postgresql 
    pool: 5 
    timeout: 5000 
    encoding: utf8 
    host: localhost 
    database: myproject
    username: myname 
    password: <%= ENV['name_DATABASE_PASSWORD'] %>
    

    I found the last paragraph is wrong, the right code is

    password: <%= ENV['myproject_DATABASE_PASSWORD'] %>
    
    0 讨论(0)
  • 2020-12-04 19:49

    Change the code as below and it will work

    pg_hba.conf:
    # IPv4 local connections:
    host    all             all             127.0.0.1/32            trust
    # IPv6 local connections:
    host    all             all             ::1/128                 trust
    

    Below its explanation:

    trust

    Allow the connection unconditionally. This method allows anyone that can connect to the PostgreSQL database server to login as any PostgreSQL user they wish, without the need for a password or any other authentication.

    md5

    Require the client to supply a double-MD5-hashed password for authentication.

    refer for more here

    0 讨论(0)
  • 2020-12-04 19:51

    If your hb_conf has already been modified to force passwords, then make sure your rails app's database configuration includes a password in both development and test environments.

    default: &default
      adapter: postgresql
      encoding: unicode
      pool: 5
      host: localhost
      username: your_user
      password: your_password
    
    development:
      <<: *default
      database: your_db_development
    
    test:
      <<: *default
      database: your_db_test
    
    production:
      url: <%= ENV['DATABASE_URL'] %>
    

    I was getting this error when I failed to supply a password for the test database.

    0 讨论(0)
  • 2020-12-04 19:53

    I use Postgres App. Which is really great because you don't have to supply username and password in the default part of the database.yml

    database.yml

    default: &default
      adapter: postgresql
      encoding: unicode
      pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
    
    development:
      <<: *default
      database: my-app_development
    
    test:
      <<: *default
      database: my-app_test
    
    production:
      <<: *default
      database: my-app_production
      username: my-app
      password: <%= ENV['MY-APP_DATABASE_PASSWORD'] %>
    

    My problem: I changed the path and wasn't able to get postgres to work.

    Solution: use the documentation to:

    1) Uninstall the app

    2) Stop the postgres process using this answer, which says to use sudo pkill -u postgres

    3) Reinstall and start the app

    Everything should work fine now, have a great day!

    Note: Doing this also solves the problem Postgres.app port 5432 in use

    0 讨论(0)
提交回复
热议问题