PG :: ConnectionBad:严重:用户“ viter”的密码身份验证失败

时间:2019-02-26 15:20:38

标签: ruby-on-rails postgresql ubuntu-14.04

我花了一半的时间来尝试解决此问题。我阅读了很多有关堆栈溢出和其他资源的主题,但没有找到任何有用的答案。

首先,我用PostgreSQL标志创建了我的应用程序,关于this tutorial,我试图建立我的环境:

这是我的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"

也尝试使用this topic,但在运行'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 :(得分:0)

确保使用正确的权限创建用户viter和数据库my_app_development。 从错误消息中,您似乎在数据库viter上尝试了一些不必要的操作。

答案 1 :(得分:0)

您面临的问题是您还没有成为应用数据库的用户。

首先,您需要通过postgres创建“ viter”用户; sudo -u postgres createuser viter -s

这也使“ viter”成为超级用户。

然后,您需要在psql中(以postgres用户身份)使用以下命令,设置“ viter”的密码以匹配“ database.yml”中使用的密码:\yourpassword viter

接下来,以“ viter”作为所有者创建每个数据库(仍在psql终端中)。

使用以下命令创建开发数据库:CREATE DATABASE my_app_development OWNER viter;

根据每个数据库的名称,对productiontest数据库重复此操作。

例如; my_app_productionmy_app_test

答案 2 :(得分:0)

在您的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

这解决了我的问题

相关问题