By Raeed Asif and Anish Singh Walia
ClickHouse is an open-source columnar database management system that excels in high-performance OLAP queries and real-time analytics. However, scaling up data storage for ClickHouse can be challenging, especially as the volume of data grows. One efficient solution is to use tiered storage, which allows you to offload infrequently accessed data to a more cost-effective storage system while keeping frequently accessed data on faster, more expensive storage. Clickhouse supports various storage backends for data, including both local disks and remote options like DigitalOcean Spaces. When managing large volumes of data, itβs common to use multiple storage devices.
DigitalOcean Spaces is an object storage service that can be integrated with ClickHouse as a tier in its tiered storage architecture. This tutorial will guide you through the steps required to configure DigitalOcean Spaces as a tiered storage option for your ClickHouse cluster.
In this tutorial, we will set up a simple Go application that sends batch logs to ClickHouse. Initially, the logs will be stored in hot storage (the default disk, also known as local), and then they will be transferred to the cold storage (for example, an S3 based storage like DO Spaces) after a specified interval of 2 minutes.
Before starting, make sure you have the following:
Log in to your DigitalOcean Cloud account and create a new Space (bucket). This bucket will serve as your tiered storage for less frequently accessed data.
At this point, your bucket is created and ready for integration with ClickHouse.
To start, create a folder and name it clickhouse
.
Create a Dockerfile under this folder and replace the placeholders for {YOUR\_AWS\_ACCESS\_KEY\_ID}
and {YOUR\_AWS\_SECRET\_ACCESS\_KEY}
with your access Key and secret Key respectively.
access_key_id
and secret_access_key
: These are your DigitalOcean Spaces credentials.Next, configure ClickHouse to use DigitalOcean Spaces as a tier in its storage system. This involves adding the storage_configuration to the config.xml
file in your ClickHouse installation.
To use a Spaces bucket as a storage disk, it must first be declared in the ClickHouse configuration file. You can either modify the existing config.xml or, preferably, add a new file under the conf.d directory, which will later be merged into config.xml.
Create a file called storage.xml
:
This section configures a remote disk (the DigitalOcean Space) that ClickHouse can use to store less frequently accessed data.
Note: Replace the placeholders for {YOUR_S3_SPACES_BUCKET_URL}, with your endpoint URL.
endpoint
: This is the URL of the DigitalOcean region where your Space is located.Now, create a table in ClickHouse that utilizes tiered storage. You can specify multiple storage policies to define which data is stored on local disks and which is stored on remote (Spaces) disks.
Define a storage policy that moves older data to DigitalOcean Spaces after a certain period:
default
: This represents the local disk storage where recent or frequently accessed data is stored.s3
: The remote storage (DigitalOcean Spaces) where older data is offloaded.This setup ensures that new data is written to the local disk and older data is automatically moved to DigitalOcean Spaces.
To start your clickhouse server simply run:
8123
: This is the HTTP port used for communicating with ClickHouse through the HTTP interface. (http://localhost:8123/play). You can use this port to run SQL queries via a browser or through command-line tools like curl or Postman. Itβs often used for web applications or clients that interact with ClickHouse over HTTP.9000
: This is the TCP port, the main port for ClickHouse clients and servers to communicate with each other using the ClickHouse native protocol.Ref
: https://clickhouse.com/docs/en/guides/sre/network-portsVerify using:
In a new folder create a file called main.go
:
Install the package dependencies:
Run the app:
To start your clickhouse client simply run:
Verify logs in your ClickHouse cluster:
When examining the storage disk for this log entry, we can see that it is stored on the default disk (local) - also known as hot storage.
After the two-minute interval specified in the CREATE TABLE
query, you can verify that these logs have been moved to S3 disks (remote/Spaces bucket) β also referred to as cold storage.
We can also see in the DigitalOcean Cloud UI that our bucket now contains some data:
By following this guide, you have successfully set up DigitalOcean Spaces as a tiered storage option for ClickHouse. This setup allows you to optimize storage costs and performance by offloading less frequently accessed data to cost-effective object storage while keeping high-performance storage for active data.
Tiered storage with ClickHouse and DigitalOcean Spaces is a powerful solution for managing growing datasets without compromising on query performance.
All this code can be found at this Github repo.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!