Help Center> GaussDB> API Reference> APIs (Recommended)> Database and Account Management> Configuring Permissions of Database Accounts
Updated on 2024-05-21 GMT+08:00

Configuring Permissions of Database Accounts

Function

This API is used to configure permissions of database accounts for a specified DB instance. Before calling this API:

Constraints

  • This operation cannot be performed when the instance is in any of the following statuses: creating, changing instance specifications, frozen, or abnormal.
  • By default, read-only users have the create and usage permissions on the public schemas.
  • You can only authorize permissions of one schema to one account at a time.

URI

POST https://{Endpoint}/v3/{project_id}/instances/{instance_id}/db-privilege

Table 1 Parameter description

Parameter

Mandatory

Description

project_id

Yes

Project ID of a tenant in a region.

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

instance_id

Yes

DB instance ID.

Request

Table 2 Parameter description

Parameter

Mandatory

Type

Description

db_name

Yes

String

Database name.

The database name contains 1 to 63 characters, including letters, digits, and underscores (_). It cannot start with pg or a digit, and must be different from template library names.

Template libraries include postgres, template0, and template1.

users

Yes

Array of objects

Database accounts. Each element is a database account. A single request supports a maximum of 50 elements. For details, see Table 3.

Table 3 users field data structure description

Parameter

Mandatory

Type

Description

name

Yes

String

Database account.

The database account name contains 1 to 63 characters, including letters, digits, and underscores (_). It cannot start with pg or a digit and must be different from system usernames.

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

readonly

Yes

Boolean

Permission of the database account.

  • true: read only
  • false: read and write

schema_name

Yes

String

Schema name.

The value cannot be empty and contains 1 to 63 characters, including letters, digits, and underscores (_). It cannot start with pg or a digit, and must be different from template library names and existing schema names. This parameter is mandatory.

The template libraries include postgres, template0, template1, public, and information_schema.

Example Request

Configuring permissions for multiple accounts of the gaussdb_test database
POST https://gaussdb-opengauss.ap-southeast-1.myhuaweicloud.com/v3/0483b6b16e954cb88930a360d2c4e663/instances/{instance_id}/db-privilege
{ 
  "db_name" : "gaussdb_test", 
  "users" : [ { 
    "name" : "rds", 
    "readonly" : false, 
    "schema_name" : "teste123" 
  }, { 
    "name" : "rds001", 
    "readonly" : true, 
    "schema_name" : "teste134" 
  }, { 
    "name" : "rds002", 
    "readonly" : false, 
    "schema_name" : "teste135" 
  } ] 
}

Example Response

None

Status Code

Error Code

For details, see Error Codes.