All Products
Search
Document Center

AnalyticDB for PostgreSQL:Manage databases

Last Updated:Jan 26, 2024

A database is a collection of tables, indexes, views, stored procedures, and operators. You can create more than one database in an AnalyticDB for PostgreSQL instance. However, one client program can be used to connect to and access only a single database at a time. This means that you cannot query data across databases.

Create a database

Execute the following CREATE DATABASE statement to create a database:

CREATE DATABASE <dbname> [ [WITH] [OWNER [=] <dbowner>] ]
                      [ENCODING [=] <encoding>] 

Note:

  • <dbname>: the name of the database that you want to create.

  • <dbowner>: the name of the user who owns the database. By default, the user who executes the statement owns the database.

  • <encoding>: the character set encoding to use in the database. You must specify a string constant such as 'SQL_ASCII' and an integer code number. Default value: utf-8.

Example:

CREATE DATABASE mygpdb;

Switch to another database

Use DMS to switch to another database

  1. Use Data Management (DMS) to connect to a database. For more information, see DMS.

  2. In the left-side navigation pane, click Instances Connected. Find and expand the instance to which you have connected.

  3. Find and expand another database and double-click the schema of the database.

Use psql to switch to another database

  1. Use psql to connect to a database. For more information, see psql.

  2. Execute the following command to switch to another database:

    \c <databasename>

    <database_name> specifies the name of the database to which you want to switch.

Delete a database

Execute the following DROP DATABASE statement to delete a database. This statement deletes the metadata of the database along with the directory of the database on the disk and the data contained in the database.

DROP DATABASE <dbname>

Note:

<dbname>: the name of the database that you want to delete.

Example:

DROP DATABASE mygpdb;