V$SQL and GV$SQL Views in Oracle

I will explain V$SQL and GV$SQL Views in Oracle in this post.

 

V$SQL and GV$SQL in Oracle

V$SQL and GV$SQL views are most important views in the Oracle Database. Because you can review the statistics of SQL statements with these views.

V$SQL shows the local instance’s SQL Statistics and GV$SQL shows the all instances’ SQL Statistics.

 

 

 

 

 

V$SQL in Oracle

V$SQL view has the following column and statistics data.

ColumnDatatypeDescription
SQL_TEXTVARCHAR2(1000)First thousand characters of the SQL text for the current cursor
SQL_FULLTEXTCLOBFull text for the SQL statement exposed as a CLOB column. The full text of a SQL statement can be retrieved using this column instead of joining with the V$SQL_TEXT dynamic performance view.
SQL_IDVARCHAR2(13)SQL identifier of the parent cursor in the library cache
SHARABLE_MEMNUMBERAmount of shared memory used by the child cursor (in bytes)
PERSISTENT_MEMNUMBERFixed amount of memory used for the lifetime of the child cursor (in bytes)
RUNTIME_MEMNUMBERFixed amount of memory required during the execution of the child cursor
SORTSNUMBERNumber of sorts that were done for the child cursor
LOADED_VERSIONSNUMBERIndicates whether the context heap is loaded (1) or not (0)
OPEN_VERSIONSNUMBERIndicates whether the child cursor is locked (1) or not (0)
USERS_OPENINGNUMBERNumber of users executing the statement
FETCHESNUMBERNumber of fetches associated with the SQL statement
EXECUTIONSNUMBERNumber of executions that took place on this object since it was brought into the library cache
PX_SERVERS_EXECUTIONSNUMBERTotal number of executions performed by Parallel eXecution Servers. The value is 0 when the statement has never been executed in parallel.
END_OF_FETCH_COUNTNUMBERNumber of times this cursor was fully executed since the cursor was brought into the library cache. The value of this statistic is not incremented when the cursor is partially executed, either because it failed during the execution or because only the first few rows produced by this cursor are fetched before the cursor is closed or re-executed. By definition, the value of the END_OF_FETCH_COUNT column should be less or equal to the value of the EXECUTIONS column.
USERS_EXECUTINGNUMBERNumber of users executing the statement
LOADSNUMBERNumber of times the object was either loaded or reloaded
FIRST_LOAD_TIMEVARCHAR2(19)Timestamp of the parent creation time
INVALIDATIONSNUMBERNumber of times this child cursor has been invalidated
PARSE_CALLSNUMBERNumber of parse calls for this child cursor
DISK_READSNUMBERNumber of disk reads for this child cursor
DIRECT_WRITESNUMBERNumber of direct writes for this child cursor
BUFFER_GETSNUMBERNumber of buffer gets for this child cursor
APPLICATION_WAIT_TIMENUMBERApplication wait time (in microseconds)
CONCURRENCY_WAIT_TIMENUMBERConcurrency wait time (in microseconds)
CLUSTER_WAIT_TIMENUMBERCluster wait time (in microseconds)
USER_IO_WAIT_TIMENUMBERUser I/O Wait Time (in microseconds)
PLSQL_EXEC_TIMENUMBERPL/SQL execution time (in microseconds)
JAVA_EXEC_TIMENUMBERJava execution time (in microseconds)
ROWS_PROCESSEDNUMBERTotal number of rows the parsed SQL statement returns
COMMAND_TYPENUMBEROracle command type definition
OPTIMIZER_MODEVARCHAR2(10)Mode under which the SQL statement is executed
OPTIMIZER_COSTNUMBERCost of this query given by the optimizer
OPTIMIZER_ENVRAW(691)Optimizer environment
OPTIMIZER_ENV_HASH_VALUENUMBERHash value for the optimizer environment
PARSING_USER_IDNUMBERUser ID of the user who originally built this child cursor
PARSING_SCHEMA_IDNUMBERSchema ID that was used to originally build this child cursor
PARSING_SCHEMA_NAMEVARCHAR2(30)Schema name that was used to originally build this child cursor
KEPT_VERSIONSNUMBERIndicates whether this child cursor has been marked to be kept pinned in the cache using the DBMS_SHARED_POOL package
ADDRESSRAW(4 | 8)Address of the handle to the parent for this cursor
TYPE_CHK_HEAPRAW(4)Descriptor of the type check heap for this child cursor
HASH_VALUENUMBERHash value of the parent statement in the library cache
OLD_HASH_VALUENUMBEROld SQL hash value
PLAN_HASH_VALUENUMBERNumerical representation of the SQL plan for this cursor. Comparing one PLAN_HASH_VALUE to another easily identifies whether or not two plans are the same (rather than comparing the two plans line by line).
CHILD_NUMBERNUMBERNumber of this child cursor
SERVICEVARCHAR2(64)Service name
SERVICE_HASHNUMBERHash value for the name listed in SERVICE
MODULEVARCHAR2(64)Contains the name of the module that was executing at the time that the SQL statement was first parsed, which is set by calling DBMS_APPLICATION_INFO.SET_MODULE
MODULE_HASHNUMBERHash value of the module listed in the MODULE column
ACTIONVARCHAR2(64)Contains the name of the action that was executing at the time that the SQL statement was first parsed, which is set by calling DBMS_APPLICATION_INFO.SET_ACTION
ACTION_HASHNUMBERHash value of the action listed in the ACTION column
SERIALIZABLE_ABORTSNUMBERNumber of times the transaction fails to serialize, producing ORA-08177 errors, per cursor
OUTLINE_CATEGORYVARCHAR2(64)If an outline was applied during construction of the cursor, then this column displays the category of that outline. Otherwise the column is left blank.
CPU_TIMENUMBERCPU time (in microseconds) used by this cursor for parsing, executing, and fetching
ELAPSED_TIMENUMBERElapsed time (in microseconds) used by this cursor for parsing, executing, and fetching
OUTLINE_SIDNUMBEROutline session identifier
CHILD_ADDRESSRAW(4 | 8)Address of the child cursor
SQLTYPENUMBERDenotes the version of the SQL language used for this statement
REMOTEVARCHAR2(1)Indicates whether the cursor is remote mapped (Y) or not (N)
OBJECT_STATUSVARCHAR2(19)Status of the cursor:

  • VALID – Valid, authorized without errors
  • VALID_AUTH_ERROR – Valid, authorized with authorization errors
  • VALID_COMPILE_ERROR – Valid, authorized with compilation errors
  • VALID_UNAUTH – Valid, unauthorized
  • INVALID_UNAUTH – Invalid, unauthorized
  • INVALID – Invalid, unauthorized but keep the timestamp
