Create a database

更新时间:
复制 MD 格式

This topic describes how to create a database in Hologres using the Hologres console and a psql client.

Prerequisites

  • You have created a Hologres instance. For more information, see Purchase a Hologres instance.

  • Only a superuser or an account with database creation permissions can create a database.

Background

After you create a Hologres instance, the system automatically creates a database named postgres. This database has limited resources and is intended only for management purposes. We recommend that you create a new database for your business workloads.

Create a database using the Hologres console

  1. Go to the Hologres console and click Instances in the left navigation pane.

  2. On the Instances page, click the instance name.

    Alternatively, you can click Manage in the Actions column of the target instance to open the instance details page.

  3. In the left navigation pane of the instance details page, click Database Management.

  4. On the Database Authorization page, click Create Database in the upper-right corner.

  5. In the Create Database dialog box, select an Instance Name, enter a Database Name, and select a Permission Model based on your business requirements. We recommend that you select SPM.

    Permission model

    Description

    Simple Permission Model (SPM)

    This permission model grants permissions at the database level and defines four roles: admin, developer, writer, and viewer. This allows you to securely and easily manage permissions on database objects. For more information, see Simple Permission Model (SPM).

    Schema-level permission model (SLPM)

    This permission model grants permissions at the schema level and defines roles such as <db>.admin, <db>.<schema>.developer, <db>.<schema>.writer, and <db>.<schema>.viewer. It provides more fine-grained control than the Simple Permission Model. For more information, see Schema-level permission model (SLPM).

    Expert model

    This model is identical to the standard PostgreSQL permission model. For more information, see Expert permission model.

  6. Click OK.

    You can view the created databases on the Database Authorization page.

Create a database using a psql client

  1. Connect to your Hologres instance from a psql client. For more information, see psql client.

  2. Sample SQL statements:

    CREATE DATABASE NewDatabaseName;
    CREATE DATABASE test; -- This command creates a database named test.
  3. Run the \l command to list all databases in the current instance.

    postgres=# \l
                                       List of databases
       Name    |    Owner    | Encoding |    Collate    |     Ctype     |   Access privileges
    -----------+-------------+----------+---------------+---------------+-----------------------
     xxx       | xxx         | UTF8     | en_US.UTF-8   | en_US.UTF-8   | xxx
     xxx       | xxx         | UTF8     | en_US.UTF-8   | en_US.UTF-8   | xxx
     xxx       | xxx         | UTF8     | en_US.UTF-8   | en_US.UTF-8   |
     xxx       | xxx         | UTF8     | en_US.UTF-8   | en_US.UTF-8   |
     xxx       | xxx         | UTF8     | en_US.UTF-8   | en_US.UTF-8   |
     xxx       | xxx         | UTF8     | en_US.UTF-8   | en_US.UTF-8   |
     xxx       | xxx         | UTF8     | en_US.UTF-8   | en_US.UTF-8   |
     test      | xxx         | UTF8     | en_US.UTF-8   | en_US.UTF-8   | xxx
    (8 rows)
  4. Run the \c NewDatabaseName command to connect to the new database. Replace NewDatabaseName with the name of your database.

    postgres=# \c test
    psql (11.8, server 11.3)
    You are now connected to database "test" as user "xxx".
    test=#

Next steps

You can use standard PostgreSQL statements in the psql client for data development. For example, import data from MaxCompute by using SQL.

You can also use HoloWeb for data development. For more information, see Connect to HoloWeb and run queries.