Skip to main content
The ClickHouse CLI (clickhousectl) is a unified command-line tool for managing ClickHouse Cloud resources and local development with ClickHouse. It also manages ClickHouse Cloud Postgres services and ClickPipes. This page is a reference for the command surface of clickhousectl 0.4.2. Run clickhousectl --version to check the version you have installed, and clickhousectl <command> --help on any command for the full list of flags.

Installation

A chctl alias is also created automatically for convenience. To update an existing installation to the latest version:

Cloud management

Authenticate with ClickHouse Cloud and manage your services directly from the command line.

Authentication

API keys are saved to .clickhouse/credentials.json (project-local, git-ignored). You can also use environment variables:
Credential precedence, from highest to lowest: --api-key/--api-secret flags, project credentials in .clickhouse/credentials.json, environment variables (shell, then .env), OAuth tokens from cloud auth login. OAuth tokens are read-only; write commands (create, delete, start, stop, update, scale) require API key authentication.

Services

Running queries

Run SQL against a Cloud service over HTTP via the Query API — no local clickhouse binary or service password required. Exactly one of --id or --name is required:
With API key authentication, queries run with read and write access. The authenticated key is used directly when the service’s query endpoint already authorizes it; otherwise the first query provisions a query endpoint and a per-service read/write key and stores that key in .clickhouse/credentials.json. Pass --no-auto-enable to fail instead of provisioning. With OAuth, SQL runs as your cloud user with read-only access (SELECT only), and nothing is provisioned. Things to know:
  • service query runs a single statement per request. Multi-statement SQL is rejected by the Query API, whichever way it arrives — --query, --queries-file, or stdin — with Error: SQL error 62: Syntax error (Multi-statements are not allowed). A trailing ; on a single statement is fine. For scripts, run clickhousectl local use latest and use clickhouse client against the service instead.
  • --query and --queries-file are mutually exclusive (exit code 2). Stdin is read only when neither is given. --query never reads stdin, so redirecting or piping data alongside it is a hard error rather than a silent no-op: Error: --query cannot be combined with SQL or data on stdin. Send an INSERT and its data as a single stream instead — printf 'INSERT INTO t FORMAT CSV\n' | cat - data.csv | clickhousectl cloud service query --id <service-id> — or read a whole statement from stdin with --queries-file -.
  • The default output format is PrettyCompact on a terminal and TabSeparated when piped. --json selects JSONEachRow and cannot be combined with --format (exit code 2).
  • A stored Query API key that the endpoint rejects with HTTP 401/403 is never replaced automatically; the CLI reads the key’s management record only to report why. Replace that one credential with clickhousectl cloud service repair-query-key <service-id>, which also deletes the key it replaced. On a running service it exits 0 only once a probe query with the new key succeeds, reported under verification in --json output. If the Query API still rejects the key when the readiness window ends the command exits 1, but the repair stands: do not rerun it, run cloud service query instead.
  • The Query API times out after about 30 seconds; the statement keeps running on the service, but the result is lost. For anything longer, run clickhousectl local use latest to put the standard clickhouse binary on PATH and connect with clickhouse client --host <host> --secure --port 9440 --user default --password <password> instead.

Service endpoints and configuration

--backup-start-time must be exactly on the hour (HH:00) and is validated by the CLI before any API call. It also requires the backup period to be 24 or 48 hours: pass --backup-period-hours 24 or --backup-period-hours 48 in the same command, or have one of those two already stored. Against any other stored period the CLI refuses before calling the API, with Error: the stored backup period is 12 hours, but --backup-start-time requires 24 or 48. --clear-backup-start-time removes a stored start time and lifts that restriction. Combine it with --backup-period-hours to clear the start time and set any period in one call. It conflicts with --backup-start-time.

Backups

To restore a backup, create a new service from it: clickhousectl cloud service create --name restored-service --backup-id <backup-id>.

ClickPipes

