To use Makara, set your adapter to #{db_type}_makara (e.g., mysql2_makara or postgresql_makara) and provide a makara configuration block.
Configuration Options
Top-level makara options:
id: An identifier for the proxy. Highly recommended if sticky: true is used, to prevent stickiness from breaking when the configuration changes.blacklist_duration: Seconds a node is blacklisted after a connection failure (default: 5).disable_blacklist: If true, nodes are not blacklisted on error.sticky: If true, a node is stuck to once used during a specific context.primary_ttl: How long the primary context is persisted (should be longer than replication lag).primary_strategy: Strategy for picking the primary node (round_robin [default] or failover).replica_strategy: Strategy for picking the replica node (round_robin [default] or failover).connection_error_matchers: An array of regexes or strings used to identify errors that should trigger blacklisting instead of being raised.
Connection options:
Each connection in the connections list can override top-level settings.
role: Must be set to primary for the primary node. If omitted, the node is assumed to be a replica.weight: Used to balance traffic (e.g., a node with weight 8 receives more traffic than weight 2).name: An optional attribute used for SQL logging.url: A full connection string (e.g., mysql2://user:pass@host:port/db).
Warning: Do NOT use the standard ENV['DATABASE_URL'] as it interferes with Makara's initialization. Use custom environment variables instead.
production:
adapter: 'mysql2_makara'
database: 'MyAppProduction'
makara:
id: mysql
blacklist_duration: 5
primary_ttl: 5
primary_strategy: round_robin
sticky: true
connections:
- role: primary
host: primary.sql.host
- role: replica
host: replica1.sql.host
weight: 8
name: Big Replica
- role: replica
host: replica2.sql.host
weight: 2
name: Small Replica