Creates a database for a PolarDB cluster.

Before you call this operation, make sure that the following requirements are met:

  • The cluster is in the Running state.
  • The cluster is unlocked.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

ParameterTypeRequiredExampleDescription
ActionStringYesCreateDatabase

The operation that you want to perform. Set the value to CreateDatabase.

DBClusterIdStringYespc-**************

The ID of the cluster.

DBNameStringYestestDB

The name of the database. The name must meet the following requirements:

  • The name can contain lowercase letters, digits, hyphens (-), and underscores (_).
  • The name must start with a lowercase letter and end with a lowercase letter or a digit. The name must be 1 to 64 characters in length.
Note The name cannot be a keyword that is reserved by the system, such as test or mysql.
CharacterSetNameStringYesutf8

The character set that is used by the cluster. For more information, see Character set tables.

DBDescriptionStringNotestdesc

The description of the database. The description must meet the following requirements:

  • It cannot start with http:// or https://.
  • It must be 2 to 256 characters in length.
Note This parameter is required if your cluster is a PolarDB for PostgreSQL(Compatible with Oracle) cluster or a PolarDB for PostgreSQL cluster. This parameter is not required if your cluster is a PolarDB for MySQL cluster.
AccountNameStringNotestacc

The name of the account that is granted permissions to access the database. You can call the DescribeAccounts operation to query account information.

Note
  • You can specify only a standard account. By default, privileged accounts have all permissions on all databases. You do not need to grant the privileged accounts permissions to access the database.
  • This parameter is required if your cluster is a PolarDB for PostgreSQL(Compatible with Oracle) cluster or a PolarDB for PostgreSQL cluster. This parameter is not required if your cluster is a PolarDB for MySQL cluster.
AccountPrivilegeStringNoReadWrite

The permissions that are granted to the account. Valid values:

  • ReadWrite: The account has read and write permissions on the database.
  • ReadOnly: The account has read-only permissions on the database.
  • DMLOnly: The account has only the permissions to execute DML statements on the database.
  • DDLOnly: The account has only the permissions to execute DDL statements on the database.
  • ReadIndex: The account has read and index permissions on the database.

If you leave this parameter empty, the default value ReadWrite is used.

Note
  • This parameter is valid only when the AccountName parameter is specified.
  • This parameter is required if your cluster is a PolarDB for PostgreSQL(Compatible with Oracle) cluster or a PolarDB for PostgreSQL cluster.
  • This parameter is not required if your cluster is a PolarDB for MySQL cluster.
CollateStringNoC

The language that specifies the collation of the database that is to be created.

Note
  • The language must be compatible with the character set that is specified by the CharacterSetName parameter.
  • This parameter is required if your cluster is a PolarDB for PostgreSQL(Compatible with Oracle) cluster or a PolarDB for PostgreSQL cluster. This parameter is not required if your cluster is a PolarDB for MySQL cluster.

    To view the valid values of this parameter, perform the following steps: Log on to the PolarDB console and click the ID of a cluster. In the left-side navigation pane, choose Settings and Management > Databases. Then, click Create Database.

CtypeStringNoC

The language that specifies the character type of the database.

Note
  • The language must be compatible with the character set that is specified by the CharacterSetName parameter.
  • The value of this parameter must be the same as the value of the Collate parameter.
  • This parameter is required if your cluster is a PolarDB for PostgreSQL(Compatible with Oracle) cluster or a PolarDB for PostgreSQL cluster. This parameter is not required if your cluster is a PolarDB for MySQL cluster.

    To view the valid values of this parameter, perform the following steps: Log on to the PolarDB console and click the ID of a cluster. In the left-side navigation pane, choose Settings and Management > Databases. Then, click Create Database.

Response parameters

ParameterTypeExampleDescription
RequestIdString93E98F25-BE02-40DA-83E3-F77F8D******

The ID of the request.

Examples

Sample requests

http(s)://polardb.aliyuncs.com/?Action=CreateDatabase
&DBClusterId=pc-**************
&DBName=testDB
&CharacterSetName=utf8
&DBDescription=testdesc
&AccountName=testacc
&AccountPrivilege=ReadWrite
&Collate=C
&Ctype=C
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateDatabaseResponse>
    <RequestId>93E98F25-BE02-40DA-83E3-F77F8D******</RequestId>
</CreateDatabaseResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "93E98F25-BE02-40DA-83E3-F77F8D******"
}

Error codes

HTTP status codeError codeError messageDescription
400InvalidDBName.MalformedThe specified parameter DBName is not valid.The error message returned because the format of the specified database name is invalid.
400Database.AddErrorInstance %s add database minidoc errorThe error message returned because the database minidoc failed to be added to cluster %s.
404InvalidDBCluster.NotFoundThe DBClusterId provided does not exist in our records.The error message returned because the specified cluster ID does not exist in the current record.

For a list of error codes, see Service error codes.