PG :: ConnectionBad: FATAL: аутентификация по паролю не удалась для пользователя - PullRequest
0 голосов
/ 26 февраля 2019

Я провел половину своего дня и попытался решить эту проблему.Я прочитал много тем о переполнении стека и других ресурсах, но не нашел ни одного полезного ответа.

Прежде всего, я создал свое приложение с флагом PostgreSQL и относительно этого урока ,пытался настроить мою среду:

Вот мой 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:

Но после команды rake db:create я получаю:

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"

Также пробовалиспользовать эту тему , но получить эту ошибку после выполнения команды 'psql':

psql: FATAL: database "viter" does not exist

Также вот мой файл pg_hba.conf:

# 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 ]

0 голосов
/ 27 февраля 2019

Проблема, с которой вы сталкиваетесь, заключается в том, что вы не создали пользователя для базы данных своего приложения.

Во-первых, вы захотите создать своего пользователя "viter" через postgres;sudo -u postgres createuser viter -s

Это также делает "viter" суперпользователем.

Затем вам нужно установить пароль для "viter", чтобы он соответствовал тому, что используется в "database.yml", используя этукоманда в psql (как пользователь postgres): \yourpassword viter

Далее создайте каждую БД с владельцем "viter" (пока еще в терминале psql).

Createваша БД разработки с этим: CREATE DATABASE my_app_development OWNER viter;

Повторите это для баз данных production и test в зависимости от имени каждой БД.

Например;my_app_production и my_app_test.

0 голосов
/ 25 июня 2019

В вашем config / database.yml, чтобы получить перезапись Postgres.app:

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

Это решит мою проблему

0 голосов
/ 26 февраля 2019

Убедитесь, что вы создали пользователя viter и базу данных my_app_development с правильными разрешениями.Из вашего сообщения об ошибке кажется, что вы пытались что-то с базой данных viter, что вам не нужно.

...