domingo, 16 de junio de 2013

Oracle las sentencias que se ejecutan desde una sesión desconectada o conectada.

Oracle las sentencias que se ejecutan desde una sesión desconectada 

Si consultas el tema Recopilación de scripts y consultas útiles de Oracle encontrarás la query que te copio para extraer información sobre las sentencias SQL y el usuario que las ha ejecutado. Ten en cuenta que la consulta te saca las sentencias que se encuentran en la Shared SQL Area, dentro de la Shared Pool, es decir, las que se están ejecutando o se han ejecutado y Oracle almacena para optimizar ejecuciones posteriores. Las que menos se utilizan irán desapareciendo de este àrea.
•• Últimas consultas SQL ejecutadas en Oracle y usuario que las ejecutó:
select distinct vs.sql_text, vs.sharable_mem,
vs.persistent_mem, vs.runtime_mem, vs.sorts,
vs.executions, vs.parse_calls, vs.module,
vs.buffer_gets, vs.disk_reads, vs.version_count,
vs.users_opening, vs.loads,
to_char(to_date(vs.first_load_time,
'YYYY-MM-DD/HH24:MI:SS'),'MM/DD HH24:MI:SS') first_load_time,
rawtohex(vs.address) address, vs.hash_value hash_value ,
rows_processed , vs.command_type, vs.parsing_user_id ,
OPTIMIZER_MODE , au.USERNAME parseuser
from v$sqlarea vs , all_users au
where (parsing_user_id != 0) AND
(au.user_id(+)=vs.parsing_user_id)
and (executions >= 1) order by buffer_gets/executions desc
A partir de aquí puedes sacar tanta la información que necesites tanto de v$sqlarea como de all_users. En la documentación online de Oracle tienes todos los campos de estadísticas disponibles para v$sqlarea. Igualmente los copio:
ColumnDatatypeDescription
SQL_TEXTVARCHAR2(1000)First thousand characters of the SQL text for the current cursor
SQL_FULLTEXTCLOBAll characters of the SQL text for the current cursor
SQL_IDVARCHAR2(13)SQL identifier of the parent cursor in the library cache
SHARABLE_MEMNUMBERAmount of shared memory used by a cursor. If multiple child cursors exist, then the sum of all shared memory used by all child cursors.
PERSISTENT_MEMNUMBERFixed amount of memory used for the lifetime of an open cursor. If multiple child cursors exist, the fixed sum of memory used for the lifetime of all the child cursors.
RUNTIME_MEMNUMBERFixed amount of memory required during execution of a cursor. If multiple child cursors exist, the fixed sum of all memory required during execution of all the child cursors.
SORTSNUMBERSum of the number of sorts that were done for all the child cursors
VERSION_COUNTNUMBERNumber of child cursors that are present in the cache under this parent
LOADED_VERSIONSNUMBERNumber of child cursors that are present in the cache and have their context heap (KGL heap 6) loaded
OPEN_VERSIONSNUMBERThe number of child cursors that are currently open under this current parent
USERS_OPENINGNUMBERNumber of users that have any of the child cursors open
FETCHESNUMBERNumber of fetches associated with the SQL statement
EXECUTIONSNUMBERTotal number of executions, totalled over all the child cursors
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 theEND_OF_FETCH_COUNT column should be less or equal to the value of the EXECUTIONS column.
USERS_EXECUTINGNUMBERTotal number of users executing the statement over all child cursors
LOADSNUMBERNumber of times the object was loaded or reloaded
FIRST_LOAD_TIMEVARCHAR2(19)Timestamp of the parent creation time
INVALIDATIONSNUMBERTotal number of invalidations over all the child cursors
PARSE_CALLSNUMBERSum of all parse calls to all the child cursors under this parent
DISK_READSNUMBERSum of the number of disk reads over all child cursors
DIRECT_WRITESNUMBERSum of the number of direct writes over all child cursors
BUFFER_GETSNUMBERSum of buffer gets over all child cursors
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 processed on behalf of this SQL statement
COMMAND_TYPENUMBEROracle command type definition
OPTIMIZER_MODEVARCHAR2(10)Mode under which the SQL statement was executed
OPTIMIZER_COSTNUMBERCost of this query given by the optimizer
OPTIMIZER_ENVRAW(703)Optimizer environment
OPTIMIZER_ENV_HASH_VALUENUMBERHash value for the optimizer environment
PARSING_USER_IDNUMBERUser ID of the user that has parsed the very first cursor under this parent
PARSING_SCHEMA_IDNUMBERSchema ID that was used to parse this child cursor
PARSING_SCHEMA_NAMEVARCHAR2(30)Schema name that was used to parse this child cursor
KEPT_VERSIONSNUMBERNumber of child cursors that have been marked to be kept using the DBMS_SHARED_POOL package
ADDRESSRAW(4 | 8)Address of the handle to the parent for this 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)
MODULEVARCHAR2(64)Contains the name of the module that was executing at the time that the SQL statement was first parsed as set by callingDBMS_APPLICATION_INFO.SET_MODULE
MODULE_HASHNUMBERHash value of the module that is named 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 as set by callingDBMS_APPLICATION_INFO.SET_ACTION
ACTION_HASHNUMBERHash value of the action that is named in the ACTION column
SERIALIZABLE_ABORTSNUMBERNumber of times the transaction fails to serialize, producing ORA-08177 errors, totalled over all the child cursors
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_SIDVARCHAR2(40)Outline session identifier
LAST_ACTIVE_CHILD_ADDRESSRAW(4)Address (identifier) of the child cursor that was the last to be active in the group (that is, the child cursor on behalf of which statistics in V$SQL were updated)
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, whenCURSOR_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_TIMEDATETime 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_SIGNATURENUMBERThe signature used when the CURSOR_SHARING parameter is set to EXACT
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

http://www.oracle.com/technetwork/es/articles/sql/o29spm-098177-esa.html

Más sobre las estadísticas...

http://cajondesastreoracle.wordpress.com/category/oracle/estadisticas/

No hay comentarios: