Updated on 2024-08-20 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 https://{Endpoint}/v3/{project_id}/instances/{instance_id}/database

Table 1 Parameter description

Parameter

Mandatory

Description

project_id

Yes

Explanation:

Project ID of a tenant in a region.

For details about how to obtain the project ID, see Obtaining a Project ID.

Restrictions:

None

Value range:

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

Default value:

None

instance_id

Yes

Instance ID.

Request Parameters

Table 2 Parameter description

Parameter

Mandatory

Type

Description

name

Yes

String

Database name.

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.

character_set

No

String

Character set. The default value is UTF8.

owner

No

String

Database user. The default value is root. The value must be an existing username and must be different from system usernames.

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

template

No

String

Name of the database template. The value can be template0.

lc_collate

No

String

Database collation. The default value is C.

NOTICE:

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 "O" 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.

lc_ctype

No

String

Database classification. The default value is 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 Code

Error Code

For details, see Error Codes.