When creating a database, the following error occurs:

andrey@asus:~/project/odnogrupniki$ rake db:create:all FATAL: Peer authentication failed for user "odnogrupniki" 

full logs: HERE

databse.yml:

 default: &default adapter: postgresql encoding: unicode pool: 5 timeout: 5000 username: 'odnogrupniki' password: '1111' development: <<: *default database: odnogrupniki test: <<: *default database: odnogrupniki_test production: <<: *default database: odnogrupniki_production 

in gemfile added: gem 'pg'
Bundle - performed

 andrey@asus:~/project/odnogrupniki$ psql --version psql (PostgreSQL) 9.5.1 

Created a user like this:

 postgres@asus:/home/andrey/project/odnogrupniki$ createuser odnogrupniki -P -S -R -D Enter password for new role: Enter it again: 

    2 answers 2

    Locally, you can tune in to work on peer athentication , but to do this, the database must have a user with the same name as the connecting login in the operating system . For development, this can be configured as quickly as possible on a clean distribution.

    In order for ActiveRecord to connect, making sure only with the account of the domain socket connecting through the Unix , you need to remove the login, password and host from the connection settings . Totally. And you can make “yourself” the superuser in the database on a newly installed PostgreSQL (when there is only one user, postgres ) in one command:

     sudo -u postgres createuser --superuser $(whoami) 
     \______________/ \______________________________/ Притворившись Создать суперпользователя с postgres именем, выведенным командой whoami 

    And then the usual rake db:create and so on.

    The advantages of this approach are enough:

    • It works with default settings: installed, made self-admin and forward
    • Account data does not exist at any time in the working tree.

    It’s not worth doing this on a “combat” server, but that 's another story ...

      Replace the authentication method in the pg_hba.conf configuration file instead of using system account authentication

       local all postgres peer 

      specify password authentication

       local all postgres md5 
      • or on trust for local database - Mal Skrylev