gpt4 book ai didi

ruby-on-rails - PG::ConnectionBad: FATAL: 用户密码验证失败

转载 作者:行者123 更新时间:2023-11-29 13:41:21 26 4
gpt4 key购买 nike

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

首先,我使用 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: 数据库“viter”不存在

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

最佳答案

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

这解决了我的问题

关于ruby-on-rails - PG::ConnectionBad: FATAL: 用户密码验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54888781/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com