0
votes

I am working on a rails app using postgresql 9.1 as a database.in postgresql i a have configured for streaming replication, Now how to add Master and Slave PostgreSQL database in rails application ( in database.yml file) I have specified the database details as

development:

adapter: postgresql encoding: unicorn database: app_development pool: 5 username: username password: password host: master ip port: port number

development:

adapter: postgresql encoding: unicorn database: app_development pool: 5 username: username password: password host: slave ip port: port number

development:

adapter: postgresql encoding: unicorn database: app_development pool: 5 username: username password: password host: svale ip port: port number

But While executing this produces error as " ActiveRecord::StatementInvalid" " PG::ReadOnlySqlTransaction: ERROR: cannot execute INSERT in a read-only transaction"

How to specify the master and slave database in database.yml file

Regards, Balu

1
Also, I think there is no native way for achieving your goal. You might want to have a look at Makara, which allows you to split read/write operations for Active Record.Lukas
This probably needs a Rails tag. Voted for migration to SO.ypercubeᵀᴹ

1 Answers

0
votes

Don't do this in your database. Use an external failover solution with either non-cached DNS records or virtual IP addresses, and let your app be able to function without knowing the failure states of the nodes.

Replication and failover is complicated stuff and if you don't want data loss, you need to make sure you do it right. This means accepting that this is not an app problem but an infrastructure problem and building it in there.