LITERAL_HASH_VALUENUMBERHash value of the literals which are replaced with system-generated bind variables and are to be matched, when CURSOR_SHARING is used. This is not the hash value for the SQL statement. If CURSOR_SHARING is not used, then the value is 0.
LAST_LOAD_TIMEVARCHAR2(19)Time at which the query plan (heap 6) was loaded into the library cache
IS_OBSOLETEVARCHAR2(1)Indicates whether the cursor has become obsolete (Y) or not (N). This can happen if the number of child cursors is too large.
CHILD_LATCHNUMBERChild latch number that is protecting the cursor
SQL_PROFILEVARCHAR2(64)SQL profile
PROGRAM_IDNUMBERProgram identifier
PROGRAM_LINE#NUMBERProgram line number
EXACT_MATCHING_SIGNATURENUMBERSignature calculated on the normalized SQL text. The normalization includes the removal of white space and the uppercasing of all non-literal strings.
FORCE_MATCHING_SIGNATURENUMBERThe signature used when the CURSOR_SHARING parameter is set to FORCE
LAST_ACTIVE_TIMEDATETIme at which the query plan was last active
BIND_DATARAW(2000)Bind data

 

You can list the any sql id’s statement statistics as follows.

select * from v$sql where sql_id='gqr94hyvp0004';

 

You can list the SQL Statistics using v$SQL as follows.

 

SELECT /*+parallel(32) */ SQL_ID , SQL_TEXT, force_matching_signature FROM V$SQL WHERE force_matching_signature IN (SELECT force_matching_signature
FROM v$sql
WHERE force_matching_signature <> 0
AND force_matching_signature <> exact_matching_signature
GROUP BY force_matching_signature
HAVING COUNT(*) > 1)
ORDER BY 3;

 

 

 

GV$SQL in Oracle

If you use the Oracle RAC and you have lots of Oracle instance, then you need to use gv$sql views.

All statistics of SQL Statement can be found as follows.

select * from gv$sql;
select * from gv$sql where sql_id='gqr94hyvp0004';


SQL Statement's some statistics 

select inst_id,SQL_PLAN_BASELINE ,sql_fulltext,sql_profile ,trunc(elapsed_time/decode(executions, 0, 1, executions)/1000000) elapsed_time, plan_hash_value,hash_value, child_number, first_load_time,
last_load_time, executions, buffer_gets, trunc(buffer_gets/decode(executions, 0, 1, executions)) gets_per_exec, trunc(rows_processed/decode(executions, 0, 1,
executions)) rows_return_per_exec
from gv$sql where sql_id='2hmam9gkmbmm8' order by last_load_time desc;



SQL Statement's history using gv$sql and dba_hist_active_sess_history

select /*+ parallel(32)*/ runday,sql_id,plnhash,sqlexec,fms,module,mntime,mxtime,mxtime-mntime,cnt,
(select sql_profile from gv$sql where sql_id=x.sql_id and rownum=1) sqlprof,
(select sql_plan_baseline from gv$sql where sql_id=x.sql_id and rownum=1) sqlbaseline,
(select substr(sql_text,1,30) from gv$sql where sql_id=x.sql_id and rownum=1) sqltext,
(select sql_fulltext from gv$sql where sql_id=x.sql_id and rownum=1) sqlFULLtext
from (select trunc(sample_time) runday,sql_id,sql_plan_hash_value plnhash,sql_exec_id sqlexec,FORCE_MATCHING_SIGNATURE fms,module,min(sample_time) mntime,max(sample_time) mxtime,count(1) cnt 
from dba_hist_active_sess_history where sql_id='81c1akh8zubg7'
group by trunc(sample_time),sql_id,sql_plan_hash_value,sql_exec_id,FORCE_MATCHING_SIGNATURE,module
order by 1 desc,count(1) desc) x;

 

 

 

Do you want to learn Oracle Database Performance Tuning detailed, then Click this link.

Performance Tuning and SQL Tuning Tutorial in the Oracle Database

About Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress [email protected].-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  [email protected] a mail atabilirsiniz.

Leave a Reply

Your email address will not be published. Required fields are marked *