Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActiveRecord::StatementInvalid: PG::Error: ERROR: cannot execute UPDATE in a read-only transaction error in Heroku

I created a new database on Heroku using a follower. After it was 0 commits behind I unfollow the master db and promote it as default.

Seems to be working fine but looks to be read only. When I try to seve a record from the console now I see this error

ActiveRecord::StatementInvalid: PG::Error: ERROR:  cannot execute UPDATE in a read-only transaction

Any idea how to solve this?

like image 611
Martin Avatar asked Nov 04 '12 23:11

Martin


1 Answers

The replica never actually got promoted. See comments.

You can tell when a replica is following a master server because:

SELECT pg_is_in_recovery();

will return true. This cannot return true in a master server because the only time a master server can be in recovery is when it is still starting up - and then you cannot connect to it, so you can't run that command. That's true as of 9.2 and 9.3beta; this may change in future versions, so if you're reading this and on a newer version check for a dedicated function for checking if the server is a replica.

like image 165
Craig Ringer Avatar answered Oct 13 '22 07:10

Craig Ringer