Skip to content

Connect SPSync to ClickHouse

This guide covers ClickHouse Cloud and ClickHouse you run yourself. SPSync uses one destination kind, clickhouse, and the same connection string shape for both.

  • ClickHouse, reachable from the machine that runs SPSync.
  • Nothing to install on that machine. SPSync includes the client libraries.
  • Rights to create a database and a user.

ClickHouse has no schemas. Every table sits directly in one database. SPSync turns dataset_name into a table-name prefix instead, joined by ___, so a list table ks_tasks with dataset_name=sync becomes sync___ks_tasks. Several replications can share one database that way.

Create the database and a least-privilege user

Section titled “Create the database and a least-privilege user”

Run spsync clickhouse-grants to print the script. It executes nothing; you run the output as a ClickHouse administrator (a user with access management rights).

Terminal window
spsync clickhouse-grants --auth-mode password --account spsync_loader --database spsync
CREATE DATABASE IF NOT EXISTS `spsync`;
CREATE USER IF NOT EXISTS `spsync_loader` IDENTIFIED WITH sha256_password BY '<choose-a-long-random-password>';
GRANT SELECT, INSERT, ALTER, CREATE TABLE, CREATE VIEW, DROP TABLE, DROP VIEW, TRUNCATE ON `spsync`.* TO `spsync_loader`;
GRANT SELECT ON INFORMATION_SCHEMA.* TO `spsync_loader`;
GRANT SELECT ON information_schema.* TO `spsync_loader`;

The user has rights on the one database and none on any other. It cannot create users, grant rights or read other databases. SPSync needs ALTER because it issues soft-delete and upsert statements as ClickHouse mutations, and the information schema because the loader reads column metadata from it. SPSync’s automated tests run the real loader as this user against ClickHouse 24.10: it loads, upserts, creates tables and deletes rows in its database, and is refused when it creates a table in another database or a user. On ClickHouse Cloud, run the same statements in the SQL console.

SPSync uses two ports on the same host:

Port Used for
9440 Native protocol with TLS (9000 without TLS). Queries.
8443 HTTPS interface. Loading data, soft deletes and Test connection.

Those are the ClickHouse Cloud defaults. A self-hosted server listens for HTTP on 8123 by default, not 8443, so give SPSync the port with http_port (below).

  • ClickHouse Cloud: under the service’s Security settings, add the address SPSync connects from to the IP access list.
  • Self-hosted: allow both ports in the host firewall and security group, and set the server’s listen_host so it accepts outside connections.

Add secure=1 to the connection string. It turns on TLS for both ports and matches ClickHouse Cloud and any self-hosted server that terminates TLS. A local test server without TLS uses secure=0 and port 9000.

clickhouse://spsync_loader:PASSWORD@HOST:9440/spsync?secure=1

For a self-hosted server whose HTTP port is not 8443, add http_port:

clickhouse://spsync_loader:PASSWORD@HOST:9440/spsync?secure=1&http_port=8123

A private CA or a client certificate. On the Destination screen, paste the PEM into CA certificate bundle, and for a client certificate paste Client certificate and Client private key (an unencrypted PEM key). If you reach the server by an address its certificate does not name, put the name the certificate carries in Certificate name to check. SPSync applies the settings to both channels it uses, the native port and the HTTP port, and Test connection checks both when TLS settings are present. SPSync keeps the PEM as a stored secret: in the operating system keychain on the desktop app, as a Key Vault reference in the Azure edition, and it never shows it again after you save. At run time SPSync writes it to an owner-only temporary file because the database driver needs a path, and removes the file when the run ends. Leave verify, ca_certs, certfile, keyfile and server_hostname out of the string: SPSync refuses a string that sets them as well.

Clearing Verify the server certificate turns checking off. The connection stays encrypted but SPSync no longer checks who it is talking to. Use it only while you fix the certificate. SPSync logs a destination_tls_verification_disabled warning on every run, Test connection reports “connected (warning: …)” and spsync doctor prints a WARNING.

This is a preview. SPSync’s automated tests run the real ClickHouse HTTP client against a local TLS server with a throw-away CA, and check that the native driver receives the same settings. It has not been run against ClickHouse Cloud or a self-hosted server with a private CA. spsync doctor prints a destination-tls line with the trust mode. The line also shows the server certificate’s subject and expiry date.

Each run logs one destination.connected_as line naming the ClickHouse user the load ran as, so you can confirm the least-privilege user from spsync clickhouse-grants is the one in use.

If the database is reachable only through a jump host, SPSync can open an SSH tunnel to that host for each run, forward a local port to the database, and close the tunnel when the run ends. This is a preview: it is tested against a real SSH server in the SPSync test suite, but it has not been run against a live ClickHouse server behind a customer’s jump host. Forward the native protocol port, 9000 (9440 with secure=1).

  1. On a machine you trust, read the jump host’s host key fingerprint. This prints a line containing SHA256: followed by 43 characters:

    Terminal window
    ssh-keyscan -t ed25519 bastion.example.com | ssh-keygen -lf -

    SPSync asks the server for an ed25519 host key first, then ECDSA, then RSA, so pin the fingerprint of the first of those the server has. If you are unsure, run ssh-keyscan without -t and pin every fingerprint it prints.

  2. In the connection string, give the database’s address as the jump host sees it, for example ch.internal:9000. SPSync rewrites the address to the local port while the tunnel is open; the string you save is not changed.

  3. On the Destination screen, tick Reach the database through an SSH bastion and fill in the host, port, user and fingerprint, then paste a private key (and its passphrase) or enter a password. The key is kept in the computer’s keychain and is not shown again.

  4. In the CLI, add an ssh_tunnel block to the destination in the config file, as below. export-config does not write it. With the admin MCP server, the assistant can set the host, port, user and fingerprint, and you enter the key or password on the secure entry page.

