DB2 Version 10.1 for Linux, UNIX, and Windows

SNAPSTMT administrative view and SNAP_GET_STMT table function - Retrieve statement snapshot information

The SNAPSTMT administrative view and the SNAP_GET_STMT table function return information about SQL or XQuery statements from an application snapshot.

Depending on if you are using the administrative view or the table function, refer to one of the following sections:

SNAPSTMT administrative view

This administrative view allows you to retrieve statement snapshot information for the currently connected database.

Used with the SNAPAGENT, SNAPAGENT_MEMORY_POOL, SNAPAPPL, SNAPAPPL_INFO and SNAPSUBSECTION administrative views, the SNAPSTMT administrative view provides information equivalent to the GET SNAPSHOT FOR APPLICATIONS on database-alias CLP command, but retrieves data from all database members.

The schema is SYSIBMADM.

Refer to Table 1 for a complete list of information that can be returned.

Authorization

One of the following authorizations is required to use the view:
  • SELECT privilege on the SNAPSTMT administrative view
  • CONTROL privilege on the SNAPSTMT administrative view
  • DATAACCESS authority
  • DBADM authority
  • SQLADM authority
One of the following is required to use the table function:
  • EXECUTE privilege on the SNAP_GET_STMT table function
  • DATAACCESS authority
  • DBADM authority
  • SQLADM authority
In addition, to access snapshot monitor data, one of the following authorities is also required:
  • SYSMON
  • SYSCTRL
  • SYSMAINT
  • SYSADM

Default PUBLIC privilege

In a non-restrictive database, SELECT privilege is granted to PUBLIC when the view is automatically created.

Example

Retrieve rows read, written and operation performed for statements executed on the currently connected single-member database.
SELECT SUBSTR(STMT_TEXT,1,30) AS STMT_TEXT, ROWS_READ, ROWS_WRITTEN, 
   STMT_OPERATION FROM SYSIBMADM.SNAPSTMT
The following is an example of output from this query.
STMT_TEXT     ROWS_READ     ROWS_WRITTEN     STMT_OPERATION
---------...- ---------...- ------------...- --------------------
-                         0                0 FETCH
-                         0                0 STATIC_COMMIT

  2 record(s) selected.

SNAP_GET_STMT table function

The SNAP_GET_STMT table function returns the same information as the SNAPSTMT administrative view, but allows you to retrieve the information for a specific database on a specific database member, aggregate of all database members or all database members.

Used with the SNAP_GET_AGENT, SNAP_GET_AGENT_MEMORY_POOL, SNAP_GET_APPL, SNAP_GET_APPL_INFO and SNAP_GET_SUBSECTION table functions, the SNAP_GET_STMT table function provides information equivalent to the GET SNAPSHOT FOR ALL APPLICATIONS CLP command, but retrieves data from all database partitions.

Refer to Table 1 for a complete list of information that can be returned.

Syntax

Read syntax diagramSkip visual syntax diagram
>>-SNAP_GET_STMT--(--dbname--+----------+--)-------------------><
                             '-, member-'      

The schema is SYSPROC.

Table function parameters

dbname
An input argument of type VARCHAR(128) that specifies a valid database name in the same instance as the currently connected database. Specify a database name that has a directory entry type of either "Indirect" or "Home", as returned by the LIST DATABASE DIRECTORY command. Specify an empty string to take the snapshot from the currently connected database. Specify a NULL value to take the snapshot from all databases within the same instance as the currently connected database.
member
An optional input argument of type INTEGER that specifies a valid database member number. Specify -1 for the current database member, or -2 for an aggregate of all active database members. If dbname is not set to NULL and member is set to NULL, -1 is set implicitly for member. If this input option is not used, that is, only dbname is provided, data is returned from all active database members. An active database member is a member where the database is available for connection and use by applications.

