Updated on 2025-10-20 GMT+08:00

Querying Real-Time Sessions

Function

This API is used to query real-time sessions of a DB instance. Before calling this API:

Constraints

This API is suitable only for nodes with CNs or DNs (primary or standby DNs).

Debugging

You can debug this API in API Explorer.

URI

POST /v3/{project_id}/instances/{instance_id}/real-time-session

Table 1 Parameter description

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

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

Default Value

N/A

instance_id

Yes

Definition

Instance ID, which uniquely identifies an instance.

Constraints

N/A

Range

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

Default Value

N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Definition

User token.

You can obtain the token by calling the IAM API used to obtain a user token.

After the request is processed, the value of X-Subject-Token in the message header is the token value.

Constraints

N/A

Range

N/A

Default Value

N/A

X-Language

No

String

Definition

Language.

Constraints

N/A

Range

  • zh-cn
  • en-us

Default Value

en-us

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

node_id

Yes

String

Definition

Node ID.

Constraints

This API is suitable only for nodes with CNs or DNs (primary or standby DNs).

Range

N/A

Default Value

N/A

component_id

Yes

String

Definition

Component ID.

Constraints

Only the ID of a CN or DN (primary or standby) component deployed on the node specified by node_id is allowed.

Range

N/A

Default Value

N/A

query_info

No

Object

Definition

Filter criteria used to obtain real-time sessions.

For details, see Table 4.

Constraints

N/A

Table 4 SessionQueryInfo description

Parameter

Mandatory

Type

Description

database_name

No

String

Definition

Database name.

Constraints

N/A

Range

N/A

Default Value

N/A

client_ip

No

String

Definition

IP address of the client.

Constraints

N/A

Range

N/A

Default Value

N/A

user_name

No

String

Definition

Username.

Constraints

N/A

Range

N/A

Default Value

N/A

Response Parameters

Table 5 Response body parameters

Parameter

Type

Description

sessions

Array of objects

Definition

Real-time sessions of the DB instance.

For details, see Table 6.

Table 6 RealTimeSession parameters

Parameter

Type

Description

session_id

String

Definition

Session ID.

Range

N/A

pid

String

Definition

Thread ID.

Range

N/A

unique_sql_id

String

Definition

SQL ID.

Range

N/A

database_name

String

Definition

Database.

Range

N/A

client_ip

String

Definition

IP address of the client.

Range

N/A

user_name

String

Definition

Username.

Range

N/A

wait

String

Definition

Whether to wait.

Range

N/A

block_session

String

Definition

Blocked session ID.

Range

N/A

wait_event

String

Definition

Wait event.

Range

N/A

state

String

Definition

Status.

Range

N/A

query_runtime

String

Definition

Statement execution duration.

Range

N/A

query

String

Definition

SQL text.

Range

N/A

back_end_start

Long

Definition

Start time of the session.

Range

N/A

transaction_start

Long

Definition

Transaction start time.

Range

N/A

query_start

Long

Definition

Start time of the statement.

Range

N/A

application_name

String

Definition

Application name.

Range

N/A

exec_time

String

Definition

Session duration, in seconds.

Range

N/A

trans_num

String

Definition

Number of transactions.

Range

N/A

rollback_num

String

Definition

Number of rollbacks.

Range

N/A

sql_num

String

Definition

Number of SQL statements.

Range

N/A

Example Request

POST https://{Endpoint}/gaussdb/v3/0483b6b16e954cb88930a360d2c4e663/instances/cc6fd964d93f4003851dfc29d57d30a5in14/real-time-session
{
	"node_id": "52c25e148a4a48c293b66ca95565719cno14",
	"component_id": "cn_5001",
        "query_info": {
               "database_name": "postgres",
                "client_ip": "127.0.0.1",
		"user_name": "user1"
        }
}

Example Response

{ 
   "sessions" : [{ 
     "session_id" : "725", 
     "pid" : "140623987341056", 
     "unique_sql_id" : "3545025713", 
     "database_name" : "postgres", 
     "client_ip" : "23.100.74.131", 
     "user_name" : "root", 
     "wait" : "f", 
     "block_session" : "", 
     "wait_event" : "none", 
     "state" : "active", 
     "query_runtime" : "00:00:22.641774", 
     "query" : "select pg_sleep(100);", 
     "back_end_start" : 1690448618645, 
     "transaction_start" : 1690448618689, 
     "query_start" : 1690448618689, 
     "application_name" : "gsql" ,
     "exec_time": "97",
     "trans_num": "0",
     "rollback_num": "0",
     "sql_num": "0"
   }] 
 }

Status Codes

Error Codes

For details, see Error Codes.