ClickHouse DB::Exception: Connection refused

Pulse - Elasticsearch Operations Done Right

On this page

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

The "DB::Exception: Connection refused" error in ClickHouse occurs when the client is unable to establish a connection with the ClickHouse server. This error indicates that the server is either not running, not accessible, or actively refusing the connection attempt.

Impact

This error prevents any interaction with the ClickHouse database, including querying data, inserting records, or performing administrative tasks. It can significantly disrupt data operations and application functionality that depends on ClickHouse.

Common Causes

  1. ClickHouse server is not running
  2. Firewall blocking the connection
  3. Incorrect connection settings (wrong host, port, or credentials)
  4. Network issues between client and server
  5. Server overload or resource exhaustion
  6. Misconfigured server settings (e.g., listen_host, tcp_port)

Troubleshooting and Resolution Steps

  1. Verify ClickHouse server status:

    sudo systemctl status clickhouse-server
    

    If not running, start the server:

    sudo systemctl start clickhouse-server
    
  2. Check firewall settings: Ensure that the ClickHouse port (default 9000) is open in your firewall.

  3. Verify connection settings: Double-check the host, port, and credentials used in your connection string.

  4. Test network connectivity: Use tools like ping or telnet to verify network connectivity to the ClickHouse server.

  5. Check server logs: Examine ClickHouse server logs for any error messages or warnings:

    sudo tail -f /var/log/clickhouse-server/clickhouse-server.log
    
  6. Review server configuration: Check the ClickHouse configuration file (usually at /etc/clickhouse-server/config.xml) for correct listen_host and tcp_port settings.

  7. Monitor server resources: Use tools like top or htop to check if the server is overloaded or out of resources.

Best Practices

  • Implement proper monitoring for your ClickHouse server to detect issues proactively.
  • Use connection pooling to manage connections efficiently and reduce the likelihood of connection refusals due to overload.
  • Regularly update ClickHouse to the latest stable version to benefit from bug fixes and performance improvements.
  • Configure proper logging and alerting to quickly identify and respond to connection issues.

Frequently Asked Questions

Q: How can I check if the ClickHouse server is listening on the correct port?
A: You can use the netstat command to check if ClickHouse is listening on the expected port:

sudo netstat -tuln | grep 9000

If ClickHouse is properly listening, you should see an entry for port 9000.

Q: What should I do if the server is running but still refusing connections?
A: Check the server's configuration file to ensure listen_host is set correctly. It should be set to 0.0.0.0 to accept connections from any IP, or to a specific IP if you want to restrict access.

Q: Can a full disk cause connection refused errors in ClickHouse?
A: Yes, if the disk where ClickHouse stores its data or logs is full, it can cause the server to stop accepting new connections. Check disk usage with df -h and clear space if necessary.

Q: How can I increase the maximum number of connections in ClickHouse?
A: You can modify the max_concurrent_queries setting in the ClickHouse configuration file. However, be cautious as increasing this may require additional server resources.

Q: Is it possible that antivirus software is causing connection refused errors?
A: Yes, some antivirus or security software can interfere with database connections. Try temporarily disabling such software to see if it resolves the issue. If it does, you may need to add an exception for ClickHouse in your security software.

Subscribe to the Pulse Newsletter

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