Getting started with Managed Service for YDB
In this tutorial, you will create a YDB
You can also work with a Yandex Managed Service for YDB DB through:
Getting started
-
Go to the management console
and log in to Yandex Cloud or sign up if not signed up yet. -
If you do not have a folder yet, create one:
-
In the management console
, select the appropriate cloud in the list on the left. -
At the top right, click
Create folder. -
Enter the folder name. The naming requirements are as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
(Optional) Enter a description of the folder.
-
Select Create a default network. This will create a network with subnets in each availability zone. Within this network, a default security group will be created, inside which all network traffic is allowed.
-
Click Create.
-
Create a database
You can create a DB in the Serverless configuration or with dedicated servers. For more information about differences between configurations, see Serverless and dedicated modes. You cannot change the DB type once you have created it.
Note
For the Amazon DynamoDB-compatible mode, use a serverless database configuration.
Create a serverless DB
-
In the management console
, select the folder to create your DB in. -
In the list of services, select Managed Service for YDB.
-
Click Create a database.
-
Enter the Name of the DB. The naming requirements are as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
Under Database type, select
Serverless
.You can leave the default parameters for the DB being created and change them later. For more information about DB parameters, see Creating a serverless database.
-
Click Create a database.
Wait for the DB to start. While being created, your database will have the Provisioning
status. Once it is ready for use, its status will change to Running
.
-
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
-
Create a database:
yc ydb database create <DB_name> --serverless
Where
<DB_name>
is the name of your database.Result:
done (6s) id: etn95g8jk8g0******** folder_id: b1g7gvsi89m3******** created_at: "2022-05-30T07:26:44Z" name: test status: PROVISIONING endpoint: grpcs://ydb.serverless.yandexcloud.net:2135/?database=/ru-central1/b1gia87mbaom********/etn95g8jk8g0******** serverless_database: storage_size_limit: "53687091200" location_id: ru-central1 backup_config: backup_settings: - name: daily backup_schedule: daily_backup_schedule: execute_time: hours: 17 backup_time_to_live: 172800s type: SYSTEM document_api_endpoint: https://docapi.serverless.yandexcloud.net/ru-central1/b1gia87mbaom********/etn95g8jk8g0******** monitoring_config: {}
A database with default parameters is created. You can change its parameters later. For more information about DB parameters, see Creating a serverless database.
-
Check the status of the created database:
yc ydb database get <DB_name>
Where
<DB_name>
is the name of the DB you created.While being created, your database will have the
PROVISIONING
status. Once it is ready for use, its status will change toRUNNING
.
Create a database on dedicated servers
-
In the management console
, select the folder to create your DB in. -
In the list of services, select Managed Service for YDB.
-
Click Create a database.
-
Enter the Name of the DB. The naming requirements are as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
Under Database type, select
Dedicated
. -
Under Computing resources, select the type and amount of computing resources.
-
Under Storage groups, select the disk type and number of storage groups that determines the total amount of storage.
-
Under Network, configure network settings:
-
(Optional) In the Public IP addresses field, select Assign if you plan to run queries against the DB both from the Yandex Cloud network and the internet.
Warning
For Managed Service for YDB databases with external IPs, the usage of outgoing internet traffic is counted by the current pricing policy.
The charges for outgoing internet traffic generated by Managed Service for YDB usage will be offset by grants.
-
Select an existing network from the Cloud network list or create a new one:
- Click Create new.
- In the window that opens, enter a Name for the new network.
- (Optional) Select the Create subnets option. Subnets in each availability zone will be created automatically.
- Click Create network.
-
Under Subnets, select a subnet or create a new one for each availability zone:
- Click Create new.
- In the window that opens, enter a Name for the new subnet.
- (Optional) Enter a Description of the subnet.
- Select the availability zone you need from the Zone list.
- Set the subnet address in CIDR
format. - Click Create subnet.
You cannot change the settings of the Network section after the database is created.
-
-
Click Create a database.
Wait for the DB to start. While being created, your database will have the
Provisioning
status. Once it is ready for use, its status will change toRunning
.
-
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
-
Create a cloud network and subnets for each availability zone, if required.
-
Create a database:
yc ydb database create <DB_name> \ --dedicated \ --resource-preset <configuration> \ --storage type=<media_type>,groups=<number_of_storage_groups> \ --public-ip \ --network-name default\ --async
Where:
--resource-preset STR
: Configuration of the node computing resources. You can find the possible values in the Configuration name column of the table in Database on dedicated resources.--storage STR
: Media type and number of storage groups, intype=<media_type>,groups=<number_of_storage_groups>
format. For thessd
type, a single storage group can store up to 100 GB of data.--public-ip
: Public IP address assignment flag. Without it, you cannot connect to the database you created from the internet.--network-name STR
: Name of the cloud network to create the database in. You can specify the network asdefault
.--async
: Asynchronous DB creation flag.
For more information about DB parameters, see Creating a serverless database.
Result:
done (7m18s) id: etnk1u65e4sh******** folder_id: b1g7gvsi89m3******** created_at: "2022-05-31T10:10:12Z" name: test-ded status: PROVISIONING endpoint: grpcs://lb.etnk1u65e4shtgj338va.ydb.mdb.yandexcloud.net:2135/?database=/ru-central1/b1gia87mbaom********/etnk1u65e4sh******** resource_preset_id: medium storage_config: storage_options: - storage_type_id: ssd group_count: "1" storage_size_limit: "107374182400" scale_policy: fixed_scale: size: "1" network_id: enpqkm0od2bu******** subnet_ids: - b0cmespgm8o3******** - e2lif378n1pg******** - e9b72lv142k4******** dedicated_database: resource_preset_id: medium storage_config: storage_options: - storage_type_id: ssd group_count: "1" storage_size_limit: "107374182400" scale_policy: fixed_scale: size: "1" network_id: enpqkm0od2bu******** subnet_ids: - b0cmespgm8o3******** - e2lif378n1pg******** - e9b72lv142k4******** assign_public_ips: true assign_public_ips: true location_id: ru-central1 backup_config: backup_settings: - name: daily backup_schedule: daily_backup_schedule: execute_time: hours: 17 backup_time_to_live: 172800s type: SYSTEM monitoring_config: {}
-
Check the status of the created database:
yc ydb database get <DB_name>
Where
<DB_name>
is the name of the DB you created.While being created, your database will have the
PROVISIONING
status. Once it is ready for use, its status will change toRUNNING
.
Run a query to the database
-
In the management console
, select the folder where the desired bucket is located. -
In the list of services, select Managed Service for YDB.
-
Select the previously created database.
-
Go to the Navigation tab.
-
Click New SQL query and enter the query text.
SELECT 1;
-
Click Run.
See the query result below:
# column0 0 1
-
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
-
To manage your DBs from the command line, install
the YDB CLI. -
To authenticate the YDB CLI in Yandex Cloud, get an IAM token and export it to the following environment variable:
export IAM_TOKEN=`yc iam create-token`
-
Get the DB endpoint and path:
yc ydb database get ydb-prod
Result:
... endpoint: grpcs://ydb.serverless.yandexcloud.net:2135/?database=/ru-central1/b1gia87mbaom********/etnudu2n9ri3******** ...
Here, a part of the
grpcs://ydb.serverless.yandexcloud.net:2135
string contains the endpoint, while/ru-central1/b1gia87mbaom********/etnudu2n9ri3********
specifies the DB path. -
Run a query to the previously created DB using the resulting endpoint value and DB path:
ydb \ --endpoint grpcs://ydb.serverless.yandexcloud.net:2135 \ --database /ru-central1/b1gia87mbaom********/etnudu2n9ri3******** \ yql -s "SELECT 1;"
Result:
┌─────────┐ | column0 | ├─────────┤ | 1 | └─────────┘
What's next
- Learn more about working with DBs.
- Read about service concepts.
- Learn more about the YQL
query language.