Skip to main content
Service deletion protection is a per-service setting that blocks deletion until you turn it off. Use it for ClickHouse Cloud services you want to keep from being removed by mistake in the Cloud console, through the ClickHouse Cloud API, or with Terraform.
This applies to ClickHouse Cloud services. It does not apply to ClickHouse Managed Postgres services.
Protection is off by default. Turning it off does not delete the service. A protected service keeps running, and queries, scaling, and other settings are unchanged. While protection is on, delete requests are refused. DELETE /v1/organizations/{organizationId}/services/{serviceId} returns HTTP 409 until you turn protection off. The service must also be stopped before it can be deleted. Deletion then runs asynchronously.

Who can change it

Turning protection on or off uses the control-plane:service:delete permission. Organization admins have this permission. See Console roles and permissions. Turning protection on also requires deletion protection to be available for the organization. ClickHouse Cloud organizations have it. A create or update that sets deletionProtection to true returns HTTP 400 when the organization does not. Turning protection off does not use that check: a request that sets deletionProtection to false is accepted, including for a service that is already protected. ClickStack services cannot be updated through the Cloud API. Turn their deletion protection on or off in the console.

Turn protection on or off in the console

Open the service and go to Settings. Under Deletion protection, use the switch. The change is saved immediately. The switch is available to anyone with control-plane:service:delete on that service. With protection on, the console refuses the delete action until you turn the switch off.

Set it with the Cloud API

The service object has a boolean field, deletionProtection. Set it when you create a service (POST /v1/organizations/{organizationId}/services) or update one (PATCH /v1/organizations/{organizationId}/services/{serviceId}). Get and list responses include the field. When it is absent, the service is not protected. Turn protection on:
To delete a protected service, turn protection off, stop the service, wait until it is stopped, and then delete it. PATCH .../state with "command": "stop" requires control-plane:service:manage and returns before the service has stopped. A delete while the service is still stopping is rejected. A delete against a protected service returns 409 and leaves the service in place. Turn protection off:
Request a stop:
Wait until result.state is stopped, then delete:

Terraform

deletion_protection is not in the latest released provider, v3.43.0. The attribute was added in terraform-provider-clickhouse#799, which is merged and not yet in a release. The example below fails on v3.43.0 with an unsupported argument. Use a provider release after v3.43.0 that includes the attribute.
The clickhouse_service resource accepts deletion_protection. While it is true, terraform destroy and any change that would replace the service fail. Set it to false and apply that change on its own, then destroy the service. Removing deletion_protection from the configuration leaves the current setting unchanged.
Setting deletion_protection = true when creating a service needs an API key that can delete all services in the organization. Changing it later needs delete permission on that service.