Managing databases in Yandex MPP Analytics for PostgreSQL
Yandex MPP Analytics for PostgreSQL allows you to manage cluster databases using only SQL queries.
A database can be modified or deleted only by its owner.
Getting a list of cluster databases
The list of databases is available to all users.
To get the list of databases in a cluster, run this command:
SELECT * FROM pg_database ORDER BY datname;
Creating a database
To create a database, a role with the CREATEDB attribute is required.
To create a database, run this command:
CREATE DATABASE <DB_name> <parameter_name> <parameter_value>;
There can be several parameter name: parameter value pairs.
Available parameters:
TEMPLATE: Database template. All the DB contents specified in theTEMPLATEparameter will be copied to the new database, including the data tables. The default value istemplate1.CONNECTION LIMIT: Maximum number of connections.
For more information about the available parameters, see the official Greenplum® documentation
For example, to create a database named
db1that can process a maximum of 55 active connections, run this command:CREATE DATABASE db1 CONNECTION LIMIT 55;
Creating a database copy
Creating a database copy requires a role with the CREATEDB attribute.
To create a copy of a database in the same cluster, run this command:
CREATE DATABASE <copy_name> TEMPLATE <name_of_DB_to_copy>;
Learning the size of a database
Database size info is available to all users.
To learn the size of a database, run this command:
SELECT pg_size_pretty(pg_database_size('<DB_name>'));
Renaming a database
To rename a database, run this command:
ALTER DATABASE <DB_name> RENAME TO <new_DB_name>;
Changing the maximum number of database connections
To change the maximum number of connections, run this command:
ALTER DATABASE <DB_name> CONNECTION LIMIT <new_number_of_connections>;
Changing Greenplum® settings at the database level
Settings set at the database level via SQL queries override the cluster-level settings.
Changing a database-level setting:
ALTER DATABASE <DB_name> SET <setting_name> TO <new_setting_value>;
Removing a database-level setting value:
ALTER DATABASE <DB_name> RESET <setting_name>;
Removing all database-level setting values:
ALTER DATABASE <DB_name> RESET ALL;
Note
If a setting's value is removed, it will use the cluster-level value.
Deleting a database
Before deleting, make sure the following conditions are met:
- You are the owner of the database.
- There are no active connections to the database.
- You are connected to another database.
To delete a database, run this command:
DROP DATABASE <DB_name>;
Warning
Deleting a database is irreversible.