A database is a collection of tables, indexes, views, stored procedures, and operators. You can create multiple databases in an AnalyticDB for PostgreSQL instance. However, a client application can connect to only one database at a time. Cross-database queries are not supported.
Create a database
To create a new database, use the CREATE DATABASE statement. The syntax is as follows:
CREATE DATABASE <dbname> [ [WITH] [OWNER [=] <dbowner>] ]
[ENCODING [=] <encoding>] Note:
<dbname>: The name of the database to create.<dbowner>: The database user who will own the new database. If omitted, the owner defaults to the user who executes the statement.<encoding>: The character set encoding for the new database. Specify a string constant, such as'SQL_ASCII', or an integer encoding number. The default is utf-8.
Example:
CREATE DATABASE mygpdb;Switch databases
In the DMS console
Log on to your database using Data Management (DMS).
In the left-side navigation pane, under Instances Connected, expand the target instance.
Find and expand the current database, and then double-click the target schema.
In psql
Log on to your database using psql.
Run the following command to switch databases:
\c <databasename><database_name>is the name of the database to switch to.
Delete a database
To delete a database, use the DROP DATABASE statement. This statement permanently removes the database's metadata and deletes the on-disk directory that contains its data. The syntax is as follows:
DROP DATABASE <dbname>Note:
<dbname> is the name of the database to delete.
Example:
DROP DATABASE mygpdb;