FATAL: Peer authentication failed for user "postgres"

279 views
Skip to first unread message

Rubin

unread,
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.

Rubin

unread,
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 0.0.0.0
/home/vagrant/.rvm/rubies/ruby-3.0.0/bin/ruby: warning: shebang line ending with \r may cause problems
=> Booting Thin
=> Rails 6.0.4.1 application starting in development http://0.0.0.0:3000
=> Run `rails server --help` for more startup options
Exiting
/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-6.0.4.1/lib/active_record/connection_adapters/postgresql_adapter.rb:46:in `postgresql_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:887:in `new_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:931:in `checkout_new_connection'       
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:910:in `try_to_checkout_new_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:871:in `acquire_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:593:in `checkout'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:437:in `connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:1125:in `retrieve_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_handling.rb:221:in `retrieve_connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/connection_handling.rb:189:in `connection'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/model_schema.rb:369:in `table_exists?'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/attribute_methods/primary_key.rb:91:in `get_primary_key'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/attribute_methods/primary_key.rb:79:in `reset_primary_key'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activerecord-6.0.4.1/lib/active_record/attribute_methods/primary_key.rb:67:in `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-6.0.4.1/lib/active_support/dependencies.rb:515:in `load'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activesupport-6.0.4.1/lib/active_support/dependencies.rb:515:in `block in load_file'
        from /home/vagrant/.rvm/gems/ruby-3.0.0/gems/activesupport-6.0.4.1/lib/active_support/dependencies.rb:706:in `new_constants_in'...................


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

3) database.yml:
development:
  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

unread,
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.

Best,

Gareth

Laurent Savaëte

unread,
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!

Laurent

--
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
Forward
0 new messages