问题
I wanted to copy a database from one app to another in heroku. I have an issue with indexes forcing me to do this using a follower db and then unfollowing.
My problem is that now after creating the follower, unfollowing, and promoting it i'm getting an error when trying to write to it:
ActiveRecord::StatementInvalid: PG::ReadOnlySqlTransaction: ERROR: cannot execute ALTER TABLE in a read-only transaction
Also, when I run: SELECT pg_is_in_recovery(); I get true
What I did was:heroku addons:create heroku-postgresql:standard-4 –follow MAIN_DB_ADDON_NAME -a app-that-follows
heroku pg:unfollow HEROKU_POSTGRESQL_COLOR_URL -a app-that-follows
heroku pg:promote HEROKU_POSTGRESQL_COLOR_URL -a app-that-follows
Any idea why i'm getting this error, and more importantly, how do I solve it??
Thanks,
Uri
回答1:
After a while the database became writable again. I'm attaching the answer I got from heroku support:
When you unfollowed the primary database, was the follower completely up to date? If the follower has a bunch of built up WAL it can sometimes leave the database in recovery until it is able to ro replay all of the WAL.
And indeed when you do a pg:info and have a follower db you can see a Behind By field showing you how many commits your follower is behind by.
Mine was way behind, so it took it a while to catch up...
Probably a good idea to add this to the heroku postgres documentation
来源:https://stackoverflow.com/questions/46422248/activerecordstatementinvalid-pgreadonlysqltransaction-heroku-database-st