Manage ClickPipes for ingesting data into a Cloud service. Most commands take the service ID as the first argument.
Things to know:
  • clickpipe create postgres requires one of --table-mapping <schema.table:target_table> (repeatable, one table per flag) or --table-mapping-json <json>; the two can be combined. The JSON form takes the API’s table mapping object verbatim and is the only way to set excludedColumns, sortingKeys, partitionByExpr, partitionKey and tableEngine. Note that partitionKey partitions the initial snapshot for parallelism and is unrelated to the destination table’s PARTITION BY, which is partitionByExpr. --iam-role is required with --auth IAM_ROLE and rejected with basic auth, and --replication-slot-name is only valid with --replication-mode cdc_only.
  • Postgres CDC settings are applied when the pipe is created: --sync-interval-seconds, --pull-batch-size, --initial-load-parallelism, --snapshot-rows-per-partition, --snapshot-parallel-tables, --allow-nullable-columns, --enable-failover-slots and --delete-on-merge. Only the sync interval and the pull batch size can be changed afterwards; the snapshot and initial-load settings cannot.
  • --role <role> on any clickpipe create subcommand is repeatable and picks the ClickHouse role granted to the pipe’s destination user. It replaces the role that user would otherwise receive: with no --role the user holds clickpipes_system and default_role, and with --role my_role it holds clickpipes_system and my_role. The role must be able to create tables in the destination database — a read-only role makes creation fail with Not enough privileges. The API-reserved names clickpipes and clickpipes_system are rejected.
  • TLS and certificate verification are on by default for Postgres sources. A publicly trusted source chain needs no CA file; for a private or self-signed source CA, pass its PEM bundle with --ca-certificate <path>. For a ClickHouse Cloud Postgres source, fetch that bundle with clickhousectl cloud postgres certs get. Hostname verification uses --host unless --tls-host <hostname> overrides it.
  • For Kafka and Kinesis pipes, --auth is inferred from the credential flags when omitted, and no authentication is sent when no credential flags are given.
  • clickpipe settings covers ingestion settings for streaming (Kafka, Kinesis) and object-storage pipes only, and Kafka-only settings are omitted for non-Kafka pipes. Database CDC pipes (Postgres, MySQL, MongoDB, BigQuery) have no ingestion settings: settings get on one exits 1 and points at clickhousectl cloud clickpipe get <service-id> <clickpipe-id>, which is where their sync interval and pull batch size are reported.
  • A pipe can only use a reverse private endpoint that has reached the Ready status; an AWS PrivateLink endpoint stays in PendingAcceptance until the connection request is accepted in the account that owns the source. Kafka pipes reference the endpoint by ID with --reverse-private-endpoint-id (repeatable); Postgres and MySQL CDC pipes pass one of the endpoint’s dnsNames as --host.
  • Google Cloud Pub/Sub pipes are in limited preview: contact support to enable the feature for your organization before creating one. --service-account-file takes the path to a GCP service account JSON key, or - to read the key from stdin; the key is never accepted inline, so it stays out of process listings and shell history.

Postgres services (beta)

Create and manage ClickHouse Cloud Postgres services.
Things to know:
  • --provider defaults to aws; gcp is also accepted, with GCP machine sizes such as c4-standard-4. --size is validated by the Cloud API rather than by the CLI, so an unsupported size is only rejected on the server.
  • Role changes are eventually consistent, and the API acknowledges promote and switchover before applying them, so exit code 0 alone does not confirm the role changed. Both accept --wait to poll until the target reports the new role, with --wait-timeout <seconds> (default 300) bounding the poll. The previous primary can keep reporting isPrimary=true for minutes afterwards, so confirm with clickhousectl cloud postgres list --filter isPrimary=true that exactly one service is primary.
  • postgres delete works from any state, including running, so the service does not have to be stopped first.

Organizations

API keys

Members and invitations

Activity log

JSON output

Use the --json flag to get JSON-formatted responses from any cloud command:
The org prometheus and service prometheus commands are the exception: they always emit raw Prometheus exposition text and silently ignore --json.

Local development

The CLI also manages local ClickHouse installations, local servers, and Docker-backed local Postgres instances. See the clickhousectl (CLI) page for getting started with local development.
Things to know:
  • local commands are project-scoped: they use the .clickhouse directory under the exact current working directory and never search parent directories. Change to the project root before running them.
  • clickhousectl local use also symlinks ~/.local/bin/clickhouse, which makes the standard subcommands such as clickhouse client, clickhouse benchmark, and clickhouse format available directly. Pass --no-global to skip the symlink.
  • local remove takes an exact installed version. It refuses to remove a version that a running server uses in any project, or one that is the current default; --force stops those servers and clears the default and the global symlink.
  • With no name, local server stop stops default if it exists and otherwise the sole known server; with several non-default servers it asks for a name. local server remove with no name only ever selects an existing default — it never guesses a custom server.
  • local client accepts -v/--version to pick an installed client version in direct host/port mode, repeats -q for multiple queries, and takes several paths for --queries-file. Combining --query and --queries-file is a usage error.
  • local postgres start blocks until PostgreSQL accepts connections, bounded by --wait-timeout seconds (default 60, maximum 600). With --port omitted it uses 5432 if free and otherwise auto-selects a port; an explicitly requested port that is already occupied is rejected.

Other commands

Requirements

  • macOS (aarch64, x86_64) or Linux (aarch64, x86_64)
  • Cloud commands require a ClickHouse Cloud API key for write access; OAuth login is read-only
  • clickhousectl local postgres requires Docker
Last modified on September 2, 2026