Skip to content

ClickHouse

In this article

Information

ClickHouse is a high-performance columnar database management system (DBMS) designed for executing OLAP-class analytical queries. The DBMS is focused on analyzing large volumes of data with low latency and is widely used in analytics, monitoring, logging, and telemetry processing tasks.

ClickHouse. Core Features

  • Columnar storage: data is stored by columns rather than rows, which significantly speeds up analytical query execution and reduces the volume of processed data.
  • High performance: optimized for handling massive datasets and capable of executing queries on billions of rows thanks to vectorized processing and efficient CPU utilization.
  • Data compression: employs specialized compression algorithms that can dramatically reduce the amount of stored data (often several times smaller than row-based DBMS), especially under analytical workloads.
  • SQL compatibility: supports extended SQL syntax with additional analytical functions, simplifying migration of existing applications.
  • Distributed processing: enables cluster creation for horizontal scaling and data processing across multiple servers.
  • Data replication: built-in replication support ensures fault tolerance and high data availability.
  • Support for multiple data formats: can import and export data in CSV, JSON, Parquet, Avro, and other formats.
  • Materialized views: automatically aggregates data in the background to accelerate recurring queries.
  • Integration with external sources: supports direct reading of data from MySQL, PostgreSQL, MongoDB, Kafka, S3, and other systems.

Deployment Features

ID
  • Installed software:

    • ClickHouse Server >= 26.1.1
    • ClickHouse Client >= 26.1.1
  • Installation specifics:

    • Software installed via the official developer script;
    • Installation time: 5-10 minutes;
    • Database is available for network connections via various SQL clients;
    • By default the user default with the password from the root account is used.

Configuration and data file locations:

  • Main server configuration: /etc/clickhouse-server/config.xml
  • User settings: /etc/clickhouse-server/users.xml
  • Server logs:
    • /var/log/clickhouse-server/clickhouse-server.log
    • /var/log/clickhouse-server/clickhouse-server.err.log
  • Data: /var/lib/clickhouse/
  • PID file: /run/clickhouse-server/clickhouse-server.pid
  • System limits: /etc/security/limits.d/clickhouse.conf

Available ports for connections:

Port Protocol Purpose Status Clients/Usage
8123 HTTP HTTP interface Active DBeaver, DataGrip, Tableau, web interface, JDBC/ODBC
9000 TCP Native ClickHouse native protocol Active clickhouse-client, Python/Go drivers
9004 MySQL MySQL protocol emulation Active MySQL Workbench, mysql client
9005 PostgreSQL PostgreSQL protocol emulation Active pgAdmin, psql client
9009 Interserver HTTP Replication between servers Active Intra-cluster communication
8443 HTTPS HTTP interface with SSL Optional Requires SSL certificate configuration
9100 gRPC gRPC interface Optional gRPC clients

Note

Ports 8443 and 9100 are disabled by default and require additional configuration in /etc/clickhouse-server/config.xml.

Note

Unless otherwise specified, we install the latest release version of the software from the official developer website.

Getting Started After Deploying ClickHouse

