Managing databases in Managed Service for ClickHouse®
Managed Service for ClickHouse® provides two ways for you to manage cluster databases:
- Using native Yandex Cloud interfaces, such as the CLI, API, or management console. Select this method if you wish to create and delete cluster databases using Yandex Managed Service for ClickHouse® features.
- SQL queries to the cluster. Select this method if you want to use an existing solution for creating and managing databases, or if you need MySQL® database support in Managed Service for ClickHouse®.
Managing databases via SQL
To enable management, activate the User management via SQL and Managing databases via SQL options when creating or reconfiguring a cluster.
In a cluster with DB management via SQL enabled:
- Database and user management using the standard Yandex Cloud interfaces (CLI, API, management console) is unavailable.
- You cannot enable user or database management using the standard Yandex Cloud interfaces.
- The existing users as well as user and database settings made with the standard Yandex Cloud interfaces will be saved.
- User management is performed using the
admin
account. You set its password when selecting the User management via SQL and Managing databases via SQL options.
Getting a list of cluster databases
- In the management console
, go to the folder page and select Managed Service for ClickHouse. - Click the name of the cluster you need and select the Databases tab.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To get a list of databases in a cluster, run the command:
yc managed-clickhouse database list \
--cluster-name=<cluster_name>
You can request the cluster name with the list of clusters in the folder.
To get a list of cluster databases, use the list REST API method for the Database resource or the DatabaseService/List gRPC API call.
-
Connect to a cluster using the
admin
account. -
Get a list of databases:
SHOW DATABASES;
Creating a database
Note
You can create a maximum of 1000 databases in each cluster.
-
In the management console
, go to the folder page and select Managed Service for ClickHouse. -
Click the cluster name.
-
Select the Databases tab.
-
Click Create database.
-
Enter the database name and click Create.
Note
The DB name may contain Latin letters, numbers, and underscores. The name may be up to 63 characters long. You cannot create a database named
default
.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
Run the create database command and set the name of the new database:
yc managed-clickhouse database create <DB_name> \
--cluster-name=<cluster_name>
Note
The DB name may contain Latin letters, numbers, and underscores. The name may be up to 63 characters long. You cannot create a database named default
.
You can request the cluster name with the list of clusters in the folder.
Managed Service for ClickHouse® runs the create database operation.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Add the
database
DB description block to the Managed Service for ClickHouse® cluster description:resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" { ... database { name = "<DB_name>" } }
Note
The DB name may contain Latin letters, numbers, and underscores. The name may be up to 63 characters long. You cannot create a database named
default
. -
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
Time limits
A Terraform provider sets the timeout for Managed Service for ClickHouse® cluster operations:
- Creating a cluster, including by restoring one from a backup: 60 minutes.
- Editing a cluster: 90 minutes.
- Deleting a cluster: 30 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
To create a new database in a cluster, use the create REST API method for the Database resource or the DatabaseService/Create gRPC API call.
-
Connect to a cluster using the
admin
account. -
Create a database:
CREATE DATABASE <DB_name>;
Note
The DB name may contain Latin letters, numbers, and underscores. The name may be up to 63 characters long. You cannot create a database named
default
.
To learn more about creating databases, see the ClickHouse® documentation
Deleting a database
- In the management console
, go to the folder page and select Managed Service for ClickHouse. - Click the cluster name and open the Databases tab.
- Click
in the required DB row and select Delete.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
To delete a database, run the command:
yc managed-clickhouse database delete <DB_name> \
--cluster-name=<cluster_name>
You can request the cluster name with the list of clusters in the folder.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Delete the
database
DB description block from the Managed Service for ClickHouse® cluster description. -
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
Time limits
A Terraform provider sets the timeout for Managed Service for ClickHouse® cluster operations:
- Creating a cluster, including by restoring one from a backup: 60 minutes.
- Editing a cluster: 90 minutes.
- Deleting a cluster: 30 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the timeouts
block to the cluster description, for example:
resource "yandex_mdb_clickhouse_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
To delete a database, use the delete REST API method for the Database resource or the DatabaseService/Delete gRPC API call.
-
Connect to a cluster using the
admin
account. -
Delete the database:
DROP DATABASE <DB_name>;
To learn more about deleting objects, see the ClickHouse® documentation
Warning
Before creating a new database with the same name, wait for the delete operation to complete, otherwise the database being deleted will be restored. Operation status can be obtained with a list of cluster operations.
ClickHouse® is a registered trademark of ClickHouse, Inc