1

Apparently when using the Octopus gem to do Postgres replication everything should be plug and play. However I can't seem to find what I'm doing wrong.

This is my config/shards.yml

octopus:
  environments:
    - development
  replicated: true
  development:
    slave1:
      adapter: postgresql
      host: localhost
      database: slaveapp_development
      username: pguser
      password: pgpass

The AR model Provider(I create the exact same tables in each app via Rake tasks) I'd like to sync/replicate to my slave:

class Provider < ActiveRecord::Base
  has_many :products
  replicated_model()
end

I boot both apps via Rails server and enter Masterapp's console and from there:

> Provider.using(:slave1).create({provider_params...})  
#=> works! I get a new record in slave1's DB.
> Provider.using(:master).create({provider_params...})  
#=> works partly. Creates record only in master's DB.

The problem is that when calling Provider.using(:master)... I'm expecting:

1 - Create record at master's DB.

2 - Replicate same record at slave1's DB. <--- This is NOT happening.

lllllll
  • 4,715
  • 6
  • 29
  • 42

2 Answers2

2

That is not the purpose of the Octopus gem.

It redirects the database requests, depending on whether it is a read or write operation. That way you can use your Rails models without thinking about the current database connection and if it fits the intended operation.

It does not copy the data to the slaves.

To perform the actual replication, i.e. the data transfer from the master to the slaves, you have to set it up yourself.

There are several options with PostgreSQL. If you are using a newer version (9.1+) you can use the integrated streaming replication in "hot standby" mode. There are tutorials on how to set it up, e.g.

If you are stuck with an older version of PostgreSQL have a look at the alternatives.

Daniel Rikowski
  • 71,375
  • 57
  • 251
  • 329
  • Oh! That explains a lot and it all makes more sense :/ Thank you for this. I'm not very experienced on this, do you have any preferred solution to implement the master-multislave replication for specific tables(not whole DB)? I'm thinking about [Slony-I](http://slony.info/). – lllllll Oct 08 '15 at 21:03
  • I have no experience in that, too, but Slony-I seems to be a safe choice, since it is actively maintened and widely used. – Daniel Rikowski Oct 09 '15 at 10:41
0

Try adding fully_replicated: false after replicated: true in your config.

Alexey Shein
  • 7,342
  • 1
  • 25
  • 38
  • @vint-i-vuit Does your `Provider` model create any related models in callbacks? If yes, check if all of them contain `replicated_model()` call. – Alexey Shein Oct 04 '15 at 19:37
  • Thanks for the input. It doesn't deal with any model in callbacks explicitly. It does have some "has_many" relationship, but I did comment that out just in case, with no luck :( – lllllll Oct 05 '15 at 17:17