Capturing database system snapshot information to a file using the SNAP_WRITE_FILE stored procedure

With the SNAP_WRITE_FILE stored procedure you can capture snapshots of monitor data and save this information to files on the database server and allow access to the data by users who do not have SYSADM, SYSCTRL, SYSMAINT, or SYSMON authority.

Any user can then issue a query with a snapshot table function to access the snapshot information in these files. In providing open access to snapshot monitor data, sensitive information (such as the list of connected users and the SQL statements they have submitted to the database) is available to all users who have the execution privilege for the snapshot table functions. The privilege to execute the snapshot table functions is granted to PUBLIC by default. (Note, however, that no actual data from tables or user passwords can be exposed using the snapshot monitor table functions.)
Important: The SYSPROC.SNAP_WRITE_FILE procedure is deprecated and might be removed in a future release. For more information, see SNAP_WRITE_FILE procedure.

Before you begin

You must have SYSADM, SYSCTRL, SYSMAINT, or SYSMON authority to capture a database snapshot with the SNAP_WRITE_FILE stored procedure.

About this task

When issuing a call to the SNAP_WRITE_FILE stored procedure, in addition to identifying the database and partition to be monitored, you need to specify a snapshot request type. Each snapshot request type determines the scope of monitor data that is collected. Choose the snapshot request types based on the snapshot table functions users will need to run. The following table lists the snapshot table functions and their corresponding request types.
Table 1. Snapshot request types
Snapshot table function Snapshot request type
SNAP_GET_AGENT APPL_ALL
SNAP_GET_AGENT_MEMORY_POOL APPL_ALL
SNAP_GET_APPL APPL_ALL
SNAP_GET_APPL_INFO APPL_ALL
SNAP_GET_STMT APPL_ALL
SNAP_GET_SUBSECTION APPL_ALL
SNAP_GET_BP_PART BUFFERPOOLS_ALL
SNAP_GET_BP BUFFERPOOLS_ALL
SNAP_GET_DB DBASE_ALL
SNAP_GET_DETAILLOG DBASE_ALL
SNAP_GET_DB_MEMORY_POOL DBASE_ALL
SNAP_GET_HADR DBASE_ALL
SNAP_GET_STORAGE_PATHS DBASE_ALL
SNAP_GET_DBM DB2
SNAP_GET_DBM_MEMORY_POOL DB2
SNAP_GET_FCM DB2
SNAP_GET_FCM_PART DB2
SNAP_GET_SWITCHES DB2
SNAP_GET_DYN_SQL DYNAMIC_SQL
SNAP_GET_LOCK DBASE_LOCKS
SNAP_GET_LOCKWAIT APPL_ALL
SNAP_GET_TAB DBASE_TABLES
SNAP_GET_TAB_REORG DBASE_TABLES
SNAP_GET_TBSP DBASE_TABLESPACES
SNAP_GET_TBSP_PART DBASE_TABLESPACES
SNAP_GET_CONTAINER DBASE_TABLESPACES
SNAP_GET_UTIL DB2
SNAP_GET_UTIL_PROGRESS DB2

Procedure

  1. Connect to a database. This can be any database in the instance you need to monitor. To be able to call a stored procedure, you must be connected to a database.
  2. Determine the snapshot request type, and the database and partition you need to monitor.
  3. Call the SNAP_WRITE_FILE stored procedure with the appropriate parameter settings for the snapshot request type, database, and partition. For example, here is a call that will capture a snapshot of application information about the SAMPLE database for the current connected partition:
       CALL SNAP_WRITE_FILE('APPL_ALL','SAMPLE',-1)
    The SNAP_WRITE_FILE stored procedure has three input parameters:
    • a snapshot request type (see Table 1, which provides a cross-reference of the snapshot table functions and their corresponding request types)
    • a VARCHAR (128) for the database name. If you enter NULL, the name of the currently connected database is used.
      Note: This parameter does not apply to the database manager level snapshot table functions; they only have parameters for request type and partition number.
    • a SMALLINT for the partition number (a value between 0 and 999). For the partition number parameter, enter the integer corresponding to partition number you want to monitor. To capture a snapshot for the currently connected partition, enter a value of -1 or a NULL. To capture a global snapshot, enter a value of -2.

Results

Once the snapshot data has been saved to a file, all users can issue queries with the corresponding snapshot table functions, specifying (NULL, NULL) as input values for database-level table functions, and (NULL) for database manager level table functions. The monitor data they receive is pulled from the files generated by the SNAP_WRITE_FILE stored procedure.
Note: While this provides a means to limit user access to sensitive monitor data, this approach does have some limitations:
  • The snapshot monitor data available from the SNAP_WRITE_FILE files is only as recent as the last time the SNAP_WRITE_FILE stored procedure was called. You can ensure that recent snapshot monitor data is available by making calls to the SNAP_WRITE_FILE stored procedure at regular intervals. For instance, on UNIX systems you can set a cron job to do this.
  • Users issuing queries with the snapshot table functions cannot identify a database or partition to monitor. The database name and partition number identified by the user issuing the SNAP_WRITE_FILE calls determine the contents of the files accessible by the snapshot table functions.
  • If a user issues an SQL query containing a snapshot table function for which a corresponding SNAP_WRITE_FILE request type has not been run, a direct snapshot is attempted for the currently connected database and partition. This operation is successful only if the user has SYSADM, SYSCTRL, SYSMAINT, or SYSMON authority.