A database in AnalyticDB for PostgreSQL is a collection of tables, indexes, views, stored procedures, and operators. Each instance can contain multiple databases, but a client can connect to only one database at a time — cross-database queries are not supported.
Create a database
CREATE DATABASE <dbname> [ [WITH] [OWNER [=] <dbowner>] ]
[ENCODING [=] <encoding>]Parameters:
| Parameter | Description | Default |
|---|---|---|
<dbname> | Name of the database to create. | — |
<dbowner> | User who owns the database. | The user who runs the statement. |
<encoding> | Character set encoding. Specify a string constant such as 'SQL_ASCII' or an integer code number. | utf-8 |
Example:
CREATE DATABASE mygpdb;Switch to another database
Use DMS
Connect to a database using Data Management (DMS). For instructions, see DMS.
In the left-side navigation pane, click Instances Connected.
Find and expand the target instance.
Expand the database you want to switch to, then double-click its schema.
Use psql
Connect to a database using psql. For instructions, see psql.
Run the following command:
\c <databasename>Replace
<databasename>with the name of the database to switch to.
Delete a database
DROP DATABASE permanently removes the database's metadata, the on-disk directory, and all data it contains. This operation cannot be undone.
DROP DATABASE <dbname>Replace <dbname> with the name of the database to delete.
Example:
DROP DATABASE mygpdb;