postgresql 如何在Heroku上使用新数据库

xnifntxz  于 2022-12-12  发布在  PostgreSQL
关注(0)|答案(1)|浏览(104)

最初,当我在Heroku(免费的)上提供数据库时,我的应用程序获得了一个名为DATABASE_URL的新环境变量,它指向一个新创建的数据库,我的应用程序使用这个数据库。
今天,当我通过UI在Heroku(付费)上提供新数据库时,我得到了一个名为HEROKU_POSTGRESQL_MAUVE_URL的新环境变量,它指向新数据库。
如何将Heroku应用指向这个新配置的数据库HEROKU_POSTGRESQL_MAUVE_URL
我希望我的数据库URL与HEROKU_POSTGRESQL_MAUVE_URL交换,但没有发生。

31moq8wy

31moq8wy1#

This happens when your app has multiple databases:
As part of the provisioning process, a DATABASE_URL config var is added to your app’s configuration. DATABASE_URL contains the URL your app uses to access the database. If your app already has a Heroku Postgres database and you’ve provisioned another one, this config var’s name instead has the format HEROKU_POSTGRESQL_<COLOR>_URL (for example, HEROKU_POSTGRESQL_YELLOW_URL
You can promote your new database to make it the primary database:
pg:promote updates the value of the DATABASE_URL config var with the newly promoted database’s connection string. It also creates an alternate attachment for the old primary database, assigned with a new HEROKU_POSTGRESQL_<color>_URL config var. The promotion process triggers a release and restarts the app.
For example:

heroku pg:promote HEROKU_POSTGRESQL_MAUVE_URL -a your-app

You should continue to use the DATABASE_URL environment variable to connect to your database.

相关问题