CLI tool to execute SQL queries against a ClickHouse cluster with checkpointing and progress monitoring
Project description
clickhouse-query-runner
A CLI tool that executes SQL queries from a file against a ClickHouse cluster, running queries in parallel with round-robin distribution across nodes, checkpointing progress in Valkey, and providing a rich terminal UI showing both batch-level and query-level progress.
Features
- Parallel query execution with configurable concurrency
- Round-robin distribution across cluster nodes
- Checkpoint/resume via Valkey for fault tolerance
- Rich progress display with per-query monitoring
- Dry-run mode for query validation
Installation
uvx (Recommended)
Run directly without installing using uv:
uvx clickhouse-query-runner queries.sql
Or install as a persistent tool:
uv tool install clickhouse-query-runner
clickhouse-query-runner queries.sql
Docker
Build the image:
docker build -t clickhouse-query-runner .
Run with environment variables and a local SQL file:
docker run --rm \
-e CLICKHOUSE_HOST=clickhouse.example.com \
-e CLICKHOUSE_USER=default \
-e CLICKHOUSE_PASSWORD=secret \
-e CLICKHOUSE_DATABASE=mydb \
-v $(pwd)/queries.sql:/app/queries.sql \
clickhouse-query-runner /app/queries.sql
Pass additional options after the image name:
docker run --rm \
-e CLICKHOUSE_HOST=node1.example.com,node2.example.com \
-e CLICKHOUSE_USER=default \
-e CLICKHOUSE_PASSWORD=secret \
-e CLICKHOUSE_DATABASE=mydb \
-e VALKEY_URL=redis://valkey:6379/0 \
-v $(pwd)/queries.sql:/app/queries.sql \
clickhouse-query-runner --concurrency 4 /app/queries.sql
To use with docker compose, add the service to your compose.yaml:
services:
query-runner:
build: .
environment:
CLICKHOUSE_HOST: clickhouse
CLICKHOUSE_USER: default
CLICKHOUSE_PASSWORD: secret
CLICKHOUSE_DATABASE: mydb
VALKEY_URL: redis://valkey:6379/0
volumes:
- ./queries.sql:/app/queries.sql
command: ["/app/queries.sql"]
depends_on:
- clickhouse
- valkey
Development
git clone https://github.com/gmr/clickhouse-query-runner.git
cd clickhouse-query-runner
uv sync --group dev
To run the tool during development:
uv run clickhouse-query-runner queries.sql
Quick Start
# Set connection environment variables
export CLICKHOUSE_HOST=clickhouse.example.com
export CLICKHOUSE_USER=default
export CLICKHOUSE_PASSWORD=secret
export CLICKHOUSE_DATABASE=mydb
# Run queries from a file
uvx clickhouse-query-runner queries.sql
# With explicit options
uvx clickhouse-query-runner \
--host node1.example.com,node2.example.com \
--concurrency 4 \
--valkey-url redis://valkey:6379/0 \
queries.sql
Command Reference
| Option | Env Var | Default | Description |
|---|---|---|---|
--host |
CLICKHOUSE_HOST |
(required) | ClickHouse hostname(s), comma-separated |
--port |
CLICKHOUSE_PORT |
9440 |
ClickHouse server port |
--database |
CLICKHOUSE_DATABASE |
(required) | Database name |
--user |
CLICKHOUSE_USER |
(required) | Username |
--password |
CLICKHOUSE_PASSWORD |
(required) | Password |
--secure |
CLICKHOUSE_SECURE |
true |
Use secure connection |
--concurrency |
2 |
Max parallel queries | |
--run-id |
(auto) | Override run ID | |
--valkey-url |
VALKEY_URL |
redis://localhost:6379/0 |
Valkey URL |
--checkpoint-ttl |
604800 |
Checkpoint TTL in seconds | |
--poll-interval |
0.5 |
Progress poll interval | |
--cancel-on-failure |
false |
Cancel in-flight on failure | |
--dry-run |
false |
Parse without executing | |
--reset |
false |
Clear checkpoints and exit | |
--verbose |
false |
Debug logging |
How It Works
- Parse - Split the SQL file into individual statements
- Checkpoint - Load completed query hashes from Valkey, skip already-done queries
- Dispatch - Send queries to nodes via round-robin, up to concurrency limit
- Monitor - Poll
system.processesfor per-query progress - Record - Checkpoint each completed query to Valkey
Architecture
src/clickhouse_query_runner/
├── __init__.py # Package initialization
├── cli.py # Entry point, arg parsing
├── runner.py # Core async execution engine
├── checkpoint.py # Valkey checkpoint management
├── parser.py # SQL file parsing
├── progress.py # Rich progress display
└── settings.py # Pydantic settings model
Code Quality
uv run ruff check src/
uv run ruff format --check src/
License
BSD 3-Clause License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clickhouse_query_runner-1.1.0.tar.gz.
File metadata
- Download URL: clickhouse_query_runner-1.1.0.tar.gz
- Upload date:
- Size: 52.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
028cf360d5f0c60e5f767add815e393491e16c4ca0624d63881a88ec191151ad
|
|
| MD5 |
723ba857c6e37760cd8ab836488a08a6
|
|
| BLAKE2b-256 |
6553968eae08aa07b21e0edc2a44ae4a69aea240b222b5b217ab3c4ebe4e11f9
|
Provenance
The following attestation bundles were made for clickhouse_query_runner-1.1.0.tar.gz:
Publisher:
publish.yaml on gmr/clickhouse-query-runner
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_query_runner-1.1.0.tar.gz -
Subject digest:
028cf360d5f0c60e5f767add815e393491e16c4ca0624d63881a88ec191151ad - Sigstore transparency entry: 933398175
- Sigstore integration time:
-
Permalink:
gmr/clickhouse-query-runner@d473897819cb620aee924f58c68de3404ff80fd1 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/gmr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@d473897819cb620aee924f58c68de3404ff80fd1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file clickhouse_query_runner-1.1.0-py3-none-any.whl.
File metadata
- Download URL: clickhouse_query_runner-1.1.0-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae8abc3f33691d25e5e8a1c422d9d2a737ee21aec0bef74703a3849e9c6f1e78
|
|
| MD5 |
6ff5ac1e2497472ca877ca66c63a8d66
|
|
| BLAKE2b-256 |
12020afd7731a8806d828326df51cf643a487901830b86b3f437ce5919cd9044
|
Provenance
The following attestation bundles were made for clickhouse_query_runner-1.1.0-py3-none-any.whl:
Publisher:
publish.yaml on gmr/clickhouse-query-runner
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clickhouse_query_runner-1.1.0-py3-none-any.whl -
Subject digest:
ae8abc3f33691d25e5e8a1c422d9d2a737ee21aec0bef74703a3849e9c6f1e78 - Sigstore transparency entry: 933398216
- Sigstore integration time:
-
Permalink:
gmr/clickhouse-query-runner@d473897819cb620aee924f58c68de3404ff80fd1 -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/gmr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@d473897819cb620aee924f58c68de3404ff80fd1 -
Trigger Event:
release
-
Statement type: