FATAL: Peer authentication failed for user "postgres"

Skip to first unread message


Oct 8, 2021, 4:35:13 PM10/8/21
to Alaveteli Dev
I recieve this error when trying to start my server. I have set the final parameter in the pg_hba.conf file to md5 and have the password of the postgres user in my config/database.yml file. I'm unsure why this error is persisting. Any advice would be appreciated. I can also provide more information, apologies if this is vague.


Oct 9, 2021, 8:37:03 AM10/9/21
to Alaveteli Dev
I have 3 pieces of output I feel might be useful.
1) Rails Output Log:
    from /home/vagrant/alaveteli/spec/factories/alaveteli_pro/draft_info_request_batches.rb:16:in `block in <top (required)>'
vagrant@alaveteli-stretch64:~/alaveteli$ bundle exec rails server -b
/home/vagrant/.rvm/rubies/ruby-3.0.0/bin/ruby: warning: shebang line ending with \r may cause problems
=> Booting Thin
=> Rails application starting in development
=> Run `rails server --help` for more startup options
/home/vagrant/.rvm/gems/ruby-3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `initialize': FATAL:  Peer authentication failed for user "postgres" (PG::ConnectionBad)
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `new'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/pg-1.2.3/lib/pg.rb:58:in `connect'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `postgresql_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `new_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `checkout_new_connection'       
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `try_to_checkout_new_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `acquire_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `checkout'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `retrieve_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `retrieve_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `table_exists?'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `get_primary_key'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `reset_primary_key'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord- `primary_key'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/bundler/gems/acts_as_versioned-63b1fc8529d0/lib/acts_as_versioned.rb:179:in `acts_as_versioned'
        from /home/vagrant/alaveteli/app/models/public_body.rb:119:in `<class:PublicBody>'
        from /home/vagrant/alaveteli/app/models/public_body.rb:37:in `<top (required)>'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activesupport- `load'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activesupport- `block in load_file'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activesupport- `new_constants_in'...................

2) /etc/postgresql/9.6/main/pg_hba.conf:
local    all    postgres    peer

3) database.yml:
  adapter: postgresql
  template: template_utf8
  username: postgres
  pasword: postgres123
  database: foi_development

4) sudo -u postgres psql \l:
                                     List of databases
      Name       |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
 foi_development | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 foi_test        | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 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 

I suspect I may need to alter permissions for foi_test and foi_development...

Gareth Rees

Oct 26, 2021, 12:05:41 PM10/26/21
to Alaveteli Dev
It's not obvious to me what's up here, but this old article [1] is the one I always reach for when digging in to postgres permissions (which is not often, so I'm pretty rusty at the moment!)

I don't think there's anything specific to Alaveteli going on here. I believe the ordering of the pg_hba.conf matters, so might just be a case of moving the line you've added above some other rule that's preventing successful authentication.

FWIW, Alaveteli doesn't yet support Ruby 3.0.0, and we use rbenv rather than rvm, so not sure whether either of those are related here. Seems unlikely, but it's not a configuration we'd recommend right now.



Laurent Savaëte

Oct 26, 2021, 12:18:54 PM10/26/21
to alavet...@googlegroups.com

A random bit of personal experience: check that you don't have multiple versions of postgres installed or running in parallel on your machine. I've been caught by this a couple of times.

The pg_hba.conf you list is for 9.6, just check that this is indeed what you're running, otherwise you can change the config all day long, and never see any impact :)

\conninfo in psql should do the trick.

Good luck!


You received this message because you are subscribed to the Google Groups "Alaveteli Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to alaveteli-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/alaveteli-dev/57300404-5071-42ff-8cf9-0fd0ae2a64cdn%40googlegroups.com.
Reply all
Reply to author
0 new messages