ClickHouse DB::Exception: Cannot create a new ZooKeeper session

Pulse - Elasticsearch Operations Done Right

On this page

Impact Common Causes Troubleshooting and Resolution Steps Best Practices Frequently Asked Questions

The error "DB::Exception: Cannot create a new ZooKeeper session" occurs when ClickHouse is unable to establish a connection with ZooKeeper, which is crucial for distributed operations and cluster management in ClickHouse.

Impact

This error can significantly impact ClickHouse's distributed functionality. It may prevent:

  • Distributed table operations
  • Replication processes
  • Cluster coordination
  • Distributed DDL queries

Common Causes

  1. ZooKeeper service is not running or unreachable
  2. Network connectivity issues between ClickHouse and ZooKeeper
  3. Misconfiguration in ClickHouse's ZooKeeper settings
  4. ZooKeeper authentication failures
  5. Exhausted ZooKeeper connection limits

Troubleshooting and Resolution Steps

  1. Verify ZooKeeper Status:

    • Check if ZooKeeper is running on the specified hosts
    • Ensure ZooKeeper ports are open and accessible
  2. Check Network Connectivity:

    • Verify network connectivity between ClickHouse and ZooKeeper servers
    • Check firewall rules and security groups
  3. Review ClickHouse Configuration:

    • Examine the zookeeper section in ClickHouse config
    • Ensure correct hostnames, ports, and paths are specified
  4. Validate ZooKeeper Authentication:

    • If using ZooKeeper authentication, verify credentials in ClickHouse config
  5. Monitor ZooKeeper Resources:

    • Check ZooKeeper logs for any resource exhaustion warnings
    • Increase ZooKeeper's maximum client connections if necessary
  6. Restart Services:

    • Restart ZooKeeper service if it's unresponsive
    • Restart ClickHouse service after confirming ZooKeeper is operational
  7. Update ClickHouse and ZooKeeper:

    • Ensure both ClickHouse and ZooKeeper are on compatible, up-to-date versions

Best Practices

  • Regularly monitor ZooKeeper health and performance
  • Implement ZooKeeper clustering for high availability
  • Keep ClickHouse and ZooKeeper versions in sync
  • Use monitoring tools to alert on ZooKeeper connectivity issues
  • Implement proper error handling in applications using ClickHouse

Frequently Asked Questions

Q: Can ClickHouse function without ZooKeeper?
A: Yes, ClickHouse can function without ZooKeeper for non-distributed operations. However, features like distributed tables, replication, and cluster management require ZooKeeper.

Q: How can I test ZooKeeper connectivity from ClickHouse?
A: You can use the SYSTEM QUERY command in ClickHouse to check ZooKeeper connectivity. For example: SELECT * FROM system.zookeeper WHERE path = '/'

Q: What should I do if ZooKeeper keeps disconnecting?
A: Check network stability, increase ZooKeeper timeout settings in ClickHouse, and ensure ZooKeeper has sufficient resources. Also, consider implementing a ZooKeeper cluster for better reliability.

Q: Is it safe to restart ZooKeeper while ClickHouse is running?
A: While it's generally safe, it may cause temporary disruptions to distributed operations. It's best to plan such restarts during maintenance windows.

Q: How does this error affect data integrity in ClickHouse?
A: This error doesn't directly affect data integrity, but it may impact distributed operations and replication. Ensure to resolve the issue promptly to maintain data consistency across the cluster.

Subscribe to the Pulse Newsletter

Get early access to new Pulse features, insightful blogs & exclusive events , webinars, and workshops.