All Products
Search
Document Center

Database Autonomy Service:GetMySQLAllSessionAsync

Last Updated:Mar 13, 2026

Asynchronously queries the sessions of an instance and collects statistics on the sessions based on dimensions.

Operation description

Note

GetMySQLAllSessionAsync is an asynchronous operation. After a request is sent, the system does not return complete results but returns a request ID. You need to use the request ID to initiate requests until the value of the isFinish field in the returned results is true, the complete results are returned. This indicates that to obtain complete data, you must call this operation at least twice.

  • This operation is applicable only to ApsaraDB RDS for MySQL instances, PolarDB for MySQL clusters, and PolarDB-X 2.0 instances.

  • If you use an Alibaba Cloud SDK or Database Autonomy Service (DAS) SDK to call this operation, we recommend that you use the latest version of the SDK.

  • If you use an SDK to call operations of DAS, you must set the region ID to cn-shanghai.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

hdm:GetMySQLAllSessionAsync

get

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

InstanceId

string

Yes

The instance ID.

Note

Only ApsaraDB RDS for MySQL, PolarDB for MySQL, and PolarDB-X 2.0 instances are supported.

rm-2ze8g2am97624****

NodeId

string

No

The node ID.

Note

You must specify this parameter for PolarDB for MySQL clusters. If you do not specify a node ID, the session data of the primary node is returned by default.

pi-wz954ryd8f893****

ResultId

string

No

The asynchronous request ID.

Note

GetMySQLAllSessionAsync is an asynchronous operation. After a request is sent, the system does not return complete results but returns a request ID. You need to use the request ID to initiate requests until the value of the isFinish field in the returned results is true, the complete results are returned. This indicates that to obtain complete data, you must call this operation at least twice.

async__507044db6c4eadfa2dab9b084e80****

Response elements

Element

Type

Description

Example

object

Code

integer

The HTTP status code returned.

200

Message

string

The returned message.

Note

If the request was successful, Successful is returned. If the request failed, an error message such as an error code is returned.

Successful

Data

object

The data returned.

Fail

boolean

Indicates whether the asynchronous request failed. Valid values:

  • true

  • false

false

SessionData

object

The session data.

TotalSessionCount

integer

The total number of sessions.

988

ActiveSessionCount

integer

The total number of active sessions.

10

MaxActiveTime

integer

The maximum execution duration of an active session. Unit: seconds.

6

SessionList

array<object>

The sessions.

object

SessionId

integer

The session ID.

14521783

User

string

The username of the database account.

testUser

Client

string

The IP address of the client.

47.100.XX.XX

DbName

string

The database name.

dbTest

Command

string

The type of the command executed in the session.

Query

Time

integer

The execution duration of the session. Unit: seconds.

6

State

string

The status of the session.

starting

SqlText

string

The SQL statement executed in the session.

INSERT INTO ...

UserClientAlias

string

The alias of the IP address of the client.

master-shanghai

TrxId

string

The ID of the transaction to which the session belongs.

754300775132

TrxDuration

integer

The duration of the transaction. Unit: seconds.

6

SqlTemplateId

string

The SQL template ID.

Note

This parameter is returned only when you use a PolarDB-X 2.0 instance.

a7cac1a9

UserStats

array<object>

The sessions that are counted by database account.

object

Key

string

The database account.

testUser

TotalCount

integer

The total number of sessions within the account.

2

ActiveCount

integer

The number of active sessions within the account.

Note

If the type of the command executed in the session is Query or Execute and the session in the transaction is not terminated, the session is active.

1

ThreadIdList

array

The IDs of the sessions within the account.

integer

The session IDs.

[14525727,14526269]

UserList

array

The database accounts to which the sessions belong.

string

The database account.

['testUser']

ClientStats

array<object>

The sessions that are counted by client IP address.

object

Key

string

The IP address of the client.

47.100.XX.XX

TotalCount

integer

