Skip to main content
To work with a database in a Managed Service for PostgreSQL cluster, you need to connect to it. Once you connect to the cluster, all PostgreSQL commands are available for you to execute. For example, you can perform these basic operations:

How to create databases

To create a database, run the CREATE DATABASE command:
CREATE DATABASE <name>;
Every cluster has at least one default database, which you specified when creating the cluster. Use the \l command to list all databases in the cluster. When a new database is created, you don’t automatically switch to it. Use the \c <name> command to connect to the database you just created.

How to modify databases

To make changes to a database, run the ALTER DATABASE command:
ALTER DATABASE <name> <changes>;
For example, you can rename the database:
ALTER DATABASE db_test RENAME TO old_testdb;
Note that you can’t rename the current database. Connect to another database, first.

How to delete databases

Do not delete the default database, as this may cause the service to malfunction.
To delete a database, run the DROP DATABASE command. This operation cannot be undone.
DROP DATABASE <name>;

Postgres, PostgreSQL and the Slonik Logo are trademarks or registered trademarks of the PostgreSQL Community Association of Canada, and used with their permission.