Managing databases in Sharded PostgreSQL
You can add and delete databases, and view their info.
Getting a list of cluster databases
- Navigate
to Yandex Managed Service for Sharded PostgreSQL. - Click the name of your cluster and select the Databases tab.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To get a list of cluster databases, run this command:
yc managed-sharded-postgresql database list \
--cluster-id <cluster_ID>
You can get the cluster ID with the list of clusters in the folder.
-
Get an IAM token for API authentication and put it into 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-spqr/v1/clusters/<cluster_ID>/databases'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.
-
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 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/spqr/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.spqr.v1.DatabaseService.ListYou can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
Getting database info
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To get database info, run this command:
yc managed-sharded-postgresql database get <database_name> \
--cluster-id <cluster_ID>
You can get the database name with the list of databases in the cluster, and the cluster ID, with the list of clusters in the folder.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Database.Get method, e.g., via the following cURL
request:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-spqr/v1/clusters/<cluster_ID>/databases/<DB_name>'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 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 that the repository contents reside in the
~/cloudapi/directory. -
Call the DatabaseService.Get 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/spqr/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.spqr.v1.DatabaseService.GetYou can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
Creating a database
-
Navigate
to Yandex Managed Service for Sharded PostgreSQL. -
Click the name of your cluster and select the Databases tab.
-
Click Create database.
-
Specify database settings:
-
Name
The database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. The following names are reserved:
postgres,template0, andtemplate1. You cannot create databases with these names. -
Deletion protection
The possible values are:
- Like the cluster
- Enabled
- DIsabled
-
-
Click Create.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To create a database in a cluster:
-
See the description of the CLI command for creating a database:
yc managed-sharded-postgresql database create --help -
Create a database by running this command:
yc managed-sharded-postgresql database create <DB_name> \ --cluster-id <cluster_ID>Where:
-
<DB_name>: Name of your new database.The database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. The following names are reserved:
postgres,template0, andtemplate1. You cannot create databases with these names. -
--cluster-id: Cluster ID which you can get with the list of clusters in the folder.
-
-
Open the current Terraform configuration file with the infrastructure plan.
To learn how to create this file, refer to Creating a Sharded PostgreSQL cluster.
-
Add the
yandex_mdb_sharded_postgresql_databaseresource:resource "yandex_mdb_sharded_postgresql_database" "<local_DB_name>" { cluster_id = <cluster_ID> name = "<DB_name>" }Where:
-
cluster_id: Cluster ID which you can get with the list of clusters in the folder. -
name: Database name.The database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. The following names are reserved:
postgres,template0, andtemplate1. You cannot create databases with these names.
For more information about the
yandex_mdb_sharded_postgresql_databaseresource, see this Terraform provider guide. -
-
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 intended 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.
-
-
-
Get an IAM token for API authentication and put it into 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" \ --url 'https://mdb.api.cloud.yandex.net/managed-spqr/v1/clusters/<cluster_ID>/databases' \ --data '{ "databaseSpec": { "name": "<DB_name>", "deletionProtection": "<protect_database_from_deletion>" } }'Where:
-
<cluster_ID>: Cluster ID which you can get with the list of clusters in the folder. -
databaseSpec: New database settings:-
name: Database name.The database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. The following names are reserved:
postgres,template0, andtemplate1. You cannot create databases with these names. -
deletionProtection: Database deletion protection,trueorfalse.
-
-
-
Check 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 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/spqr/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "database_spec": { "name": "<DB_name>", "deletion_protection": "<protect_database_from_deletion>" } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.spqr.v1.DatabaseService.CreateWhere:
-
cluster_id: Cluster ID which you can get with the list of clusters in the folder. -
database_spec: New database settings:-
name: Database name.The database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. The following names are reserved:
postgres,template0, andtemplate1. You cannot create databases with these names. -
deletion_protection: Database deletion protection,trueorfalse.
-
-
-
Check the server response to make sure your request was successful.
Deleting a database
To delete a database:
- Navigate
to Yandex Managed Service for Sharded PostgreSQL. - Click the name of your cluster and select the Databases tab.
- Find the database you need in the list, click
in its row, select Delete, then confirm the deletion.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To delete a database, run this command:
yc managed-sharded-postgresql database delete <DB_name> \
--cluster-id <cluster_ID>
You can get the database name with the list of databases in the cluster, and the cluster ID, with the list of clusters in the folder.
-
Open the current Terraform configuration file with the infrastructure plan.
To learn how to create this file, refer to Creating a Sharded PostgreSQL cluster.
-
Delete the
yandex_mdb_sharded_postgresql_databaseresource describing 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 updating the resources.
-
Run this command to view the intended 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.
-
-
-
Get an IAM token for API authentication and put it into 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-spqr/v1/clusters/<cluster_ID>/databases/<DB_name>'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 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 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/spqr/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.spqr.v1.DatabaseService.DeleteYou can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.