If both dbname and member are set to NULL, an attempt is made to read data from the file created by SNAP_WRITE_FILE procedure. Note that this file could have been created at any time, which means that the data might not be current. If a file with the corresponding snapshot API request type does not exist, then the SNAP_GET_STMT table function takes a snapshot for the currently connected database and database member number.

Authorization

One of the following authorizations is required:
  • EXECUTE privilege on the SNAP_GET_STMT table function
  • DATAACCESS authority
In addition, to access snapshot monitor data, one of the following authorities is also required:
  • SYSMON
  • SYSCTRL
  • SYSMAINT
  • SYSADM

Default PUBLIC privilege

In a non-restrictive database, EXECUTE privilege is granted to PUBLIC when the function is automatically created.

Example

Retrieve rows read, written and operation performed for statements executed on current database member of currently connected database.
SELECT SUBSTR(STMT_TEXT,1,30) AS STMT_TEXT, ROWS_READ, 
   ROWS_WRITTEN, STMT_OPERATION FROM TABLE(SNAP_GET_STMT('',-1)) AS T
The following is an example of output from this query.
STMT_TEXT                      ROWS_READ     ...
------------------------------ ---------...- ...
update t set a=3                           0 ...
SELECT SUBSTR(STMT_TEXT,1,30)              0 ...
-                                          0 ...
-                                          0 ...
update t set a=2                           9 ...
                                             ...
5 record(s) selected.                        ...
Output from this query (continued).
... ROWS_WRITTEN     STMT_OPERATION      
... ------------...- --------------------
...                0 EXECUTE_IMMEDIATE   
...                0 FETCH               
...                0 NONE                
...                0 NONE                
...                1 EXECUTE_IMMEDIATE   
...                                      

Information returned

Table 1. Information returned by the SNAPSTMT administrative view and the SNAP_GET_STMT table function
Column name Data type Description or corresponding monitor element
SNAPSHOT_TIMESTAMP TIMESTAMP The date and time that the snapshot was taken.
DB_NAME VARCHAR(128) db_name - Database name
AGENT_ID BIGINT agent_id - Application handle (agent ID)
ROWS_READ BIGINT rows_read - Rows read
ROWS_WRITTEN BIGINT rows_written - Rows written
NUM_AGENTS BIGINT num_agents - Number of agents working on a statement
AGENTS_TOP BIGINT agents_top - Number of agents created
STMT_TYPE VARCHAR(20) stmt_type - Statement type . This interface returns a text identifier based on defines in sqlmon.h and is one of:
  • DYNAMIC
  • NON_STMT
  • STATIC
  • STMT_TYPE_UNKNOWN
STMT_OPERATION VARCHAR(20) stmt_operation/operation - Statement operation . This interface returns a text identifier based on defines in sqlmon.h and is one of:
  • CALL
  • CLOSE
  • COMPILE
  • DESCRIBE
  • EXECUTE
  • EXECUTE_IMMEDIATE
  • FETCH
  • FREE_LOCATOR
  • GETAA
  • GETNEXTCHUNK
  • GETTA
  • NONE
  • OPEN
  • PREP_COMMIT
  • PREP_EXEC
  • PREP_OPEN
  • PREPARE
  • REBIND
  • REDIST
  • REORG
  • RUNSTATS
  • SELECT
  • SET
  • STATIC_COMMIT
  • STATIC_ROLLBACK
