Updated on 2026-07-21 GMT+08:00

Querying Historical Top SQL (Instantaneous)

Function

This API is used to query historical top SQL (instantaneous).

Authorization Information

Each account has all the permissions required to call all APIs, but IAM users must be assigned the required permissions.
  • If you are using role/policy-based authorization, see Permissions and Supported Actions for details on the required permissions.
  • If you are using identity policy-based authorization, the following identity policy-based permissions are required.

Action

Access Level

Resource Type (*: required)

Condition Key

Alias

Dependencies

rds:instance:getTopSql

list

-

g:EnterpriseProjectId

g:ResourceTag/<tag-key>

-

-

Constraints

This API is available only for RDS for PostgreSQL.

URI

  • URI format

    GET /v3/{project_id}/instances/{instance_id}/history-top-sql?start_time={start_time}&end_time={end_time}

  • Parameter description
    Table 1 Parameters

    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

    N/A

    Default Value

    N/A

    instance_id

    Yes

    Definition

    Instance ID.

    You can obtain the value of this parameter from id in Table 4 by calling the API for querying DB instances.

    Constraints

    N/A

    Range

    N/A

    Default Value

    N/A

    user_name

    No

    Definition

    Username.

    Constraints

    N/A

    Range

    N/A

    Default Value

    N/A

    database_name

    No

    Definition

    Database name.

    Constraints

    N/A

    Range

    N/A

    Default Value

    N/A

    start_time

    Yes

    Definition

    Start time.

    Constraints

    The value is in the UTC timestamp format.

    Range

    N/A

    Default Value

    N/A

    end_time

    Yes

    Definition

    End time.

    Constraints

    The value is in the UTC timestamp format.

    Range

    N/A

    Default Value

    N/A

    offset

    No

    Definition

    Index offset. If offset is set to N, the query starts from the N+1 piece of data. The value 0 indicates that the query starts from the first piece of data.

    Constraints

    The value must be a non-negative number.

    Range

    An integer greater than or equal to 0

    Default Value

    0

    limit

    No

    Definition

    Number of records returned by a query.

    Constraints

    N/A

    Range

    [1, 1000]

    Default Value

    100

Request

None

Example Request

Query historical top SQL (instantaneous).

GET https://{Endpoint}/v3/0483b6b16e954cb88930a360d2c4e663/instances/24c6678f474241fe89ee9c42f768022ein03/history-top-sql?start_time=1764669600000&end_time=1765249000000

Response

  • Normal response
    Table 2 Parameters

    Parameter

    Type

    Description

    total_count

    Integer

    Definition

    Total number of records.

    Range

    N/A

    top_sqls

    Array of objects

    Definition

    Top SQL statement list.

    For details, see Table 3.

    Table 3 top_sqls field description

    Parameter

    Type

    Description

    sample_time

    String

    Definition

    Sampling time.

    Range

    N/A

    count

    Integer

    Definition

    Quantity.

    Range

    N/A

    database_name

    String

    Definition

    Database name.

    Range

    N/A

    user_name

    String

    Definition

    Username.

    Range

    N/A

    sql_statement

    String

    Definition

    SQL statement.

    Range

    N/A

    query_id

    String

    Definition

    Query ID.

    Range

    N/A

  • Example normal response
    { 
      "top_sqls" : [ { 
        "sample_time" : "2025-12-02 18:03:27", 
        "count" : 1, 
        "database_name" : "", 
        "user_name" : "", 
        "sql_statement" : "", 
        "query_id" : "" 
      } ], 
      "total_count" : 1 
    }
  • Abnormal response

    For details, see Abnormal Request Results.

Status Code

Error Code

For details, see Error Codes.