Cloud.ClickHouse
A managed ClickHouse instance. An instance runs on one node with no
replicas, so snapshots are how you recover from data loss (see
ClickHouseScheduledSnapshot). Deploying blocks until the instance
is running (up to 30 minutes), and fails with a typed WaitFailed when
it ends failed or degraded, or WaitTimeout past the budget.
Plans and versions. type is the plan, CH1 (4 vCPU, 4 GB, 64 GB,
per Better Stack’s ClickHouse docs) to CH8; Cloud.listClickhouseType
lists them with prices.
engineVersion is the LTS version, defaulting to the latest;
Cloud.listClickhouseVersion lists them.
Billing. term is monthly (the default) or annual: annual
commits you to a year of the plan (the API: “Paid for a year”). A
change of term applies at once and starts a new term.
What changes in place. name, metadata, publicAccess, term and
timezone update in place; type rescales (the node stops and resizes)
and engineVersion upgrades, each through its own action, and the deploy
waits until the instance is running on the new value; networkIds and
firewallIds (at most one firewall: a swap detaches the old one first)
attach and detach one at a time. teamId and
availabilityZone replace the instance, which deletes its data: a replace
that keeps an explicit name deletes the old instance first.
Connecting. host, publicHost and the ports (endpoint.ports)
come from the instance; user, password, database, connectionUri
(clickhouse://, native protocol), publicConnectionUri, httpsUrl /
publicHttpsUrl (the HTTP interface, without credentials: send
user/password as basic auth) and caCertificate from the credentials
endpoint, read once the instance is running. Secrets are Redacted.
Credentials: the deploy never rotates them on its own. Set
rotateCredentials to a new value to rotate the admin password once; a
rotation done in the console or CLI is read on the next deploy, without a
replace.
Creating an instance
Section titled “Creating an instance”A CH1 instance on a private network
const network = yield* BetterStack.Cloud.Network("private", { ipPrefix: "10.0.0.0", ipPrefixLength: 24,});const analytics = yield* BetterStack.Cloud.ClickHouse("analytics", { type: "CH1", networkIds: [network.id],});Public access and a time zone
yield* BetterStack.Cloud.ClickHouse("events", { name: "events", type: "CH2", publicAccess: true, timezone: "Europe/Prague", term: "monthly",});Connecting
Section titled “Connecting”A Cloud.Service reading the URI from its environment
const analytics = yield* BetterStack.Cloud.ClickHouse("analytics", { type: "CH1" });// In the Service's props: env: { CLICKHOUSE_URL: analytics.connectionUri }// In its program: const url = yield* Config.Redacted("CLICKHOUSE_URL");The HTTP interface, for @clickhouse/client
const env = { CLICKHOUSE_URL: analytics.httpsUrl, CLICKHOUSE_USER: analytics.user, CLICKHOUSE_PASSWORD: analytics.password,};Rescaling and upgrading
Section titled “Rescaling and upgrading”Change the plan in place
// Was "CH1": the deploy rescales and waits until the instance runs on CH2.yield* BetterStack.Cloud.ClickHouse("analytics", { type: "CH2" });Looking up an existing instance
Section titled “Looking up an existing instance”Reference an instance by id
const existing = BetterStack.Cloud.ClickHouse.lookup({ id: "42" });Reference an instance by name (fails with AmbiguousLookup when several share it)
const byName = BetterStack.Cloud.ClickHouse.lookup({ name: "analytics" });type string required
The instance's plan, such as CH2. Get the plans via betterstack clickhouse-type list.
availabilityZone string
Availability zone the resource lives in, such as us-west-2a. Defaults to the credentials' zone (BETTERSTACK_AVAILABILITY_ZONE, or the profile's). Changing it replaces the resource. A child of a resource in another zone (a firewall rule, a node pool, a snapshot of an instance outside the credentials' zone) must repeat the parent's availabilityZone: it receives only the parent's id, so its zone cannot be derived.
engineVersion string
The ClickHouse LTS version, such as 26.8. Get the versions via betterstack clickhouse-version list. Defaults to the latest version.
firewallIds string[]
The IDs of the firewalls attached to the instance, at most one.
metadata CreateClickhouseRequestMetadataMap
Your own tags as string pairs, at most 10. An update replaces all tags, so an empty object removes every tag.
name string
The instance's name, up to 255 characters, unique among the organization's ClickHouse instances that aren't failed or destroyed. Defaults to a unique name generated from the stack, stage and logical id. Changes in place.
networkIds string[]
The IDs of the private networks attached to the instance. Must be in the instance's team.
publicAccess boolean
Whether the instance accepts connections on a public IP. The TLS ports 9440 and 8443 are public. The ports without TLS stay on private networks.
rotateCredentials string
Rotate the credentials: every change of this value after create (for example a date, "2026-12") calls the API's rotate operation once on the next deploy, and the new secrets replace the old ones in the attributes (and so in every env that references them). Leaving it out, or keeping the same value, never rotates. A rotation done in the console or CLI is simply read on the next deploy.
teamId string
Team that owns the resource, such as t123. Defaults to the credentials' team (BETTERSTACK_TEAM_ID, or the profile's team). Changing it replaces the resource.
term "monthly" | "annual" | string
The billing term. A change applies at once, from monthly to annual or back. Billing ends the current term and starts the new one. Sending the current term changes nothing. - monthly: Billed every month. - annual: Paid for a year.
timezone string
The default time zone for date and time functions, UTC or an IANA name such as Europe/Prague. A change applies to connections opened after it.
Attributes
Section titled “Attributes”availabilityZone string always set
Availability zone the resource lives in, such as us-west-2a.
caCertificate string always set
The CA certificate (PEM) that signs the instance's TLS certificate.
connectionUri Redacted<string> always set
clickhouse:// URI (native protocol over TLS) for your private networks, with the password in it (credentials uri).
database string always set
The default database, defaultdb (credentials database).
host string always set
The hostname to connect to from the private networks attached to the instance (endpoint.hostname): native protocol on 9000 (9440 with TLS), HTTP on 8123 (8443 with HTTPS). undefined until provisioned.
httpsUrl string always set
The HTTPS URL for the private networks, https://<host>:8443, without credentials (built from endpoint.hostname and endpoint.ports.https).
id string always set
The instance's ID.
password Redacted<string> always set
The admin user's password (credentials password).
publicConnectionUri Redacted<string> always set
The same from the internet, undefined unless publicAccess is on (credentials public_uri).
publicHost string always set
The hostname to connect to from the internet (endpoint.publicHostname), TLS ports only (9440, 8443); undefined unless publicAccess is on.
publicHttpsUrl string always set
The public HTTPS URL, https://<publicHost>:8443, without credentials; undefined unless publicAccess is on.
rotatingUntil string always set
After a rotation: until when the previous password still works; undefined otherwise.
user string always set
The admin user, admin (credentials user).
availableEngineVersions string[]
The versions you can upgrade the instance to now. Holds the next LTS version once we offer it, and is empty until then.
createdAt string
When the instance was created.
endpoint ClickhouseEndpoint
Where to connect to the instance.
enginePatchVersion string | null
The exact ClickHouse version the instance runs, or null until the instance's first upgrade.
engineVersion string
The ClickHouse LTS version, such as 26.8. Get the versions via betterstack clickhouse-version list. Defaults to the latest version.
firewallIds string[]
The IDs of the firewalls attached to the instance, at most one.
latestSnapshotAt string | null
When the newest available snapshot was created, or null when the instance has no snapshot.
maxConcurrentQueries number
The most queries the plan runs at the same time. A query over this limit fails at once.
members ClickhouseMembersItem[]
The node that runs the instance. An instance has one.
metadata ClickhouseMetadataMap
Your own tags as string pairs, at most 10. An update replaces all tags, so an empty object removes every tag.
name string
The instance's name, up to 255 characters. Must differ from the names of the organization's other ClickHouse instances, except failed and destroyed ones.
networkIds string[]
The IDs of the private networks attached to the instance. Must be in the instance's team.
preUpgradeSnapshotId string
The ID of the snapshot we created before the upgrade.
publicAccess boolean
Whether the instance accepts connections on a public IP. The TLS ports 9440 and 8443 are public. The ports without TLS stay on private networks.
status string
The instance's state. - provisioning: We're creating the instance. - running: The instance is ready. - degraded: The instance works, but needs attention. status_message says why. - rescaling: We're changing the plan. When the change doesn't complete, the instance returns to running with a status_message. - upgrading: We're upgrading the ClickHouse version. The upgrade is done when the instance is running on the new engine_version. When the instance is running on the old version with a status_message, the upgrade failed. - restoring: We're restoring a snapshot onto the instance. The instance is running again once ClickHouse responds to queries. - failed: The instance couldn't be created or recovered. A failed instance stays in this state. - destroyed: The instance is deleted.
statusMessage string | null
Why the instance failed or is degraded, or why an operation didn't complete.
teamId string
The ID of the team that owns the instance. betterstack team list shows it. Can't be changed after the instance is created.
term "monthly" | "annual"
The billing term. A change applies at once, from monthly to annual or back. Billing ends the current term and starts the new one. Sending the current term changes nothing. - monthly: Billed every month. - annual: Paid for a year.
timezone string
The default time zone for date and time functions, UTC or an IANA name such as Europe/Prague. A change applies to connections opened after it.
type string
The instance's plan, such as CH2. Get the plans via betterstack clickhouse-type list.
updatedAt string
When the instance was last updated.
usableDiskGb number
Storage for your data, in GiB.
Lookup
Section titled “Lookup”ClickHouse.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.
availabilityZone string
Zone it lives in, such as us-west-2a. Defaults to the credentials' zone.
See also
Section titled “See also”- Ownership. Every object the stack creates carries an
alchemyentry in itsmetadata(<stack>/<stage>/<resource id>#<instance>), added on every write and left out of the attributes and of diffs; your own keys are untouched (it takes one of the 10 slots). A deploy that lost track of an object it created (a create that failed or timed out after the API accepted it) finds it by that marker and converges it instead of creating another;list(and soalchemy nuke) returns only Alchemy-created objects; an object with the same name but no marker of this resource is taken over only with--adopt. - https://betterstack.com/docs/cloud/api/clickhouses/credentials-clickhouse/