gv$sql_audit is the global SQL audit table. It shows the client of each query, information about the execution server, execution status, wait events, and time consumed for each execution stage.
sql_audit settings
Set the switch of
sql_audit.obclient> ALTER SYSTEM SET enable_sql_audit = true; /*Enable sql_audit*/ obclient> ALTER SYSTEM SET enable_sql_audit = false; /*Disable sql_audit*/Set the maximum memory usage of
sql_audit. By default, the maximum memory usage is 3 GB, and it can be configured in the range of [64 MB, +∞).obclient> ALTER SYSTEM SET sql_audit_memory_limit = '3G'; Query OK, 0 rows affected
Eviction mechanism of sql_audit
sql_auditchecks its backend task once every other 1s and determines whether to start eviction based on the following criteria:The maximum memory that can be utilized by
sql_auditis determined byavail_mem_limit = min (available memory on the OBServer node × 10%,sql_audit_memory_limit).- If
avail_mem_limitfalls in the range of [64 MB, 100 MB], eviction is triggered when the memory used reachesavail_mem_limit - 20 MB. - If
avail_mem_limitfalls in the range of [100 MB, 5 GB], eviction is triggered when the memory used reachesavail_mem_limit × 0.8. - If
avail_mem_limitfalls in the range of [5 GB, +∞), eviction is triggered when memory usage reachesavail_mem_limit - 1 GB.
- If
Eviction is also triggered when the number of records in
sql_auditexceeds 9 million.
sql_auditstops eviction by the following criteria:If the eviction is triggered by reaching the upper memory usage limit:
- If
avail_mem_limitfalls in the range of [64 MB, 100 MB], eviction is stopped when the memory used drops toavail_mem_limit - 40 MB. - If
avail_mem_limitfalls in the range [100 MB, 5 GB], eviction is stopped when the memory used drops toavail_mem_limit × 0.6. - If
avail_mem_limitfalls in the range [5 GB, +∞), eviction is stopped when the memory used drops toavail_mem_limit - 2 GB.
- If
If the eviction is triggered by the upper record number limit, it is stopped when the number of record rows drops to 8 million.
sql_audit fields
| Field | Type | Description |
|---|---|---|
| SVR_IP | varchar(32) | The IP address. |
| SVR_PORT | bigint(20) | The port number. |
| REQUEST_ID | bigint(20) | The ID of the request. |
| SQL_EXEC_ID | bigint(20) | If an SQL plan is being executed, the value is the corresponding SQL ID. |
| TRACE_ID | varchar(128) | The trace ID of the statement. |
| SID | bigint(20) unsigned | The ID of the session. |
| CLIENT_IP | varchar(32) | The IP address of the client that sends the request. |
| CLIENT_PORT | bigint(20) | The port of the client that sends the request. |
| TENANT_ID | bigint(20) | The ID of the tenant that sent the request. |
| TENANT_NAME | varchar(64) | The name of the tenant that sent the request. |
| EFFECTIVE_TENANT_ID | bigint(20) | The ID of the tenant. |
| USER_ID | bigint(20) | The ID of the user that sent the request. |
| USER_NAME | varchar(64) | The name of the user that sent the request. |
| USER_GROUP | bigint(20) | The user group. |
| USER_CLIENT_IP | varchar(46) | The IP address of the client that sent the request. |
| DB_ID | bigint(20) unsigned | The ID of the database. |
| DB_NAME | varchar(128) | The name of the database. |
| SQL_ID | varchar(32) | The ID of the SQL query. |
| QUERY_SQL | varchar(32768) | The actual SQL statement. |
| PLAN_ID | bigint(20) | The ID of the execution plan. |
| AFFECTED_ROWS | bigint(20) | The number of rows affected. |
| RETURN_ROWS | bigint(20) | The number of returned rows. |
| PARTITION_CNT | bigint(20) | The number of partitions scanned by the request. |
| RET_CODE | bigint(20) | The return code of the execution. |
| QC_ID | bigint(20) unsigned | The query coordinator (QC) ID in the parallel query. |
| DFO_ID | bigint(20) | The data flow operator (DFO) ID in the parallel query. |
| SQC_ID | bigint(20) | The subquery coordinator (SQC) ID in the parallel query. |
| WORKER_ID | bigint(20) | The thread ID. |
| EVENT | varchar(64) | The name of the wait event with the longest wait time. |
| P1TEXT | varchar(64) | The first parameter of the wait event. |
| P1 | bigint(20) unsigned | The value of the first parameter of the wait event. |
| P2TEXT | varchar(64) | The second parameter of the wait event. |
| P2 | bigint(20) unsigned | The value of the second parameter of the wait event. |
| P3TEXT | varchar(64) | The third parameter of the wait event. |
| P3 | bigint(20) unsigned | The value of the third parameter of the wait event. |
| LEVEL | bigint(20) | The level of the wait event. |
| WAIT_CLASS_ID | bigint(20) | The ID of the class to which the wait event belongs. |
| WAIT_CLASS# | bigint(20) | The subscript of the class to which the wait event belongs. |
| WAIT_CLASS | varchar(64) | The name of the class to which the wait event belongs. |
| STATE | varchar(19) | The state of the wait event. |
| WAIT_TIME_MICRO | bigint(20) | The wait time of the wait event, in µs. |
| TOTAL_WAIT_TIME_MICRO | bigint(20) | The total wait time in the execution process, in µs. |
| TOTAL_WAITS | bigint(20) | The total number of waits during the execution. |
| RPC_COUNT | bigint(20) | The number of remote procedure calls (RPCs) sent. |
| PLAN_TYPE | bigint(20) | The type of the execution plan. Valid values:
|
| IS_INNER_SQL | tinyint(4) | Indicates whether the request is an internal SQL request. |
| IS_EXECUTOR_RPC | tinyint(4) | Indicates whether the current request is an RPC request. |
| IS_HIT_PLAN | tinyint(4) | Indicates whether the plan cache is hit. |
| REQUEST_TIME | bigint(20) | The time when the execution starts. |
| ELAPSED_TIME | bigint(20) | The amount of time elapsed from when the request was received to when the execution of the request ended. |
| NET_TIME | bigint(20) | The time consumed from RPC sending to request reception. |
| NET_WAIT_TIME | bigint(20) | The time consumed from the reception of a request to the start of queuing. |
| QUEUE_TIME | bigint(20) | The wait time of the request in the queue. |
| DECODE_TIME | bigint(20) | The decoding time of the request after it left the queue. |
| GET_PLAN_TIME | bigint(20) | The time consumed from execution start to plan acquisition |
| EXECUTE_TIME | bigint(20) | The time consumed for plan execution. |
| APPLICATION_WAIT_TIME | bigint(20) unsigned | The total amount of time spent on waiting for events of the application class. |
| CONCURRENCY_WAIT_TIME | bigint(20) unsigned | The total amount of time spent on waiting for events of the concurrency class. |
| USER_IO_WAIT_TIME | bigint(20) unsigned | The total amount of time spent on waiting for the events of the user_io class. |
| SCHEDULE_TIME | bigint(20) unsigned | The total amount of time spent on events of the schedule class. |
| ROW_CACHE_HIT | bigint(20) | The number of row cache hits. |
| BLOOM_FILTER_CACHE_HIT | bigint(20) | The number of Bloom filter cache hits. |
| BLOCK_CACHE_HIT | bigint(20) | The number of block cache hits. |
| BLOCK_INDEX_CACHE_HIT | bigint(20) | The number of block index cache hits. |
| DISK_READS | bigint(20) | The number of physical reads. |
| RETRY_CNT | bigint(20) | The number of retries. |
| TABLE_SCAN | tinyint(4) | Indicates whether the request contains a full table scan. |
| CONSISTENCY_LEVEL | bigint(20) | The consistency level. |
| MEMSTORE_READ_ROW_COUNT | bigint(20) | The number of rows read from MEMSTORE. |
| SSSTORE_READ_ROW_COUNT | bigint(20) | The number of rows read from SSSTORE. |
| REQUEST_MEMORY_USED | bigint(20) | The memory consumed by the request. |
| EXPECTED_WORKER_COUNT | bigint(20) | The number of worker threads expected by the request. |
| USED_WORKER_COUNT | bigint(20) | The number of worker threads used by the request. |
| SCHED_INFO | varchar(16384) | The scheduling information of the request. |
| FUSE_ROW_CACHE_HIT | bigint(20) | At present, this field is not supported and is NULL by default. |
| PS_STMT_ID | bigint(20) | The ID of the PREPARE statement corresponding to the request.
|
| TRANSACTION_HASH | bigint(20) unsigned | The hash value of the transaction corresponding to the request. |
| REQUEST_TYPE | bigint(20) | The type of the request. Valid values:
|
| IS_BATCHED_MULTI_STMT | tinyint(4) | Indicates whether optimization has been performed for batch execution of multiple statements. |
| OB_TRACE_INFO | bigint(20) | The trace information configured by the user. |
| PLAN_HASH | bigint(20) unsigned | The hash value of the execution plan. |
| LOCK_FOR_READ_TIME | bigint(20) | The time in microseconds spent on waiting for locked data to be unlocked before it can be read. |
| WAIT_TRX_MIGRATE_TIME | bigint(20) | When wait events must be frozen due to the inner compaction mechanism during data writes, unfinished transactions must be migrated. This field indicates the time in microseconds required for migrating the unfinished transactions. |
| PARAMS_VALUE | longtext | The parameter value. |