Oracle sql shared pool $sqlarea analysis of SQL resource usage

Posted by GBahle on Mon, 09 Dec 2019 21:53:47 +0100

If you need to check the sql usage of a system, you can query the $sql, $sssession, $sqlarea of Oracle for statistical troubleshooting

Check the basic information of $sql and $session before troubleshooting

 select *
   from v$sql a, v$session b
  where b.SQL_ADDRESS = a.ADDRESS
    and b.SQL_HASH_VALUE = a.HASH_VALUE
    and b.SQL_CHILD_NUMBER = a.CHILD_NUMBER

$sqlarea table means:
Quote: https://blog.csdn.net/study4034/article/details/51331120

SQL_TEXT //The first 1000 characters of the sql text of the cursor currently executing
SQL_FULLTEXT //CLOB type entire sql text, without the help of V $sql? Text view to view the entire text
SQL_ID //Flags for SQL parent cursors in the library cache
SHARABLE_MEM //Size of shared memory used by child cursors, bytes
PERSISTENT_MEM //Total fixed memory used in child cursor lifetime, bytes
RUNTIME_MEM //Fixed memory size required during sub cursor execution, bytes
SORTS //The number of sorts that occurred in the child cursor
LOADED_VERSIONS // Show whether context heap is loaded, 1 yes, 0 no
USERS_OPENING // Number of users executing this sql
FETCHES // Number of sql fetches
EXECUTIONS //Number of sql executions since being loaded into the shared pool
FIRST_LOAD_TIME // Timestamp generated by parent cursor
PARSE_CALLS //Number of parsing calls
DISK_CALLS //Number of disk reads
DIRECT_WRITES //Number of direct writes
BUFFER_GETS //The number of times to get data directly from the buffer
APPLICATION_WAIT_TIME // Application wait time, MS
CONCURRENCY_WAIT_TIME //Concurrent wait time, MS
USER_IO_WAIT_TIME //User IO wait time
ROWS_PROCESSED SQL //Total number of rows returned by parsing sql
OPTIMIZER_MODE //optimizer mode
OPTIMIZER_COST //The cost given by optimizer for sql
PARSING_USER_ID //The first user id to create this child cursor
HASH_VALUES //Hash value generated by parsing
CHILD_NUMBER //Number of the child cursors
SERVICE //service name
CPU_TIME //CPU time used by the sub cursor to parse, execute and get data, MS
ELAPSED_TIME //Execution time of sql, MS
INVALIDATIONS //Invalid number of times for this child cursor
MODULE //Module name set by DBMS application info.set action when parsing the statement for the first time
ACTION //The first time the statement is parsed, the action name set by DBMS? Application? Info.set? Action
IS_OBSOLETE //Mark whether the child cursor expires. This happens when the child cursor is too large
is_bind_sensitive //It not only indicates whether to use binding variable snooping to generate execution plan, but also indicates whether the execution plan depends on the snooped value. If so, this field will be set to Y, otherwise it will be set to N.
is_bind_aware //Indicates whether the cursor uses the extended cursor share. If yes, this field will be set to Y, if not, this field will be set to n. If it is set to N, the cursor will be discarded and will no longer be available.
is_shareable //Indicates whether the cursor can be shared. If you can, this field will be set to Y, otherwise, it will be set to n. If set to N, the cursor is discarded and is no longer available.

Go to the SQL shared pool $sqlarea of Oracle to query the execution times of SQL and analyze the execution performance of SQL

EXECUTIONS: the number of times all child cursors execute SQL
Disk? Reads: the number of hard disks that all child cursors need to read to execute SQL
Buffer? Gets: the number of times that all child cursors need to read to execute SQL
Elapsed time: the time required for all child cursors to execute SQL

Analyze SQL execution performance

SELECT SQL_TEXT,
       SQL_FULLTEXT,
       ELAPSED_TIME,
       DISK_READS,
       BUFFER_GETS,
       EXECUTIONS,
       Round(ELAPSED_TIME / EXECUTIONS ,2),
       ROUND(DISK_READS / EXECUTIONS, 2),
       ROUND(BUFFER_GETS / EXECUTIONS , 2),
       ROUND((BUFFER_GETS - DISK_READS) / BUFFER_GETS, 2) 
  FROM V$SQLAREA 
 WHERE EXECUTIONS > 0
   AND BUFFER_GETS > 0
   AND (BUFFER_GETS - DISK_READS) / BUFFER_GETS < 0.8
   ORDER BY Round(ELAPSED_TIME / EXECUTIONS ,2) desc;

Then explain these meanings:
Round (elapsed_time / executions, 2): find the time required for each cursor to execute SQL

Round (disk \ reads / executions, 2): count the number of times each cursor needs to read the disk to execute SQL

Round (buffer_gets / executions, 2): count the number of times each cursor needs to read memory to execute SQL

Round ((buffer gets - disk reads) / buffer gets, 2): SQL hit rate

All in all, go to the $sqlarea shared pool to query statistics, and then analyze SQL. The lower the above data, the higher the execution speed and the better the performance of SQL

Topics: SQL Oracle Session