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
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
.clickhouse/credentials.json (project-local, git-ignored). You can also use environment variables:
--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 localclickhouse binary or service password required. Exactly one of --id or --name is required:
.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 queryruns a single statement per request. Multi-statement SQL is rejected by the Query API, whichever way it arrives —--query,--queries-file, or stdin — withError: SQL error 62: Syntax error (Multi-statements are not allowed). A trailing;on a single statement is fine. For scripts, runclickhousectl local use latestand useclickhouse clientagainst the service instead.--queryand--queries-fileare mutually exclusive (exit code 2). Stdin is read only when neither is given.--querynever 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 anINSERTand 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
PrettyCompacton a terminal andTabSeparatedwhen piped.--jsonselectsJSONEachRowand 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 underverificationin--jsonoutput. 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, runcloud service queryinstead. - 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 latestto put the standardclickhousebinary onPATHand connect withclickhouse 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
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.clickpipe create postgresrequires 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 setexcludedColumns,sortingKeys,partitionByExpr,partitionKeyandtableEngine. Note thatpartitionKeypartitions the initial snapshot for parallelism and is unrelated to the destination table’sPARTITION BY, which ispartitionByExpr.--iam-roleis required with--auth IAM_ROLEand rejected with basic auth, and--replication-slot-nameis 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-slotsand--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 anyclickpipe createsubcommand 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--rolethe user holdsclickpipes_systemanddefault_role, and with--role my_roleit holdsclickpipes_systemandmy_role. The role must be able to create tables in the destination database — a read-only role makes creation fail withNot enough privileges. The API-reserved namesclickpipesandclickpipes_systemare 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 withclickhousectl cloud postgres certs get. Hostname verification uses--hostunless--tls-host <hostname>overrides it. - For Kafka and Kinesis pipes,
--authis inferred from the credential flags when omitted, and no authentication is sent when no credential flags are given. clickpipe settingscovers 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 geton one exits 1 and points atclickhousectl 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
Readystatus; an AWS PrivateLink endpoint stays inPendingAcceptanceuntil 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’sdnsNamesas--host. - Google Cloud Pub/Sub pipes are in limited preview: contact support to enable the feature for your organization before creating one.
--service-account-filetakes 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.--providerdefaults toaws;gcpis also accepted, with GCP machine sizes such asc4-standard-4.--sizeis 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
promoteandswitchoverbefore applying them, so exit code 0 alone does not confirm the role changed. Both accept--waitto poll until the target reports the new role, with--wait-timeout <seconds>(default 300) bounding the poll. The previous primary can keep reportingisPrimary=truefor minutes afterwards, so confirm withclickhousectl cloud postgres list --filter isPrimary=truethat exactly one service is primary. postgres deleteworks from any state, includingrunning, 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:
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.localcommands are project-scoped: they use the.clickhousedirectory under the exact current working directory and never search parent directories. Change to the project root before running them.clickhousectl local usealso symlinks~/.local/bin/clickhouse, which makes the standard subcommands such asclickhouse client,clickhouse benchmark, andclickhouse formatavailable directly. Pass--no-globalto skip the symlink.local removetakes 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;--forcestops those servers and clears the default and the global symlink.- With no name,
local server stopstopsdefaultif it exists and otherwise the sole known server; with several non-default servers it asks for a name.local server removewith no name only ever selects an existingdefault— it never guesses a custom server. local clientaccepts-v/--versionto pick an installed client version in direct host/port mode, repeats-qfor multiple queries, and takes several paths for--queries-file. Combining--queryand--queries-fileis a usage error.local postgres startblocks until PostgreSQL accepts connections, bounded by--wait-timeoutseconds (default 60, maximum 600). With--portomitted 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 postgresrequires Docker