SECTION_NUMBER BIGINT section_number - Section number
QUERY_COST_ESTIMATE BIGINT query_cost_estimate - Query cost estimate
QUERY_CARD_ESTIMATE BIGINT query_card_estimate - Query number of rows estimate
DEGREE_PARALLELISM BIGINT degree_parallelism - Degree of parallelism
STMT_SORTS BIGINT stmt_sorts - Statement sorts
TOTAL_SORT_TIME BIGINT total_sort_time - Total sort time
SORT_OVERFLOWS BIGINT sort_overflows - Sort overflows
INT_ROWS_DELETED BIGINT int_rows_deleted - Internal rows deleted
INT_ROWS_UPDATED BIGINT int_rows_updated - Internal rows updated
INT_ROWS_INSERTED BIGINT int_rows_inserted - Internal rows inserted
FETCH_COUNT BIGINT fetch_count - Number of successful fetches
STMT_START TIMESTAMP stmt_start - Statement operation start timestamp
STMT_STOP TIMESTAMP stmt_stop - Statement operation stop timestamp
STMT_USR_CPU_TIME_S BIGINT stmt_usr_cpu_time - User CPU time used by statement (in seconds)*
STMT_USR_CPU_TIME_MS BIGINT stmt_usr_cpu_time - User CPU time used by statement (fractional, in microseconds)*
STMT_SYS_CPU_TIME_S BIGINT stmt_sys_cpu_time - System CPU time used by statement (in seconds)*
STMT_SYS_CPU_TIME_MS BIGINT stmt_sys_cpu_time - System CPU time used by statement (fractional, in microseconds)*
STMT_ELAPSED_TIME_S BIGINT stmt_elapsed_time - Most recent statement elapsed time (in seconds)*
STMT_ELAPSED_TIME_MS BIGINT stmt_elapsed_time - Most recent statement elapsed time (fractional, in microseconds)*
BLOCKING_CURSOR SMALLINT blocking_cursor - Blocking cursor
STMT_NODE_NUMBER SMALLINT stmt_node_number - Statement node
CURSOR_NAME VARCHAR(128) cursor_name - Cursor name
CREATOR VARCHAR(128) creator - Application creator
PACKAGE_NAME VARCHAR(128) package_name - Package name
STMT_TEXT CLOB(16 M) stmt_text - SQL statement text
CONSISTENCY_TOKEN VARCHAR(128) consistency_token - Package consistency token
PACKAGE_VERSION_ID VARCHAR(128) package_version_id - Package version
POOL_DATA_L_READS BIGINT pool_data_l_reads - Buffer pool data logical reads
POOL_DATA_P_READS BIGINT pool_data_p_reads - Buffer pool data physical reads
POOL_INDEX_L_READS BIGINT pool_index_l_reads - Buffer pool index logical reads
POOL_INDEX_P_READS BIGINT pool_index_p_reads - Buffer pool index physical reads
POOL_XDA_L_READS BIGINT pool_xda_l_reads - Buffer Pool XDA Data Logical Reads monitor element
POOL_XDA_P_READS BIGINT pool_xda_p_reads - Buffer Pool XDA Data Physical Reads monitor element
POOL_TEMP_DATA_L_READS BIGINT pool_temp_data_l_reads - Buffer pool temporary data logical reads
POOL_TEMP_DATA_P_READS BIGINT pool_temp_data_p_reads - Buffer pool temporary data physical reads
POOL_TEMP_INDEX_L_READS BIGINT pool_temp_index_l_reads - Buffer pool temporary index logical reads
POOL_TEMP_INDEX_P_READS BIGINT pool_temp_index_p_reads - Buffer pool temporary index physical reads
POOL_TEMP_XDA_L_READS BIGINT pool_temp_xda_l_reads - Buffer Pool Temporary XDA Data Logical Reads
POOL_TEMP_XDA_P_READS BIGINT pool_temp_xda_p_reads - Buffer Pool Temporary XDA Data Physical Reads monitor element
DBPARTITIONNUM SMALLINT dbpartitionnum - Database partition number monitor element
MEMBER SMALLINT member - Database member monitor element
* To calculate the total time spent for the monitor element that this column is based on, you must add the full seconds reported in the column for this monitor element that ends with _S to the fractional seconds reported in the column for this monitor element that ends with _MS, using the following formula: (monitor-element-name_S × 1,000,000 + monitor-element-name_MS) ÷ 1,000,000. For example, (ELAPSED_EXEC_TIME_S × 1,000,000 + ELAPSED_EXEC_TIME_MS) ÷ 1,000,000.