A notification will be sent to the e-mail specified during registration that the server is ready for work after paying for the order. It will contain the IP address of the VPS, as well as the login and password for the connection. Clients of our company manage the hardware in the server`s and API control panel - Invapi.

Authorization details:

  • Server IP address: provided in the email and in the control panel;
  • Login: default;
  • Password: matches the password of the root account and is sent to the email address.

Important

For GUI clients (DBeaver, DataGrip, and others) use port 8123 (HTTP interface). Port 9000 is reserved only for the native clickhouse-client.

Connecting to ClickHouse

Connection Methods

This section describes the most common ways to connect to ClickHouse via clickhouse-client (command-line client) and DBeaver (graphical interface). ClickHouse also supports connections via other clients: DataGrip, Tableau, MySQL Workbench (through port 9004), pgAdmin (through port 9005), as well as programming libraries for Python, Go, Java, and other languages.

Connecting via clickhouse-client

ClickHouse includes a native command-line client for database operations.

1. Connecting from the server (locally):

clickhouse-client

2. Connecting from a remote machine:

clickhouse-client --host <IP-address> --port 9000 --user default --password <password>

3. Executing a simple query:

SELECT version();

4. Viewing the list of databases:

SHOW DATABASES;

Connecting via DBeaver

DBeaver is a universal GUI client for working with various databases, including ClickHouse.

1. Installing DBeaver

Download and install DBeaver from the official website.

2. Creating a new connection

  • Launch DBeaver
  • Select Database >> New Database Connection (or press Ctrl+Shift+N)

  • In the database list find and select ClickHouse

  • Click Next

3. Configuring connection parameters

In the settings window specify the following parameters:

Host: <IP-address of your server>
Port: 8123
Database/Schema: (leave empty or specify default)
Username: default
Password: <root_password>

Critically important

For DBeaver connections use port 8123.

4. Downloading the JDBC driver

When connecting for the first time, DBeaver will prompt you to download the JDBC driver for ClickHouse:

  • Click Download in the popup window:

  • Wait for the driver to finish downloading:

  • Click OK

5. Testing the connection

  • Click Test Connection;
  • If everything is configured correctly, a message will appear: Connected (XXX ms):

  • The message will include:
  • Server: ClickHouse X.X.X.XXX
  • Driver: ClickHouse JDBC Driver X.X.X

6. Finalizing setup

  • Click Finish;
  • The connection will appear in the Database Navigator;
  • Expand the connection tree to view databases, tables, and other objects.

Common issues:

Error Cause Fix
transport error: 400 Port 9000 used instead of 8123 Change to port 8123
Connection refused Wrong IP or firewall blocks port Verify IP address and firewall rules
Authentication failed Wrong login or password Verify credentials
Hostname is not specified SSH tunnel accidentally enabled without configuration Close the SSH tab in connection settings

Core Operations in ClickHouse

Creating a database

CREATE DATABASE IF NOT EXISTS my_database;

Creating a table

CREATE TABLE my_database.events
(
    event_date Date,
    event_time DateTime,
    user_id UInt32,
    event_type String,
    value Float64
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(event_date)
ORDER BY (event_date, user_id);

Inserting data

INSERT INTO my_database.events VALUES
    ('2024-12-25', '2024-12-25 10:00:00', 1, 'click', 1.5),
    ('2024-12-25', '2024-12-25 10:05:00', 2, 'view', 2.3),
    ('2024-12-25', '2024-12-25 10:10:00', 1, 'purchase', 99.99);

Selecting data

Simple query:

SELECT * FROM my_database.events LIMIT 10;

Aggregating data:

SELECT 
    event_type,
    count() as events_count,
    avg(value) as avg_value
FROM my_database.events
WHERE event_date = '2024-12-25'
GROUP BY event_type;

Time series:

SELECT 
    toStartOfHour(event_time) as hour,
    count() as events_per_hour
FROM my_database.events
WHERE event_date >= '2024-12-01'
GROUP BY hour
ORDER BY hour;

Importing data from CSV

Creating a table:

CREATE TABLE my_database.logs
(
    timestamp DateTime,
    level String,
    message String
)
ENGINE = MergeTree()
ORDER BY timestamp;

Importing data:

INSERT INTO my_database.logs
FROM INFILE '/path/to/file.csv'
FORMAT CSV;

Managing users and privileges

Creating a user:

CREATE USER analyst IDENTIFIED BY 'secure_password';

Granting permissions:

GRANT SELECT ON my_database.* TO analyst;

Viewing users:

SHOW USERS;

Viewing privileges:

SHOW GRANTS FOR analyst;

Managing the service

Starting the service:

clickhouse start

Stopping the service:

clickhouse stop

Restarting the service:

clickhouse restart

Service status:

clickhouse status

Viewing logs:

tail -f /var/log/clickhouse-server/clickhouse-server.log

Note

If you are not operating as root, prepend sudo to commands: sudo clickhouse start

Checking active ports

To see which ports ClickHouse is listening on:

ss -tlnp | grep clickhouse

Or more detailed:

ss -tlnp | grep $(pidof clickhouse-server)

To check configured ports in the configuration:

cat /etc/clickhouse-server/config.xml | grep -E "port>" | head -20

To check a specific port:

ss -tlnp | grep :8123

Expected port check output:

LISTEN  *:8123  clickhouse-serv  (HTTP)
LISTEN  *:9000  clickhouse-serv  (Native TCP)
LISTEN  *:9004  clickhouse-serv  (MySQL)
LISTEN  *:9005  clickhouse-serv  (PostgreSQL)
LISTEN  *:9009  clickhouse-serv  (Interserver)

Note

Detailed information on ClickHouse configuration and optimization is available in the official developer documentation.

Ordering a server with ClickHouse

To install this software using the API, follow these instructions.


Some of the content on this page was created or translated using AI.

question_mark
Is there anything I can help you with?
question_mark
AI Assistant ×