Updated on 2025-08-19 GMT+08:00

Creating a Database

Function

This API is used to create a database in a specified DB instance. Before calling this API:

Constraints

This API can only be used to create a single database. This operation cannot be performed when the instance is in any of the following statuses: creating, changing instance specifications, frozen, or abnormal.

URI

POST /v3/{project_id}/instances/{instance_id}/database

Table 1 Parameter description

Parameter

Mandatory

Description

project_id

Yes

Definition

Project ID of a tenant in a region.

To obtain the value, see Obtaining a Project ID.

Constraints

N/A

Range

The value can contain 32 characters. Only letters and digits are allowed.

Default Value

N/A

instance_id

Yes

Definition

Instance ID, which uniquely identifies an instance.

Constraints

N/A

Range

The value can contain 36 characters. Only letters and digits are allowed.

Default Value

N/A

Request Parameters

Table 2 Parameter description

Parameter

Mandatory

Type

Description

name

Yes

String

Definition

Database name.

Constraints

N/A

Range

The value can contain 1 to 63 characters, including letters, digits, and underscores (_). It cannot start with pg or a digit, and must be different from template database names. Template databases include postgres, template0, template1, and templatem.

Default Value

N/A

character_set

No

String

Definition

Database character set.

Constraints

N/A

Range

For details, see "Developer Guide" > "SQL Reference" > "Character Sets and Collations."

Default Value

If this parameter is not specified, the UTF-8 encoding format is used for the M-compatible database by default, and the encoding format of the template database is used for other databases by default.

owner

No

String

Definition

Database owner.

Constraints

It must be an existing user not named after any system user.

System users: rdsAdmin, rdsMetric, rdsBackup, and rdsRepl.

Range

N/A

Default Value

root

template

No

String

Definition

Database template name.

Constraints

Only centralized instances of version 2.0-8.100 or later as well as distributed instance of version V2.0-8.200 or later support creation of M-compatible databases using the templatem template.

Range

template0, templatea, or templatem

Default Value

N/A

lc_collate

No

String

Definition

Database collation.

Comparison of the same string in different collations may have different results. For example, the execution result of select 'a'>'A'; is false when this parameter is set to en_US.utf8 and is true when this parameter is set to 'C'. If a database is migrated from Oracle Database to GaussDB, this parameter needs to be set to 'C' to meet your expectations. You can query the supported collations from the pg_collation table.

Constraints

N/A

Range

N/A

Default Value

C

lc_ctype

No

String

Definition

Character classification.

Constraints

N/A

Range

N/A

Default Value

C

Response Parameters

None

Example Request

Creating a database named gaussdb_test
POST https://gaussdb-opengauss.ap-southeast-1.myhuaweicloud.com/v3/0483b6b16e954cb88930a360d2c4e663/instances/{instance_id}/database
{ 
   "name" : "gaussdb_test", 
   "owner" : "test", 
   "template" : "template0", 
   "character_set" : "UTF8", 
   "lc_collate" : "en_US.UTF-8", 
   "lc_ctype" : "en_US.UTF-8" 
 }

Example Response

None

Status Codes

Error Codes

For details, see Error Codes.