Changing ClickHouse® settings at the query level
- Getting a list of ClickHouse® settings at the query level
- Specifying ClickHouse® settings using the Yandex Cloud interfaces
- Specifying ClickHouse® settings in a user account
- Specifying ClickHouse® settings in a settings profile
- Specifying ClickHouse® settings in a session
- Specifying ClickHouse® settings when connecting to a database via the command line
You can specify ClickHouse® settings at the query 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 any ClickHouse® settings at the query level. The way you set up ClickHouse® depends on the type of settings:
-
User settings. In the
CREATE USERandALTER USERSQL queries, you can use theSETTINGScondition to provide settings. This way, settings will only apply to the selected user.To use this method, enable User management via SQL when creating or updating the cluster. Once you enable this option, you will not be able to manage users via the Yandex Cloud interfaces, as user management via SQL cannot be disabled.
-
Profile-level settings. In ClickHouse®, the settings profile
contains the values and limits of these settings, along with the list of roles and users the profile applies to. To provide ClickHouse® settings, use theCREATE SETTINGS PROFILEandALTER SETTINGS PROFILESQL queries.To use this method, enable User management via SQL when creating or updating the cluster.
-
Session settings. During a session, you can provide ClickHouse® settings using the
SETSQL query. This way you can specify settings in a cluster with any configuration, but they will only apply to the current session.This method does not work for all SQL editors, as some of them run each query in a separate session. Check the specifications of your SQL editor before configuring a session.
-
Connection settings. When connecting to a database via clickhouse-client, you can provide ClickHouse® settings using flags. This way you can specify settings in a cluster with any configuration, but they will only apply to the current connection.
You can also specify connection settings in different drivers for ClickHouse® or provide them as URL parameters when sending ClickHouse® HTTP API requests. For more information about these methods, see this ClickHouse® overview article
.
-
Getting a list of ClickHouse® settings at the query level
-
Connect to the database in the cluster.
-
Run this query:
SELECT name, description, value FROM system.settings;The result contains names, descriptions, and values of ClickHouse® settings at the query level. All these are values for the current session and the user who initiated that session.
Specifying ClickHouse® settings using the Yandex Cloud interfaces
To configure ClickHouse®:
- In the management console
, select the folder the cluster is in. - Go to Managed Service for ClickHouse.
- Click the name of the cluster you need, then go the Users section.
- In the appropriate user row, click
and select Settings. - In the Advanced settings list, expand settings and configure ClickHouse®.
- Click Save changes.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To configure ClickHouse®:
-
View the full list of user-level settings:
yc managed-clickhouse user get <username> <cluster_name_or_ID> -
View the description of the CLI command for updating user settings:
yc managed-clickhouse user update --help -
Set the parameter values as needed:
yc managed-clickhouse user update <username> \ --cluster-name=<cluster_name> \ --settings="<parameter_1_name>=<value_1>,<parameter_2_name>=<value_2>,..."
To configure ClickHouse®:
-
Open the current Terraform configuration file describing your infrastructure.
For information on how to create such a file, see Creating a cluster.
-
In the Managed Service for ClickHouse® cluster user description, under
settings, edit the parameters as follows:resource "yandex_mdb_clickhouse_user" "<username>" { ... settings { <parameter_1_name> = <value_1> <parameter_2_name> = <value_2> ... } } -
Make sure the settings are correct.
-
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.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the User.Update method, for instance, 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>/users/<username>' \ --data '{ "updateMask": "<list_of_settings_to_update>", "settings": { <ClickHouse®_settings> } }'Where:
-
updateMask: Comma-separated list of settings you want to update. -
settings: Required ClickHouse® settings with new values.
You can get the cluster ID with the list of clusters in the folder. You can get the username with the list of users in the cluster.
-
-
View 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 the repository contents are stored in the
~/cloudapi/directory. -
Call the UserService.Update method, for instance, 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/user_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "user_name": "<username>", "update_mask": { "paths": [ <list_of_settings_to_update> ] }, "settings": { <ClickHouse®_settings> } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.UserService.UpdateWhere:
-
update_mask: List of settings to update as an array of strings (paths[]). -
settings: Required ClickHouse® settings with new values.
You can get the cluster ID with the list of clusters in the folder. You can get the username with the list of users in the cluster.
-
-
View the server response to make sure your request was successful.
Specifying ClickHouse® settings in a user account
You can provide ClickHouse® settings when adding a new user or changing settings of a current user.
Adding a new user with ClickHouse® settings
-
Connect to the database in the cluster as
admin. -
Create a user:
CREATE USER <username> IDENTIFIED WITH sha256_password BY '<user_password>' SETTINGS <list_of_ClickHouse®_settings>;Note
The username may contain Latin letters, numbers, hyphens, and underscores but must begin with a letter or underscore.
The password must be from 8 to 128 characters long.
Under
SETTINGS, you can specify the setting value along with its minimum and maximum. Here is an example for the idle_connection_timeout setting:CREATE USER <username> IDENTIFIED WITH sha256_password BY 'password' SETTINGS idle_connection_timeout = 60 MIN 5 MAX 120;For more information about creating users, see this ClickHouse® guide
.
Changing ClickHouse® settings of a user
-
Connect to the database in the cluster as
admin. -
Edit the user account:
ALTER USER <username> SETTINGS <list_of_ClickHouse®_settings>;For more information on editing accounts, see this ClickHouse® guide
.
Specifying ClickHouse® settings in a settings profile
You can specify ClickHouse® settings when creating or updating a settings profile.
Creating a profile with ClickHouse® settings
-
Connect to the database in the cluster as
admin. -
Create a settings profile:
CREATE SETTINGS PROFILE <settings_profile_name> SETTINGS <list_of_ClickHouse®_settings>;Under
SETTINGS, you can specify the setting value along with its minimum and maximum. Here is an example for the idle_connection_timeout setting:CREATE SETTINGS PROFILE <settings_profile_name> SETTINGS idle_connection_timeout = 60 MIN 5 MAX 120;You can assign a settings profile to a user:
CREATE SETTINGS PROFILE <settings_profile_name> SETTINGS <list_of_ClickHouse®_settings> TO <username>;For more information about creating settings profiles, see this ClickHouse® guide
.
Changing ClickHouse® settings in a settings profile
-
Connect to the database in the cluster as
admin. -
Update a settings profile:
ALTER SETTINGS PROFILE <settings_profile_name> SETTINGS <list_of_ClickHouse®_settings>;In this query, you can define the setting minimum and maximum values and assign the profile to a user. For more information about changing settings profiles, see this ClickHouse® guide
.
Specifying ClickHouse® settings in a session
-
Connect to the database in the cluster.
-
Run this query:
SET <username> SETTINGS <list_of_ClickHouse®_settings>;The settings you apply will only be valid for the current session.
-
Make sure the settings are applied:
SELECT value FROM system.settings;To view the value of a setting, run this query:
SELECT value FROM system.settings WHERE name='<setting_name>';
Specifying ClickHouse® settings when connecting to a database via the command line
-
Set the dependencies required for connecting to a database.
-
View the description of the command for connecting to a database:
clickhouse-client --helpMost flags in the command output are advanced ClickHouse® settings.
-
Select the flags with the required settings by matching the flag names with the names of ClickHouse® settings
. -
Provide the selected flags in the database connection command:
-
Connecting without SSL:
clickhouse-client --host <FQDN_of_any_ClickHouse®_host> \ --user <username> \ --database <DB_name> \ --port 9000 \ --ask-password \ <flags_with_ClickHouse®_settings> -
Connecting with SSL:
clickhouse-client --host <FQDN_of_any_ClickHouse®_host> \ --secure \ --user <username> \ --database <DB_name> \ --port 9440 \ --ask-password \ <flags_with_ClickHouse®_settings> -
Here is an example of connecting without SSL with the idle_connection_timeout
setting:clickhouse-client --host rc1a-goh2a9tr********.mdb.yandexcloud.net \ --user user1 \ --database db1 \ --port 9440 \ --ask-password \ --idle_connection_timeout 60
-
-
Make sure the settings are applied:
SELECT value FROM system.settings;To view the value of a setting, run this query:
SELECT value FROM system.settings WHERE name='<setting_name>';
ClickHouse® is a registered trademark of ClickHouse, Inc