ClickHouse is a column-oriented, open-source database for analytics. It is designed to count, group, and analyze millions or billions of rows in fractions of a second. Typical data includes logs, metrics, website clicks, or events from a game, such as logins, kills, or purchases. You write queries in SQL.
In this guide, we’ll show you two ways to get started: the easy way, as a One-Click App, which gets ClickHouse running in a few minutes with an automatically generated username and password, and a manual installation with Docker Compose via the console. Then you’ll learn how to secure the ports, create tables, set up dedicated users for applications, connect tools such as Grafana, and back up your data.
Running your own ClickHouse server is worthwhile if:
- you want to store and analyze many events, such as game server player statistics, bot commands, or orders, and keep queries like “kills per player per day” fast even with millions of rows.
- you want to collect logs or metrics centrally and search through them later with SQL.
- you’re building dashboards, for example with Grafana, and need a fast data source.
- a piece of software requires ClickHouse, such as an analytics or observability tool that you run yourself.
- you want to learn or test ClickHouse without paying a cloud service for each query or for storage.
ClickHouse is less suitable as a database for a regular application that often changes or deletes individual rows, such as user accounts, shopping carts, or bot settings. A traditional database such as PostgreSQL or MariaDB is a better choice for that.
| ClickHouse | PostgreSQL | |
|---|---|---|
| Strength | Analyzing very large numbers of rows (counting, summing, grouping) | Many small read and write operations on individual records |
| Changing data | Possible, but slow and intended for occasional corrections | Routine, with transactions |
| Typical data | Logs, metrics, events, statistics | Users, orders, settings |
| Storage requirements | Highly compressed, often a fraction of the raw data | Normal |
| RAM | From 2 GB; significantly more for larger volumes of data | From 256 MB |
You can also use both: your application stores its data in PostgreSQL and writes events to ClickHouse as well. See Set Up PostgreSQL on a Linux Server to learn how to set up PostgreSQL.
With your VPS One-Click Apps, you can start a standalone ClickHouse server running LTS version 26.8. During installation, the app creates a database, a user with a randomly generated name, and a long, random password. The default user default, which has no password, is disabled. Data and logs are stored in persistent volumes on your VPS.
- A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See VPS: One-Click Apps for instructions.
- At least 2 vCPU cores, 2 GB RAM, and 5 GB of storage. We recommend 4 vCPU cores, 8 GB RAM, and 50 GB of storage. Your actual requirements depend on the amount of data and your queries.
- Ports
8123and9000must be available on your VPS. Otherwise, choose different ports during installation.
- Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.
- Search for “ClickHouse” in the App catalog and click Install app next to ClickHouse.
- Under App name, you can enter a custom name, such as “ClickHouse Statistics.”
- You can adjust three values under App configuration, but you don’t need to:
| Field | Default | Description |
|---|---|---|
CLICKHOUSE_DB | app | Name of the database created during installation |
CLICKHOUSE_HTTP_PORT | 8123 | HTTP interface port, used by most tools and programming languages |
CLICKHOUSE_NATIVE_PORT | 9000 | Port for ClickHouse’s own protocol, for example, for clickhouse-client |
- Click Queue installation. The app will show as Online after one to two minutes.
You don’t need a custom domain. ClickHouse is accessible through your VPS IP address. The app card shows both addresses under Connection, for example, 123.123.123.123:8123 and 123.123.123.123:9000.
The app generates a username and password during installation. You can find them in the app settings (gear icon) under App environment > Automatically generated values. Click the eye icon to display a value or the copy icon to copy it.
| Value | Description |
|---|---|
SERVICE_USER_CLICKHOUSE | Username, a short random string |
SERVICE_PASSWORD_CLICKHOUSE | This user’s password, consisting of 32 random characters |
This user has full permissions. It can create and delete databases and tables, and manage other users. So don’t share these credentials with applications or dashboards. Instead, create a separate user for each application, as described in “Create users for applications.”
CLICKHOUSE_DB only takes effect on the first start. Changing it later won’t create a new database. You can create additional databases with CREATE DATABASE.
The quickest way to test ClickHouse is directly on the server. Connect to your VPS via SSH and open the app container’s command-line client:
docker ps --filter name=clickhouse-
docker exec -it CONTAINER_NAME sh -c 'clickhouse-client --user "$CLICKHOUSE_USER" --password "$CLICKHOUSE_PASSWORD"'
The first command shows you the container name, which starts with clickhouse-. The second command gets the username and password from the app, so you don’t have to type them in. Run SELECT version(); to see the version currently running, and exit to close the client.
From outside the server, connect to ClickHouse through the HTTP interface. Send a query as text to port 8123:
curl -u DB_USER:DB_PASSWORD 'http://SERVER_IP:8123/' --data-binary 'SELECT version()'
The app publishes both ports on all of your VPS’s addresses. Anyone on the internet can reach them and try passwords, and the connection is not encrypted because the app doesn’t configure TLS. No one can access your data without a valid password, but you should still restrict the ports immediately after installation to the IP addresses that actually need to connect.
The firewall on the VPS itself (ufw) won’t help here: ports published by Docker are accessible even if ufw blocks them. Instead, use the Network firewall in the ZapX dashboard. It filters traffic before it reaches your VPS:
- Open your VPS in the ZapX dashboard and go to the Network firewall tab. Make sure Firewall active is turned on.
- Click Add rule. Set Direction to
IN, Action toACCEPT, and Service template to Custom. Set Protocol totcpand Destination port to8123. - Under Source, enter the IP address that’s allowed to connect, such as your web server’s or game server’s IP address, and click Create. If that address also needs port
9000, create a second rule for it. - Then create a rule for each port with Direction set to
IN, Action set toDROP, Protocol set totcp, and the port set as the Destination port. Leave Source empty. - Check the order under Custom rules: the first matching rule takes precedence, so the
ACCEPTrules must be above theDROPrules. New rules are added to the end of the list; use the arrows to move them.
Connections from apps on the same VPS don’t pass through the Network Firewall and will continue to work. For more on ports and firewalls, see VPS: Open Ports and Manage the Firewall on Linux.
You don’t need to open a port to connect from your own PC. Open an SSH tunnel with ssh -L 8123:127.0.0.1:8123 root@SERVER_IP and connect your program to localhost:8123. This encrypts the connection.
ClickHouse includes a simple query interface. With the SSH tunnel running, open http://localhost:8123/play in your browser, click the key icon in the top-right corner, and enter your username and password. Then write SQL in the input field and run the query by clicking Run or pressing Ctrl + Enter.
The page is also accessible directly at http://SERVER_IP:8123/play. However, your password and data will then be sent over the internet unencrypted, so it’s better to use the tunnel.
- Updates: Open the app settings (gear icon) > App update and click Check for updates. If a new app version is available, install it by clicking Apply update. Your data will be retained.
- Back up: A VPS backup in the Backups tab also backs up the volumes. You can also back up individual databases with the SQL command
BACKUP, as described under “Back up your data.” - Uninstall: Under App actions > Uninstall app, you can also delete the data volumes. This permanently deletes all databases. Back them up first.
The rest of this guide describes a manual installation of ClickHouse with Docker Compose via the console, for example, on a server without One-Click Apps. The commands are written for Debian and Ubuntu. Unlike the One-Click App, ClickHouse initially listens only on the server itself.
| Minimum | Recommended | |
|---|---|---|
| CPU | 2 vCPU cores | 4 vCPU cores |
| RAM | 2 GB | 8 GB |
| Storage | 5 GB free (image is just over 1 GB) | 50 GB, depending on the amount of data |
These values apply to small to medium data volumes. By default, ClickHouse uses up to 90 percent of the available RAM. The manufacturer recommends significantly more RAM for large data volumes. You’ll also need Docker with the Compose plugin, as described in Set Up Docker on a Linux Server, and SSH access; see VPS: First Connection via SSH.
ClickHouse doesn’t need an open port for this setup because it’s bound only to 127.0.0.1. Open only SSH in ufw:
sudo apt install -y ufw
sudo ufw allow OpenSSH
sudo ufw enable
Ports that Docker publishes on all addresses with ports: are accessible from outside even if ufw blocks them. So leave the 127.0.0.1: prefix on the ports in the Compose file unless you need external access.
Create a folder and create a .env file in it with a random password:
sudo mkdir -p /opt/clickhouse
cd /opt/clickhouse
echo "CLICKHOUSE_PASSWORD=$(openssl rand -hex 24)" | sudo tee .env > /dev/null
sudo chmod 600 .env
sudo nano compose.yaml
Add the following content to compose.yaml:
services:
clickhouse:
image: clickhouse/clickhouse-server:26.8.37.168-alpine
container_name: clickhouse
restart: unless-stopped
environment:
CLICKHOUSE_USER: admin
CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD}
CLICKHOUSE_DB: app
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
ports:
- "127.0.0.1:8123:8123"
- "127.0.0.1:9000:9000"
ulimits:
nofile:
soft: 262144
hard: 262144
volumes:
- clickhouse-data:/var/lib/clickhouse
- clickhouse-logs:/var/log/clickhouse-server
healthcheck:
test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8123/ping || exit 1"]
interval: 10s
timeout: 5s
retries: 10
start_period: 20s
volumes:
clickhouse-data:
clickhouse-logs:
The important lines:
image: clickhouse/clickhouse-server:26.8.37.168-alpineis the same version as the One-Click App. The fixed version number prevents a restart from unexpectedly downloading a new version.CLICKHOUSE_USERandCLICKHOUSE_PASSWORDcreate theadminuser and disable thedefaultuser, which would otherwise be able to log in without a password. The password comes from.env.CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1allowsadminto create additional users and grant permissions using SQL.127.0.0.1:8123and127.0.0.1:9000make ClickHouse accessible only from the server itself.ulimitsincreases the number of open files. ClickHouse recommends this value because it opens many files at the same time.- The
clickhouse-datavolume contains all databases and users created with SQL;clickhouse-logscontains the server’s log files.
Start ClickHouse and check its status:
sudo docker compose up -d
sudo docker compose ps
After about 20 seconds, the STATUS column should show healthy.
Open the command-line client in the container:
sudo docker exec -it clickhouse sh -c 'clickhouse-client --user admin --password "$CLICKHOUSE_PASSWORD"'
Run SHOW DATABASES; to see the app database, and exit to close the client. You can access the Play interface from your PC through the SSH tunnel described in the “Secure access” tip; the password is in .env.
If applications on other servers need to connect, a reverse proxy with TLS is better than opening port 8123. To do this, create a subdomain such as clickhouse.example.com that points to your server, and configure nginx to forward it to the HTTP interface:
server {
listen 80;
server_name clickhouse.example.com;
location / {
proxy_pass http://127.0.0.1:8123;
proxy_set_header Host $host;
proxy_read_timeout 300s;
client_max_body_size 100m;
}
}
proxy_read_timeout allows longer queries, and client_max_body_size allows larger data imports. See VPS: Set Up a Reverse Proxy with nginx on Linux and VPS: Create an SSL Certificate (Let's Encrypt) for Linux Servers to learn how to set up nginx and issue the certificate. Applications can then connect to https://clickhouse.example.com on port 443. ClickHouse’s own protocol on port 9000 doesn’t go through nginx. If you need external access to it, open the port and restrict it to fixed IP addresses.
ClickHouse backs up databases with the SQL command BACKUP. The File destination writes the backup to the /var/lib/clickhouse/backups/ folder in the volume:
BACKUP DATABASE app TO File('app-2026-01-31');
Each backup needs a new name. To download it from the server, copy it out of the container:
sudo mkdir -p /root/backups
sudo docker cp clickhouse:/var/lib/clickhouse/backups/app-2026-01-31 /root/backups/
For the One-Click App, replace clickhouse with the app’s container name. Restore a backup under a new name and check it before replacing the old database:
RESTORE DATABASE app AS app_restore FROM File('app-2026-01-31');
Download backups from the server regularly, for example, via SFTP. A backup stored only on the same server won’t help if the disk fails.
Enter the new version number for image in compose.yaml and restart:
cd /opt/clickhouse
sudo nano compose.yaml
sudo docker compose pull
sudo docker compose up -d
Updates within an LTS version such as 26.8 are low-risk. Before upgrading to a new version, read the changelog and create a backup first. LTS versions receive bug fixes for one year.
These steps are the same for the One-Click App and the manual installation.
In ClickHouse, you usually create tables with the MergeTree engine. The ORDER BY clause is important: ClickHouse stores data in this order and reads only the necessary parts for matching queries. Choose the columns that you filter by most often:
CREATE TABLE app.events
(
ts DateTime,
player String,
action LowCardinality(String),
value UInt32
)
ENGINE = MergeTree
ORDER BY (action, ts);
LowCardinality(String) saves space in columns with few distinct values, such as join or kill. Add data with INSERT, ideally in batches of many rows rather than one row at a time. A typical analysis query looks like this:
SELECT action, count() AS events, round(avg(value), 1) AS avg_value
FROM app.events
GROUP BY action
ORDER BY events DESC;
Create a separate user for each application and give it only the permissions it needs. A dashboard, for example, only needs read access:
CREATE USER grafana_ro IDENTIFIED BY 'CHANGE_ME' HOST ANY;
GRANT SELECT ON app.* TO grafana_ro;
Replace CHANGE_ME with a long, random password. If the application also needs to write, grant it INSERT as well. To restrict a user to a fixed IP address, use HOST IP '203.0.113.10' instead of HOST ANY. Users created with SQL are stored in the data volume and persist through restarts and app updates. Set a new password with ALTER USER grafana_ro IDENTIFIED BY 'NEW_PASSWORD';.
- Grafana: Install the ClickHouse data source plugin in Grafana and enter the server, port
8123(HTTP protocol) or9000(Native), and a read-only user. See Set Up Grafana on a Linux Server to learn how to run Grafana on your VPS. - Programming languages: Official clients are available for Python, Node.js, Go, Java, and others. Many use the HTTP interface on port
8123; some, such as the Go client, also use port9000. - Database tools: Tools such as DBeaver connect through the JDBC driver on port
8123. Use the SSH tunnel to connect from your PC.
If your application is running on the same VPS, it connects using the VPS IP address. For information about other database systems such as MariaDB, Redis, or MongoDB, see the overview Set Up Databases on a Linux Server.
- No encryption by default: The One-Click App doesn’t configure TLS. For internet access, use an SSH tunnel or restrict the ports to fixed IP addresses.
- No management interface: The Play interface only runs SQL. You manage users, tables, and permissions with SQL.
- A single server: The app runs ClickHouse without replication or a cluster. If the VPS goes down, the database won’t be accessible.
- High memory usage for large queries: Queries across very large numbers of rows or with large
GROUP BYresults need a lot of RAM. If there isn’t enough, ClickHouse stops the query and returns an error.
With ClickHouse, you analyze logs and statistics in a fast analytics database on your own server and back up your data with BACKUP. Next, the guide Set Up Grafana on a Linux Server shows you how to visualize your ClickHouse data in dashboards in your browser.
If you have any other questions or need help, our support team is available every day! 🙂
