GV$OB_SQL_AUDIT is the global SQL audit view. It displays the client of each query and 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 percentage of the tenant memory used by SQL Audit. The default value is
3. You can set the value in the range of [0, 80].obclient> SET global ob_sql_audit_percentage = 3; Query OK, 0 rows affected
Eviction mechanism of SQL Audit
OceanBase Database runs a background task for each tenant to check the memory usage of the OBServer node and SQL Audit every second and determines whether to start SQL eviction. The maximum memory that can be used by SQL Audit is determined by ob_sql_audit_percentage.
When the memory usage of SQL Audit reaches the specified threshold, eviction is triggered. When the memory usage of SQL Audit falls below the specified threshold, eviction stops. The following table describes the eviction mechanism of SQL Audit.
| Trigger condition | Maximum memory for SQL Audit | Eviction triggering threshold | Eviction stopping threshold |
|---|---|---|---|
| Memory usage | [0,64M] | Maximum memory * 50% | 0 M |
| Memory usage | [64M,100M] | Maximum memory - 20 MB | Maximum memory - 40 MB |
| Memory usage | [100M,5G] | Maximum memory * 80% | Maximum memory * 60% |
| Memory usage | [5G,+∞] | Maximum memory - 1 GB | Maximum memory - 2 GB |
| Records | None | 9 million | 8 million |
Fields in GV$OB_SQL_AUDIT
| Field | Type (MySQL mode) | Type (Oracle mode) | Description |
|---|---|---|---|
| SVR_IP | varchar(46) | varchar(46) | The IP address. |
| SVR_PORT | bigint(20) | number(38) | The port number. |
| REQUEST_ID | bigint(20) | number(38) | The ID of the request. |
| SQL_EXEC_ID | bigint(20) | number(38) | If an SQL plan is being executed, the value is the corresponding SQL ID. |
| TRACE_ID | varchar(128) | varchar(128) | The trace ID of the statement. |
| SID | bigint(20) unsigned | number(38) | The ID of the session. |
| CLIENT_IP | varchar(46) | varchar(46) | The IP address of the client that sends the request. |
| CLIENT_PORT | bigint(20) | number(38) | The port of the client that sends the request. |
| TENANT_ID | bigint(20) | number(38) | The ID of the tenant that sent the request. |
| TENANT_NAME | varchar(64) | varchar(46) | The name of the tenant that sends the request. |
| EFFECTIVE_TENANT_ID | bigint(20) | number(38) | The ID of the tenant. |
| USER_ID | bigint(20) | number(38) | The ID of the user that sent the request. |
| USER_NAME | varchar(64) | varchar(46) | The name of the user that sends the request. |
| USER_GROUP | bigint(20) | number(38) | The user group. |
| USER_CLIENT_IP | varchar(32) | varchar(32) | The IP address of the client that sent the request. |
| DB_ID | bigint(20) unsigned | number(38) | The ID of the database. |
| DB_NAME | varchar(128) | varchar(128) | The name of the database. |
| SQL_ID | varchar(32) | varchar(32) | The ID of the SQL query. |
| QUERY_SQL | longtext | CLOB | The actual SQL statement. |
| PLAN_ID | bigint(20) | number(38) | The ID of the execution plan. |
| AFFECTED_ROWS | bigint(20) | number(38) | The number of rows affected. |
| RETURN_ROWS | bigint(20) | number(38) | The number of rows returned. |
| PARTITION_CNT | bigint(20) | number(38) | The number of partitions scanned by the request. |
| RET_CODE | bigint(20) | number(38) | The return code of the execution. |
| QC_ID | bigint(20) unsigned | number(38) | The query coordinator (QC) ID in the parallel query. |
| DFO_ID | bigint(20) | number(38) | The data flow operator (DFO) ID in the parallel query. |
| SQC_ID | bigint(20) | number(38) | The subquery coordinator (SQC) ID in the parallel query. |
| WORKER_ID | bigint(20) | number(38) | The thread ID. |
| EVENT | varchar(64) | varchar(64) | The name of the wait event with the longest wait time. |
| P1TEXT | varchar(64) | varchar(64) | The first parameter of the wait event. |
| P1 | bigint(20) unsigned | number(38) | The value of the first parameter of the wait event. |
| P2TEXT | varchar(64) | varchar(64) | The second parameter of the wait event. |
| P2 | bigint(20) unsigned | number(38) | The value of the second parameter of the wait event. |
| P3TEXT | varchar(64) | varchar(64) | The third parameter of the wait event. |
| P3 | bigint(20) unsigned | number(38) | The value of the third parameter of the wait event. |
| LEVEL | bigint(20) | number(38) | The level of the wait event. |
| WAIT_CLASS_ID | bigint(20) | number(38) | The ID of the class to which the wait event belongs. |
| WAIT_CLASS# | bigint(20) | number(38) | The subscript of the class to which the wait event belongs. |
| WAIT_CLASS | varchar(64) | varchar(64) | The name of the class to which the wait event belongs. |
| STATE | varchar(19) | varchar(19) | The state of the wait event. |
| WAIT_TIME_MICRO | bigint(20) | number(38) | The wait time of the wait event, in ms. |
| TOTAL_WAIT_TIME_MICRO | bigint(20) | number(38) | The total wait time in the execution process, in ms. |
| TOTAL_WAITS | bigint(20) | number(38) | The total number of waits during the execution. |
| RPC_COUNT | bigint(20) | number(38) | The number of remote procedure calls (RPCs) sent. |
| PLAN_TYPE | bigint(20) | number(38) | The type of the execution plan. Valid values:
|
| IS_INNER_SQL | tinyint(4) | number(38) | Indicates whether the request is an internal SQL request. |
| IS_EXECUTOR_RPC | tinyint(4) | number(38) | Indicates whether the current request is an RPC request. |
| IS_HIT_PLAN | tinyint(4) | number(38) | Indicates whether the plan cache is hit. |
| REQUEST_TIME | bigint(20) | number(38) | The time when the execution starts. |
| ELAPSED_TIME | bigint(20) | number(38) | The amount of time elapsed from when the request was received to when the execution of the request ended. |
| NET_TIME | bigint(20) | number(38) | The time consumed from RPC sending to request reception. |
| NET_WAIT_TIME | bigint(20) | number(38) | The time consumed from the reception of a request to the start of queuing. |
| QUEUE_TIME | bigint(20) | number(38) | The wait time of the request in the queue. |
| DECODE_TIME | bigint(20) | number(38) | The decoding time of the request after it left the queue. |
| GET_PLAN_TIME | bigint(20) | number(38) | The time consumed from execution start to plan acquisition |
| EXECUTE_TIME | bigint(20) | number(38) | The time consumed for plan execution. |
| APPLICATION_WAIT_TIME | bigint(20) unsigned | number(38) | The total amount of time spent on waiting for events of the application class. |
| CONCURRENCY_WAIT_TIME | bigint(20) unsigned | number(38) | The total amount of time spent on waiting for events of the concurrency class. |
| USER_IO_WAIT_TIME | bigint(20) unsigned | number(38) | The total amount of time spent on waiting for the events of the user_io class. |
| SCHEDULE_TIME | bigint(20) unsigned | number(38) | The total amount of time spent on events of the schedule class. |
| ROW_CACHE_HIT | bigint(20) | number(38) | The number of row cache hits. |
| BLOOM_FILTER_CACHE_HIT | bigint(20) | number(38) | The number of Bloom filter cache hits. |
| BLOCK_CACHE_HIT | bigint(20) | number(38) | The number of block cache hits. |
| DISK_READS | bigint(20) | number(38) | The number of physical reads. |
| RETRY_CNT | bigint(20) | number(38) | The number of retries. |
| TABLE_SCAN | tinyint(4) | number(38) | Indicates whether the request contains a full table scan. |
| CONSISTENCY_LEVEL | bigint(20) | number(38) | The consistency level. |
| MEMSTORE_READ_ROW_COUNT | bigint(20) | number(38) | The number of rows read in the MemStore. |
| SSSTORE_READ_ROW_COUNT | bigint(20) | number(38) | The number of rows read from SSSTORE. |
| DATA_BLOCK_READ_CNT | bigint(20) | NO | The number of data microblocks accessed. |
| DATA_BLOCK_CACHE_HIT | bigint(20) | NO | The number of data microblock cache hits. |
| INDEX_BLOCK_READ_CNT | bigint(20) | NO | The number of intermediate-layer microblocks accessed. |
| INDEX_BLOCK_CACHE_HIT | bigint(20) | NO | The number of intermediate-layer microblock cache hits. |
| BLOCKSCAN_BLOCK_CNT | bigint(20) | NO | The number of data microblocks scanned during a unilateral scan. |
| BLOCKSCAN_ROW_CNT | bigint(20) | NO | The number of data rows scanned during a unilateral scan. |
| PUSHDOWN_STORAGE_FILTER_ROW_CNT | bigint(20) | NO | The number of rows that remain after the filter condition is pushed down to and applied in the storage layer. |
| REQUEST_MEMORY_USED | bigint(20) | number(38) | The memory consumed by the request. |
| EXPECTED_WORKER_COUNT | bigint(20) | number(38) | The number of worker threads expected by the request. |
| USED_WORKER_COUNT | bigint(20) | number(38) | The number of worker threads used by the request. |
| SCHED_INFO | varchar(16384) | varchar(16384) | The scheduling information of the request. |
| FUSE_ROW_CACHE_HIT | bigint(20) | number(38) | At present, this field is not supported and is NULL by default. |
| PS_CLIENT_STMT_ID | bigint(20) | NO | The ID of the PREPARE statement corresponding to the request.
|
| PS_INNER_STMT_ID | bigint(20) | NO | The ID of the PREPARE statement corresponding to the request.
|
| TX_ID | bigint(20) | NO | The hash value of the transaction corresponding to the request. |
| SNAPSHOT_VERSION | bigint(20)unsigned | NO | The snapshot version of the current statement. |
| REQUEST_TYPE | bigint(20) | number(38) | The type of the request. Valid values:
|
| IS_BATCHED_MULTI_STMT | tinyint(4) | number(38) | Indicates whether optimization has been performed for batch execution of multiple statements. |
| OB_TRACE_INFO | VARCHAR2(4096) | VARCHAR2(4096) | The trace information configured by the user. |
| PLAN_HASH | bigint(20) unsigned | number(38) | The hash value of the execution plan. |
| LOCK_FOR_READ_TIME | bigint(20) | number(38) | The time in microseconds spent on waiting for locked data to be unlocked before it can be read. |
| PARAMS_VALUE | longtext | CLOB | The parameter value. |