destination:
kind: clickhouse
connection_string_env: SPSYNC_DSN
ssh_tunnel:
host: bastion.example.com
port: 22 # optional, 22 by default
user: spsync
host_key_fingerprints:
- "SHA256:<the fingerprint from step 1>"
private_key_env: keychain:spsync/bastion-key # or file:/path/to/key, or an environment variable name
# passphrase_env: BASTION_KEY_PASSPHRASE # only if the key has one
# password_env: BASTION_PASSWORD # instead of private_key_env

The host key is always checked. If the jump host presents a key that is not in host_key_fingerprints, SPSync stops before it sends any credential, and there is no setting that turns the check off. Keep a second fingerprint in the list while you rotate the host key. SPSync ignores ~/.ssh/config, known_hosts and any SSH agent: it uses exactly what is configured here. The key, its passphrase and the password are never written to the config file or to the control store; they are stored as keychain or Key Vault references, and a plain environment variable name works for the CLI.

Test connection and spsync doctor open the same tunnel as a run and say so in their result: connected through SSH tunnel, then the user, host and port, and host key pinned. The read-only MCP server (spsync mcp serve) opens its own connection to the replica and does not go through the tunnel.

SSH encrypts the hop to the jump host. With secure=1 the driver checks the server certificate against the host in the connection string, which the tunnel changes to the loopback address, so the check fails unless the certificate lists 127.0.0.1. SPSync does not switch verification off for you.

  • User name and password in the connection string. URL-encode any @, : or / in the password.
  • A TLS client certificate, presented in addition to the user name and password (see “A private CA or a client certificate” above). The connection string always carries a password, so a certificate-only user (one created with IDENTIFIED WITH ssl_certificate) is not supported: SPSync’s loading path uses ClickHouse’s native protocol driver, which cannot log in by certificate alone.

SPSync accepts no other credential. A ClickHouse Cloud API key is not accepted: those keys manage services through the Cloud API and cannot run SQL, so create a SQL user with a password in the console. There is no Entra, IAM or single sign-on mode.

  • Desktop app: open the Destination screen, choose ClickHouse, paste the string into Connection string and choose Test connection.

  • CLI:

    Terminal window
    export SPSYNC_CLICKHOUSE_DSN='clickhouse://spsync_loader:PASSWORD@HOST:9440/spsync?secure=1'
    spsync export-config --output replication.yaml \
    --site-url https://contoso.sharepoint.com/sites/x --list Projects \
    --pipeline-name spsync_dev --prefix dev \
    --destination-kind clickhouse --connection-string-env SPSYNC_CLICKHOUSE_DSN \
    --dataset-name sync --client-id <entra-app-client-id>
  • AI assistant: with the admin MCP server connected, ask for the destination requirements, then let the assistant create the destination. You enter the string on the secure entry page.

Test connection connects over the HTTP port (http_port, or 8443 when not given) and runs SELECT 1. spsync doctor reports the destination probe as destination-connectivity. A pass proves the host, the HTTP port, TLS, the user name and password and the database, and names the user the server says the connection runs as (connected as spsync_loader, from currentUser()), in spsync doctor, in Test connection and on the Destination screen. It does not open the native port 9440, which loading and queries use, so a firewall that allows only the HTTP port passes the test and fails the first run. It also does not prove the user can create tables.

What you see What it means and the fix
Connection timed out on 9440 or 8443 A firewall, security group or the Cloud IP access list is blocking a port. Open both.
Authentication failed: password is incorrect Wrong user or password, or the user cannot connect from SPSync’s address.
the connection string sets ca_certs You gave SPSync a CA or client certificate and the string also sets a TLS parameter. Remove it from the string.
Test connection passes, the run cannot connect The native port 9440 is blocked, or secure does not match the port (9440 needs secure=1, 9000 needs secure=0).
Connects to 8443 on a self-hosted server and fails The HTTP interface is on 8123. Add &http_port=8123.
Not enough privileges or ACCESS_DENIED The user lacks rights on the database. Run the script from spsync clickhouse-grants above.
Database ... does not exist Create the database named in the path of the connection string.

A SharePoint “Date only” column is stored as ClickHouse Date32, which holds 1900-01-01 to 2299-12-31. Earlier builds used Date, which only holds 1970-01-01 to 2149-06-06 and silently changed anything outside it (1965 became 1970-01-01, 2200 became 2149-06-06). A table created by an earlier build keeps its Date column; to get the fix, recreate that table or change the column with ALTER TABLE ... MODIFY COLUMN <name> Nullable(Date32) and run a full reload so the stored values are rewritten from SharePoint. Date and time columns already use DateTime64(6,'UTC') and were not affected. A value outside 1900 to 2299 is still outside what ClickHouse can hold.