【问题标题】:Rails db:migrate with postgres running in a containerRails db:使用在容器中运行的 postgres 迁移
【发布时间】:2017-10-31 10:22:37
【问题描述】:

在我的开发环境中,我在容器中运行 postgres,运行 db:migrate 工作正常,直到最近我需要将架构更改为 sql

config.active_record.schema_format = :sql

当我运行 db:migrate 时不会出现以下错误:

pg_dump: [archiver (db)] connection to database "mydatabase" failed: FATAL:  password authentication failed for user "myuser"

在我看来 pg_dump 忽略了 database.yml 设置。其他人对这种设置有任何运气吗?

【问题讨论】:

    标签: ruby-on-rails postgresql docker


    【解决方案1】:

    我最终做的是在你使用的 ubuntu 中安装 postgresql-client-common 和 postgresql-client:

    sudo apt install postgresql-client-common postgresql-client
    

    这给了我本地的 pg_dump,然后我在 docker 机器中打开了一个终端并将host all all 0.0.0.0/0 trust 添加到默认的 pg_hba.conf 文件中

    要打开一个外壳使用:

    docker exec -i -t <idOfContainer> /bin/bash
    

    添加行:

    cd /var/lib/postgresql/data
    echo host all all 0.0.0.0/0 trust >> pg_hba.conf
    

    最后一步是您需要将本地用户添加到 postgress,pg_dump 不会使用来自 datbaase.yml 的凭据,因此您应该连接到 psql 并运行:

    CREATE USER <youruser>
    

    【讨论】:

      猜你喜欢
      • 2018-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-03
      • 2020-07-02
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多