Managing databases in Managed Service for ClickHouse®
Managed Service for ClickHouse® provides two methods for managing cluster databases:
- Using the native Yandex Cloud interfaces, such as the CLI, API, and management console. Select this method to create and delete cluster databases using the Yandex Managed Service for ClickHouse® features.
- Using SQL queries against the cluster. Select this method to use your own solution to create and manage databases, or if you need MySQL® database support in Managed Service for ClickHouse®.
Database management via SQL
To enable this management method, select User management via SQL and Managing databases via SQL when creating or reconfiguring your cluster.
In a cluster with enabled database management via SQL:
- You cannot manage databases and users via the native Yandex Cloud interfaces, such as the CLI, API, and management console.
- You cannot enable user or database management via the native Yandex Cloud interfaces.
- The existing users, user settings, and databases created with the native Yandex Cloud interfaces will remain unchanged.
- Use the
adminaccount for management. You set theadminpassword when selecting the User management via SQL and Managing databases via SQL options.
Getting a list of cluster databases
- In the management console
, select the folder the cluster is in. - Navigate to the Managed Service for ClickHouse service.
- Click the name of your cluster and select the Databases tab.
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 --folder-name or --folder-id.
To get a list of cluster databases, run this command:
yc managed-clickhouse database list \
--cluster-name=<cluster_name>
You can get the cluster name with the list of clusters in the folder.
-
Get an IAM token for API authentication and place it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Database.List method, e.g., via the following cURL
request:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/databases'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 place it in 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 DatabaseService.List method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.DatabaseService.ListYou can get the cluster ID with the list of clusters in the folder.
-
View the server response to make sure your request was successful.
Creating a database
Note
You can create a maximum of 1000 databases in each cluster.
To learn more about limits, see Quotas and limits.
-
In the management console
, select the folder the cluster is in. -
Navigate to the Managed Service for ClickHouse service.
-
Click the name of your cluster.
-
Select the Databases tab.
-
Click Create database.
-
Enter a name for the database.
Note
The database name may contain Latin letters, numbers, and underscores. It may be up to 63 characters long. You cannot create a database named
default. -
Select the database engine:
-
Atomic, the default option, supports the non-blockingDROP TABLEandRENAME TABLEoperations and atomicEXCHANGE TABLESoperations. -
Replicatedsupports table metadata replication across all database replicas. The set of tables and their schemas will be the same for all replicas.It is only available in replicated clusters.
You can only set the engine when creating a database and cannot change it later.
-
-
Click Create.
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 --folder-name or --folder-id.
Run the database create command, providing the new database name:
yc managed-clickhouse database create <DB_name> \
--cluster-name=<cluster_name> \
--engine=<DB_engine>
Where:
-
--cluster-name: Database cluster name. -
--engine: Database engine. This is an optional parameter. The possible values are:-
database-engine-atomic(default):Atomicengine; supports non-blockingDROP TABLEandRENAME TABLEqueries, and atomicEXCHANGE TABLESqueries. -
database-engine-replicated:Replicatedengine; supports table metadata replication across all database replicas. The set of tables and their schemas will be the same for all replicas.It is only available in replicated clusters.
You can only set the engine when creating a database and cannot change it later.
-
Note
The database name may contain Latin letters, numbers, and underscores. It may be up to 63 characters long. You cannot create a database named default.
You can get the cluster name from the list of clusters in your folder.
Managed Service for ClickHouse® will start creating the database.
-
Open the current Terraform configuration file describing your infrastructure.
To learn how to create this file, see Creating a cluster.
-
Add the
yandex_mdb_clickhouse_databaseresource:resource "yandex_mdb_clickhouse_database" "<DB_name>" { cluster_id = "<cluster_ID>" name = "<DB_name>" engine = "<DB_engine>" }Where:
-
cluster_id: Database cluster ID. -
name: Database name. -
engine: Database engine. This is an optional parameter. The possible values are:-
atomic(default):Atomicengine; supports non-blockingDROP TABLEandRENAME TABLEqueries, and atomicEXCHANGE TABLESqueries. -
replicated:Replicatedengine; supports table metadata replication across all database replicas. The set of tables and their schemas will be the same for all replicas.It is only available in replicated clusters.
You can only set the engine when creating a database and cannot change it later.
-
Note
The database name may contain Latin letters, numbers, and underscores. It may be up to 63 characters long. You cannot create a database named
default.When creating both a cluster and a database with Terraform at the same time, specify a name for the new cluster rather than cluster ID in the
yandex_mdb_clickhouse_databaseresource:resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" { name = "<cluster_name>" ... } resource "yandex_mdb_clickhouse_database" "<DB_name>" { cluster_id = yandex_mdb_clickhouse_cluster.<cluster_name>.id name = "<DB_name>" } -
-
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 resource changes.
-
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 place it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Database.Create method, e.g., via the following cURL
request:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/databases' \ --data '{ "databaseSpec": { "name": "<DB_name>", "engine": "<database_engine>" } }'Where:
-
databaseSpec.name: Database name.Note
The database name may contain Latin letters, numbers, and underscores. It may be up to 63 characters long. You cannot create a database named
default. -
databaseSpec.engine: Database engine. The possible values are:-
DATABASE_ENGINE_ATOMIC(default):Atomicengine; supports non-blockingDROP TABLEandRENAME TABLEqueries, and atomicEXCHANGE TABLESqueries. -
DATABASE_ENGINE_REPLICATED:Replicatedengine; supports table metadata replication across all database replicas. The set of tables and their schemas will be the same for all replicas.It is only available in replicated clusters.
-
DATABASE_ENGINE_UNSPECIFIED: This value will set the default engine, i.e.,DATABASE_ENGINE_ATOMIC.
You can only set the engine when creating a database and cannot change it later.
-
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 place it in 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 DatabaseService.Create method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "database_spec": { "name": "<DB_name>", "engine": "<database_engine>" } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.DatabaseService.CreateWhere:
-
database_spec.name: Database name.Note
The database name may contain Latin letters, numbers, and underscores. It may be up to 63 characters long. You cannot create a database named
default. -
database_spec.engine: Database engine. The possible values are:-
DATABASE_ENGINE_ATOMIC(default):Atomicengine; supports non-blockingDROP TABLEandRENAME TABLEqueries, and atomicEXCHANGE TABLESqueries. -
DATABASE_ENGINE_REPLICATED:Replicatedengine; supports table metadata replication across all database replicas. The set of tables and their schemas will be the same for all replicas.It is only available in replicated clusters.
-
DATABASE_ENGINE_UNSPECIFIED: This value will set the default engine, i.e.,DATABASE_ENGINE_ATOMIC.
You can only set the engine when creating a database and cannot change it later.
-
You can get the cluster ID with the list of clusters in the folder.
-
-
View the server response to make sure your request was successful.
-
Create a database:
CREATE DATABASE <DB_name>;Note
The database name may contain Latin letters, numbers, and underscores. It may be up to 63 characters long. You cannot create a database named
default.
To learn more about creating databases, see this ClickHouse® guide
Deleting a database
- In the management console
, select the folder the cluster is in. - Navigate to the Managed Service for ClickHouse service.
- Click the name of your cluster and select the Databases tab.
- Click
in the relevant database row and select Delete.
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 --folder-name or --folder-id.
To delete a database, run this command:
yc managed-clickhouse database delete <DB_name> \
--cluster-name=<cluster_name>
You can get the cluster name with the list of clusters in the folder.
-
Open the current Terraform configuration file describing your infrastructure.
To learn how to create this file, see Creating a cluster.
-
Remove the
yandex_mdb_clickhouse_databaseresource with the name of the database you want to delete. -
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 resource changes.
-
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 place it in an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Database.Delete method, e.g., via the following cURL
request:curl \ --request DELETE \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-clickhouse/v1/clusters/<cluster_ID>/databases/<DB_name>'You can get the cluster ID from the list of clusters in your folder, and the database name from the list of databases in your cluster.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and place it in 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 DatabaseService.Delete method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/clickhouse/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "database_name": "<DB_name>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.clickhouse.v1.DatabaseService.DeleteYou can get the cluster ID from the list of clusters in your folder, and the database name, from the list of databases in your cluster.
-
View the server response to make sure your request was successful.
Learn more about deleting objects in this ClickHouse® guide
Warning
Before creating a new database with the same name, wait for the delete operation to complete. Otherwise, the original database will be restored. You can check the operation status in the list of cluster operations.
ClickHouse® is a registered trademark of ClickHouse, Inc