1

I spent half of my day and tried to fix this issue. I read a lot of topics on stack overflow and other resources but haven't found any useful answers.

First of all, I created my application with PostgreSQL flag, and regarding this tutorial, was trying to set up my environment:

Here is my database.yml

default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see Rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  host: localhost
  username: viter
  password: ******

development:
  <<: *default
  database: my_app_development

  # The specified database role being used to connect to postgres.
  # To create additional roles in postgres see `$ createuser --help`.
  # When left blank, postgres will use the default role. This is
  # the same name as the operating system user that initialized the database.
  #username: my_app

  # The password associated with the postgres role (username).
  #password:

  # Connect on a TCP socket. Omitted by default since the client uses a
  # domain socket that doesn't need configuration. Windows does not have
  # domain sockets, so uncomment these lines.
  #host: localhost

  # The TCP port the server listens on. Defaults to 5432.
  # If your server runs on a different port number, change accordingly.
  #port: 5432

  # Schema search path. The server defaults to $user,public
  #schema_search_path: myapp,sharedapp,public

  # Minimum log levels, in increasing order:
  #   debug5, debug4, debug3, debug2, debug1,
  #   log, notice, warning, error, fatal, and panic
  # Defaults to warning.
  #min_messages: notice

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: my_app_test

# As with config/secrets.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
#   DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
#   production:
#     url: <%= ENV['DATABASE_URL'] %>
#
production:

But after the command rake db:create I receive:

FATAL:  password authentication failed for user "viter"
FATAL:  password authentication failed for user "viter"
Couldn't create 'my_app_development' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: FATAL:  password authentication failed for user "viter"
FATAL:  password authentication failed for user "viter"

Also tried to use this topic but receive this error after running 'psql' command:

psql: FATAL: database "viter" does not exist

Also here is my pg_hba.conf file:

# Database administrative login by Unix domain socket
local   all             postgres                                md5

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.

3 Answers3

0

Make sure that you create the user viter and the database my_app_development with the correct permissions. From your error message, it seems you tried something with the database viter, which you don't need.

Philipp F
  • 417
  • 2
  • 11
0

The problem you are facing is that you haven't made a user for your app's DB.

First, you'll want to create your "viter" user via postgres; sudo -u postgres createuser viter -s

This also makes "viter" a superuser.

Then, you need to set the password for "viter" to match what is used in "database.yml" by using this command while in psql (as the postgres user): \yourpassword viter

Next, create each DB with "viter" as the owner (while still in the psql terminal).

Create your development DB with this: CREATE DATABASE my_app_development OWNER viter;

Repeat this for both production and test databases depending on the name of each DB.

For example; my_app_production and my_app_test.

Jake
  • 1,086
  • 12
  • 38
  • Hello Jake, after this command 'sudo -u postgres createuser viter -s' I received '[sudo] password for viter:' I typed password (same as in my database.yml file) pushed "Enter" button, and it requested second time 'Password:', I typed second time password, and received: 'createuser: could not connect to database postgres: FATAL: password authentication failed for user "postgres" –  Feb 27 '19 at 09:40
0

In your config/database.yml to get Postgres.app running rewrite:

default: &default
  adapter: postgresql
  encoding: unicode
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: myapp_development

test:
  <<: *default
  database: myapp_test

This solve my problem

nourza
  • 2,215
  • 2
  • 16
  • 42