Heroku postgres create follower db and promote follower to master from slave
I needed to migrate heroku postgres between 2 different heroku applications. One of them has heroku postgres add-on, but the other was connecting to first application's postgres.
However, I wanted to delete first application, so here is how I migrated heroku postgress add-on to another application.
NOTE: you cannot use follower db with hobby plan
-
Create new postgres on second app which follows original db
heroku addons:create heroku-postgresql:standard-0 --follow postgresql-test-xxxx -a second_app
you can check add-on name with
heroku pg:info -a first_app
-
Check how much new db catch up original
heroku pg:info -a second_app
This returns
Following: HEROKU_POSTGRESQL_LAVENDER (DATABASE_URL) Behind By: 125 commits
Once behind by is 0 commits, you are ready to promote!!
-
Turn on maintenance mode to avoid database update(this cause downtime, but should be less than 1 min...)
heroku maintenance:on -a first_app heroku maintenance:on -a second_app
-
Unfollow the original postgres
heroku pg:unfollow HEROKU_POSTGRESQL_COLOR_URL -a second_app
(this url is new postgres url. you can get with
heroku config -a second_app
) -
Promote new postgres
heroku pg:promote HEROKU_POSTGRESQL_COLOR -a second_app
This update config
DATABESE_URL
with new postgres URL -
Turn off maintenance mode
heroku maintenance:off -a first_app heroku maintenance:off -a second_app