Changing ClickHouse® settings at the server level
You can specify ClickHouse® settings at the server level
-
Using the Yandex Cloud interfaces. This way you can only specify the ClickHouse® settings available in Yandex Cloud.
-
Using SQL queries. This way you can specify settings for MergeTree tables. You can:
- Specify the settings when creating a table.
- Specify the settings of an existing table.
- Restore the default settings of an existing table.
Specifying ClickHouse® settings using the Yandex Cloud interfaces
Changing some server settings will restart ClickHouse® servers on the cluster hosts.
Note
You cannot directly change the Max server memory usage
To configure ClickHouse®:
- In the management console
, select the folder the cluster is in. - Navigate to Managed Service for ClickHouse.
- Select your cluster and click Edit in the top panel.
- Under DBMS settings, click Settings.
- Specify the ClickHouse® settings.
- Click Save changes.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To configure ClickHouse®:
-
View the full list of settings for the cluster:
yc managed-clickhouse cluster get <cluster_name_or_ID> --full -
View the description of the CLI command for updating the cluster configuration:
yc managed-clickhouse cluster update-config --help -
Set the parameter values as needed:
yc managed-clickhouse cluster update-config <cluster_name_or_ID> \ --set <parameter_1_name>=<value_1>,...
To configure ClickHouse®:
-
Open the current Terraform configuration file describing your infrastructure.
For more on how to create this file, see Creating a cluster.
-
In the Managed Service for ClickHouse® cluster description, under
clickhouse.config, edit the parameters as follows:resource "yandex_mdb_clickhouse_cluster_v2" "<cluster_name>" { ... clickhouse = { ... config = { # General DBMS settings ... merge_tree = { # MergeTree engine settings ... } kafka = { # General settings for getting data from Apache Kafka ... } rabbit_mq = { # Settings for getting data from RabbitMQ username = "<username>" password = "<password>" } compression = [ { # Data compression settings method = "<compression_method>" min_part_size = <data_part_size> min_part_size_ratio = <size_ratio> } ] graphite_rollup = [ { # GraphiteMergeTree engine settings for data thinning, aggregation, and rollup in Graphite. ... } ] } ... } ... }Where:
method: Compression method,LZ4orZSTD.min_part_size: Minimum size of a table data part, in bytes.min_part_size_ratio: Ratio of the smallest data part size to the full table size.
-
Validate your configuration.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider guide.
Timeouts
The Terraform provider sets the following timeouts for Managed Service for ClickHouse® cluster operations:
- Creating a cluster, including by restoring from a backup: 60 minutes.
- Updating a cluster: 90 minutes.
- Deleting a cluster: 30 minutes.
Operations exceeding the timeout are aborted.
How to change these limits
Add the timeouts section to your cluster description, such as the following:
resource "yandex_mdb_clickhouse_cluster_v2" "<cluster_name>" {
...
timeouts = {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Cluster.Update method, e.g., via the following cURL
request:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
updateMaskparameter as a single comma-separated string.curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>' \ --data '{ "updateMask": "configSpec.clickhouse.config.<setting_1>,...,configSpec.clickhouse.config.<setting_N>", "configSpec": { "clickhouse": { "config": { "<setting_1>": "<value_1>", "<setting_2>": "<value_2>", ... "<setting_N>": "<value_N>" } } } }'Where:
updateMask: Comma-separated string of settings to update.configSpec.clickhouse.config: ClickHouse® server-level settings. For the list of possible parameters and their values, see the method description.
You can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the ClusterService.Update method, e.g., via the following gRPCurl
request:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
update_maskparameter as an array ofpaths[]strings.Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "update_mask": { "paths": [ "configSpec.clickhouse.config.<setting_1>", "configSpec.clickhouse.config.<setting_2>", ... "configSpec.clickhouse.config.<setting_N>" ] }, "config_spec": { "clickhouse": { "config": { "<setting_1>": "<value_1>", "<setting_2>": "<value_2>", ... "<setting_N>": "<value_N>" } } } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.ClusterService.UpdateWhere:
update_mask: List of settings to update as an array of strings (paths[]).config_spec.clickhouse.config: ClickHouse® server-level settings. For the list of possible parameters and their values, see the method description.
You can request the cluster ID with the list of clusters in the folder.
-
View the server response to make sure your request was successful.
Checking MergeTree table settings
-
Connect to the database in the cluster.
-
To view all table-level settings, run the following query:
SHOW CREATE TABLE <table_name>;Warning
The
SHOW CREATE TABLEoutput only includes settings overridden by the user. If a user-defined value matches the default value, this setting is also output.
Specifying settings for MergeTree tables using SQL queries
Changing settings when creating a MergeTree table
-
Connect to the database in the cluster.
-
Create a table. To configure it, list its settings under
SETTINGS, separated by commas:CREATE TABLE <table_name> ( <table_column_description> ) ENGINE = MergeTree PRIMARY KEY (<column_or_group_of_columns>) SETTINGS <setting_name> = <setting_value>, <setting_name> = <setting_value>;Here is an example of the query for the merge_with_ttl_timeout
and merge_with_recompression_ttl_timeout settings:CREATE TABLE <table_name> ( user_id UInt32, message String, ) ENGINE = MergeTree PRIMARY KEY (user_id) SETTINGS merge_with_ttl_timeout = 15000, merge_with_recompression_ttl_timeout = 15000;
For more information about creating MergeTree tables, see this ClickHouse® guide
Changing the settings of an existing MergeTree table
-
Connect to the database in the cluster.
-
To change the settings of an existing table, run this query:
ALTER TABLE <table_name> MODIFY SETTING <setting_name> = <new_setting_value>;You can change multiple settings with a single query. To do this, list
<setting_name> = <new_setting_value>pairs separated by commas.
Resetting a MergeTree table setting to default
-
Connect to the database in the cluster.
-
To reset a setting of an existing table to its default, run this query:
ALTER TABLE <table_name> RESET SETTING <setting_name>;You can reset multiple settings to default with a single query. To do this, list the names of the settings separated by commas.
ClickHouse® is a registered trademark of ClickHouse, Inc