Heroku 永久数据库凭据 [英] Heroku Permanent Database Credentials

查看:86
本文介绍了Heroku 永久数据库凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定在操作方面节省时间并转向 Heroku.我计划在 Heroku 上使用 postgres 数据库和另一个从同一数据库读取的 dyno.

I've decided to save time on the ops side of things and move to Heroku. I'm planning to have a production dyno on Heroku with a postgres database AND another dyno that reads from the same database.

但是当我打开postgres的设置时,它说:

However when I opened the settings of postgres, it said:

数据库凭据
获取手动连接到此数据库的凭据.

Database Credentials
Get credentials for manual connections to this database.

请注意,这些凭据不是永久性的.
Heroku 会定期轮换凭据并更新附加此数据库的应用程序.

Please note that these credentials are not permanent.
Heroku rotates credentials periodically and updates applications where this database is attached.

解决这个问题的好方法是什么?

What's a good way to go about this?

推荐答案

来自 Heroku 文档

凭据

请勿将数据库凭据复制并粘贴到单独的环境或应用程序的代码中.数据库 URL 由 Heroku 管理,在某些情况下会发生变化,例如:

Do not copy and paste database credentials to a separate environment or into your application’s code. The database URL is managed by Heroku and will change under some circumstances such as:

  • 用户使用 heroku pg:credentials:rotate 启动数据库凭据轮换.
  • 灾难性硬件故障导致 Heroku Postgres 员工在新硬件上恢复您的数据库.
  • 启用 HA 的计划上的自动故障转移事件.

最好的做法是在您的应用程序启动时始终从相应的 Heroku 应用程序中获取数据库 URL 配置变量.例如,您可以使用 Heroku CLI 遵循 12Factor 应用程序配置原则,并像这样调用您的流程:

It is best practice to always fetch the database URL config var from the corresponding Heroku app when your application starts. For example, you may follow 12Factor application configuration principles by using the Heroku CLI and invoke your process like so:

DATABASE_URL=$(heroku config:get DATABASE_URL -a your-app-name) your_process

通过这种方式,您可以确保您的流程或应用程序始终拥有正确的数据库凭据.

This way, you ensure your process or application always has correct database credentials.

这篇关于Heroku 永久数据库凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