Database management

You can add and remove databases, as well as view information about them.

Getting a list of cluster databases

  1. Go to the folder page and select Managed Service for PostgreSQL.
  2. Click on the name of the cluster you need and select the Databases tab.

If you don't have the Yandex.Cloud command line interface yet, install 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 flag.

To get a list of databases in a cluster, run the command:

$ yc managed-postgresql database list
     --cluster-name=<cluster name>

The cluster name can be requested with a list of clusters in the folder.

To get a list of cluster databases, use the list method.

Creating a database

The number of databases in a cluster is unlimited.

Important

By default, databases are created with string collation and sorting settings: LC_COLLATE=C and LC_CTYPE=C. This allows PostgreSQL to more effectively execute queries with string data, but it canwork subtly (for example, with Cyrillic).

These settings are covered in more detail in the PostgreSQL documentation.

The LC_COLLATE and LC_CTYPE settings of a database cannot be changed after its creation. To create a database with the necessary values for these settings, use such flags as --lc-collate и --lc-type in the yc managed-postgresql database create CLI command.

Once the database is created, you can specify the collation and order sorting settings for columns when creating and changingtables. Learn more in the PostgreSQL documentation.

  1. Go to the folder page and select Managed Service for PostgreSQL.
  2. Click on the name of the cluster you need.
  3. If the owner of the new database still doesn't exist, add the user.
  4. Select the Databases tab.
  5. Click Add.
  6. Enter the database name and select its owner.

If you don't have the Yandex.Cloud command line interface yet, install 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 flag.

To create a database in a cluster:

  1. See the description of the CLI's create database command:

    $ yc managed-postgresql database create --help
    
  2. Request a list of cluster users to select the owner of the new database:

    $ yc managed-postgresql user list
         --cluster-name <cluster name>
    

    If the required user is not in the list, create a user.

  3. Run the create database command:

    $ yc managed-postgresql database create <database name>
         --cluster-name <cluster name>
         --owner <DB owner username>
    

    Managed Service for PostgreSQL runs the create database operation.

The cluster name can be requested with a list of clusters in the folder.

You can create a new database in a cluster using the create method.

Deleting a database

  1. Go to the folder page and select Managed Service for PostgreSQL.
  2. Click on the name of the cluster you need and select the Databases tab.
  3. Click image in the line of the necessary DB and select Delete.

If you don't have the Yandex.Cloud command line interface yet, install 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 flag.

To delete a database, run the command:

$ yc managed-postgresql database delete <database name>
     --cluster-name=<cluster name>

The cluster name can be requested with a list of clusters in the folder.

You can delete a database using the delete method.

Important

Before creating a new database with the same name, wait for the delete operation to complete, otherwise the database being deleted is restored. Operation status can be obtained with a list of cluster operations.