Configure and use ClickHouse Cluster mode
masterCluster mode allows you to define multiple nodes in config/database.php.
Important Constraints:
- All nodes must use the same database name, username, and password.
- Reads and writes use the first available node.
- Migrations run on all nodes (will fail if one node is unavailable).
You can manually switch to the next node in the cluster using slideNode().
// config/database.php
'clickhouse' => [
'driver' => 'clickhouse',
'cluster' => [
['host' => 'clickhouse01', 'port' => 8123],
['host' => 'clickhouse02', 'port' => 8123],
],
// ... other settings
];
// Switching nodes
$row = new MyTable();
echo $row->getThisClient()->getConnectHost(); // 'clickhouse01'
$row->resolveConnection()->getCluster()->slideNode();
echo $row->getThisClient()->getConnectHost(); // 'clickhouse02'