在try 通过ahoy_matey GEM创建到数据库blazer的连接时,从Rails应用程序内部,配置需要连接到Postgres,首先try 直接连接,而不是通过ENV变量

data_sources:
  main:
#    url: <%= ENV["BLAZER_DATABASE_URL"] %>
    url: "postgres://deploy_root@111.222.333.44:5432/databasename_production"

语法应该在哪里 ENV["BLAZER_DATABASE_URL"] = "postgres://user:password@hostname:5432/databasename_production"

对于具有超级用户权限的postgres,存在用户deploy_root,但是,错误地填写了database.yml:

production:
  <<: *default
  database: databasename_production
  username: deploy_root
  password: <%= ENV["DATABASENAME_DATABASE_PASSWORD"] %>

其中控制台确认

> ENV["DATABASENAME_DATABASE_PASSWORD"]
=> nil

the application runs as expected, connecting to the database. The replication of those connections for blazer is however failing as such:
"postgres://deploy_root@111.222.333.44:5432/databasename_production"

ActiveRecord cannot connect  
`ActiveRecord::ConnectionNotEstablished (could not connect to server: Connection refused
        Is the server running on host "111.222.333.44" and accepting
        TCP/IP connections on port 5432?`

Blazer需要设置DATA_SOURCES/Main(遗憾的是它没有依赖于Rails应用程序连接的机制……)这就提出了如何连接的问题,因为密码不确定(用于此服务器上的另一个应用程序).

• how to recover the encrypted password for the postgres USER?
• if it is nil how to establish the connection?

推荐答案

@dbugger有正确的观点. 此外,gem还记录了一个有用的策略,

但是,此时自封闭Rails应用程序上的连接会连接到本地IP "postgres://blazer:some_secret@127.0.01:5432/databasename_production"

Ruby-on-rails相关问答推荐

Ubuntu Webhooks无法读取安装的正确RVM Ruby

Ruby:如何通过谓词将一个集合拆分为 ruby​​ 中的两个集合?

Rails 7 共享刺激控制器功能

BigDecimals 的总和最终成为整数 [Ruby on Rails]

如何在 Arel 中重用单个绑定变量?

Rails 3 的data-method='delete'如何优雅地降级?

禁用冻结字符串文字注释判断

如何添加到序列化数组

Rails - 生产模式下的错误

升级到 ruby​​ 1.9.2 后奇怪的无法要求配置/ bootstrap

Rails:使用 gem 卸载特定版本的库

设计记住我和会话

如何检测我的代码是否在 Rails 3 的控制台中运行?

参数错误:范围主体需要可调用

ActiveRecord 查找现有表索引

Rspec - Rails - 如何遵循重定向

如何在rails中正确使用单选按钮?

RoR select_tag 默认值和选项

使用连接的 Ruby on Rails ActiveRecord 查询

是否可以输出rake db:migrate产生的 SQL 更改脚本?