尝试使用 Rails 连接 Postgresql 时出现连接错误

问题描述 投票:0回答:1

我正在尝试将 Rails 中的应用程序与 Postgresql 连接,但我遇到了有关用户名的错误,但是,我检查了几次,一切似乎都正常。 我正在使用 Rails 7 这是 docker-compose 文件:

version: "3.8"
services:
  database:
    image: "postgres:14-alpine"
    ports:
      - 5432:5432
    environment:
      - POSTGRES_USER=aventuraweb
      - POSTGRES_PASSWORD=secret
      - POSTGRES_DB=aventuraweb_development
    volumes:
      - postgres_data_development:/var/lib/postgresql/data

  redis:
    image: "redis:7"
    ports:
      - 6379:6379

volumes:
  postgres_data_development: {}

这是数据库.yml:

default: &default
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>

development:
  <<: *default
  database: aventuraweb_development
  username: aventuraweb
  password: secret
  host: localhost

我运行 foreman,一切似乎都正常,但是当我尝试访问该页面时,我发现了错误:

aventuraweb-database-1  | 2023-07-16 17:40:16.711 UTC [29] FATAL:  password authentication failed for user "aventuraweb"
19:40:16 db.1    | aventuraweb-database-1  | 2023-07-16 17:40:16.711 UTC [29] DETAIL:  Role "aventuraweb" does not exist.
19:40:16 db.1    | aventuraweb-database-1  |    Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"

18:21:12 web.1   | ActiveRecord::DatabaseConnectionError (There is an issue connecting to your database with your username/password, username: aventuraweb.
18:21:12 web.1   | 
18:21:12 web.1   | Please check your database configuration to ensure the username/password are valid.

我多次尝试修剪系统和网络,但我不知道下一步该怎么做 知道发生了什么吗? 谢谢!

ruby-on-rails postgresql connection
1个回答
0
投票

似乎问题可能是您的 Rails 应用程序的 config/database.yml 中有

host: localhost
。 应将其设置为
host: database
,它映射到名为
database
的 docker-compose.yml 数据库服务,而不是映射到您的主机 (localhost)。

© www.soinside.com 2019 - 2024. All rights reserved.