Changing ClickHouse® settings at the query level
- Getting the 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 the 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 specify only the ClickHouse® settings available in Yandex Cloud.
-
Using SQL queries. This way you can specify any ClickHouse® settings at the query level. The method of specifying settings depends on their type:
-
User settings. In the
CREATE USERandALTER USERSQL queries, you can use theSETTINGScondition to provide settings. This way, settings will apply to the selected user only.To use this method, enable the User management via SQL option when creating or updating the cluster. After that, you will not be able to manage users using the Yandex Cloud interfaces; however, you cannot disable user management via SQL.
-
Settings at the profile level. In ClickHouse®, the settings profile
contains the values and limitations of these settings as well as the list of roles and users to whom the profile applies. ClickHouse® settings are provided in theCREATE SETTINGS PROFILEandALTER SETTINGS PROFILESQL queries.To use this method, enable the User management via SQL option when creating or updating the cluster.
-
Session settings. During a session, you can specify ClickHouse® settings using the
SETSQL query. This way you can specify settings in a cluster with any configuration, but they will apply to the current session only.This method is not suitable for all SQL editors: in some of them, every query runs in a separate session. Check the characteristics of your SQL editor before configuring a session.
-
Connection settings. When you connect to a database using the clickhouse-client utility, you can specify ClickHouse® settings using flags. This way you can specify settings in a cluster with any configuration, but they will apply to the currently established connection only.
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 the ClickHouse® documentation
.
-
Getting the list of ClickHouse® settings at the query level
-
Connect to the database in the cluster.
-
Run this request:
SELECT name, description, value FROM system.settings;The result contains names, descriptions, and values of ClickHouse® settings at the query level. The result displays values for the current session and the user who established that session.
Specifying ClickHouse® settings using the Yandex Cloud interfaces
To configure ClickHouse®:
- In the management console
, navigate to the folder page and select 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 specify the ClickHouse® settings.
- 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 settings specified for a user:
yc managed-clickhouse user get <username> <cluster_name_or_ID> -
View the description of the CLI command to update the user settings:
yc managed-clickhouse user update --help -
Set the required parameter values:
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 that defines your infrastructure.
For more information about creating this file, see Creating clusters.
-
In the Managed Service for ClickHouse® cluster user description, under
settings, edit the following parameters: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 the Terraform provider documentation.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>" -
Use the User.update method and send the following request, e.g., using cURL
: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: List of parameters to update as a single string, separated by commas. -
settings: Required ClickHouse® settings with new values.
You can request the cluster ID with the list of clusters in the folder. You can request the user name with the list of users in the cluster.
-
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the 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. -
Use the ClusterService.Update call and send the following request, e.g., via gRPCurl
: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 parameters to update as an array ofpaths[]strings. -
settings: Required ClickHouse® settings with new values.
You can request the cluster ID with the list of clusters in the folder. You can request the user name with the list of users in the cluster.
-
-
View the server response to make sure the request was successful.
Specifying ClickHouse® settings in a user account
You can specify ClickHouse® settings when adding a new user or changing settings of an existing user.
Adding a new user with ClickHouse® settings
-
Connect to the DB in the cluster using the
adminaccount. -
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.
In the
SETTINGSparameter, apart from with the setting value, you can specify its minimum and maximum value. 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 the ClickHouse® documentation
.
Changing ClickHouse® settings of a user
-
Connect to the DB in the cluster using the
adminaccount. -
Update the user account.
ALTER USER <username> SETTINGS <list_of_ClickHouse®_settings>;For more information on updating accounts, see the ClickHouse® documentation
.
Specifying ClickHouse® settings in the settings profile
You can specify ClickHouse® settings when creating or updating a settings profile.
Creating a profile with ClickHouse® settings
-
Connect to the DB in the cluster using the
adminaccount. -
Create a settings profile:
CREATE SETTINGS PROFILE <settings_profile_name> SETTINGS <list_of_ClickHouse®_settings>;In the
SETTINGSparameter, apart from with the setting value, you can specify its minimum and maximum value. 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 attach 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 the ClickHouse® documentation
.
Changing ClickHouse® settings in the settings profile
-
Connect to the DB in the cluster using the
adminaccount. -
Update a settings profile:
ALTER SETTINGS PROFILE <settings_profile_name> SETTINGS <list_of_ClickHouse®_settings>;In this query, you can specify the boundary values of settings and bind the profile to a user. For more information about changing settings profiles, see the ClickHouse® documentation
.
Specifying ClickHouse® settings in a session
-
Connect to the database in the cluster.
-
Run this request:
SET <username> SETTINGS <list_of_ClickHouse®_settings>;The applied settings will be valid during the opened session only.
-
Make sure the settings were 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
. -
Specify the selected flags in the command for connecting to a database:
-
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 via 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 were 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