The total number of sessions that belong to the client IP address.

2

ActiveCount

integer

The number of active sessions that belong to the client IP address.

Note

If the type of the command executed in the session is Query or Execute and the session in the transaction is not terminated, the session is active.

1

ThreadIdList

array

The IDs of the sessions that belong to the client IP address.

integer

The session IDs.

[14526018,14525956]

UserList

array

The database accounts to which the sessions belong.

string

The database account.

['testUser']

DbStats

array<object>

The sessions that are counted by database.

object

Key

string

The database name.

dbTest

TotalCount

integer

The total number of sessions of the database.

2

ActiveCount

integer

The number of active sessions of the database.

Note

If the type of the command executed in the session is Query or Execute and the session in the transaction is not terminated, the session is active.

1

ThreadIdList

array

The IDs of the sessions of the database.

integer

The session IDs.

[14525727,14526269]

UserList

array

The database accounts to which the sessions belong.

string

The database account.

['testUser']

TimeStamp

integer

The time when the session was queried. This value is a UNIX timestamp representing the number of milliseconds that have elapsed since January 1, 1970, 00:00:00 UTC.

1659581514000020

ResultId

string

The ID of the asynchronous request.

async__507044db6c4eadfa2dab9b084e80****

IsFinish

boolean

Indicates whether the asynchronous request was complete. Valid values:

  • true

  • false

true

State

string

The state of the asynchronous request. Valid values:

  • RUNNING

  • SUCCESS

  • FAIL

SUCCESS

Complete

boolean

Indicates whether the asynchronous request was complete. Valid values:

  • true

  • false

true

Timestamp

integer

The time when the asynchronous request was made. This value is a UNIX timestamp representing the number of milliseconds that have elapsed since January 1, 1970, 00:00:00 UTC.

1660100753556

RequestId

string

The request ID.

B6D17591-B48B-4D31-9CD6-9B9796B2****

Success

boolean

Indicates whether the request was successful. Valid values:

  • true

  • false

true

Examples

Success response

JSON format

{
  "Code": 200,
  "Message": "Successful",
  "Data": {
    "Fail": false,
    "SessionData": {
      "TotalSessionCount": 988,
      "ActiveSessionCount": 10,
      "MaxActiveTime": 6,
      "SessionList": [
        {
          "SessionId": 14521783,
          "User": "testUser",
          "Client": "47.100.XX.XX",
          "DbName": "dbTest",
          "Command": "Query",
          "Time": 6,
          "State": "starting",
          "SqlText": "INSERT INTO ...",
          "UserClientAlias": "master-shanghai",
          "TrxId": "754300775132",
          "TrxDuration": 6,
          "SqlTemplateId": "a7cac1a9"
        }
      ],
      "UserStats": [
        {
          "Key": "testUser",
          "TotalCount": 2,
          "ActiveCount": 1,
          "ThreadIdList": [
            0
          ],
          "UserList": [
            "['testUser']"
          ]
        }
      ],
      "ClientStats": [
        {
          "Key": "47.100.XX.XX",
          "TotalCount": 2,
          "ActiveCount": 1,
          "ThreadIdList": [
            0
          ],
          "UserList": [
            "['testUser']"
          ]
        }
      ],
      "DbStats": [
        {
          "Key": "dbTest",
          "TotalCount": 2,
          "ActiveCount": 1,
          "ThreadIdList": [
            0
          ],
          "UserList": [
            "['testUser']"
          ]
        }
      ],
      "TimeStamp": 1659581514000020
    },
    "ResultId": "async__507044db6c4eadfa2dab9b084e80****",
    "IsFinish": true,
    "State": "SUCCESS",
    "Complete": true,
    "Timestamp": 1660100753556
  },
  "RequestId": "B6D17591-B48B-4D31-9CD6-9B9796B2****",
  "Success": true
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidParams The request parameters are invalid.
403 NoPermission You are not authorized to do this action.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.