< Day Day Up > |
Prior to the introduction of RTS, the only way to gather statistics about DB2 database structures was by running the RUNSTATS utility. As discussed in Chapter 34, "Catalog Manipulation Utilities," RUNSTATS collects statistical information about DB2 database objects and stores this data in the DB2 Catalog. RTS, on the other hand, runs in the background and automatically updates statistics in two special tables as the data in DB2 databases is modified. Where RUNSTATS is a hands-on administrative process, RTS is hands-off. NOTE Real Time Statistics was announced with APARs PQ48447 , PQ48448 , PQ46859 , and PQ56256 . The RTS TablesAlthough DB2 is always collecting RTS data, nothing is externalized until you set up the RTS database and tables to store the real time statistics. The RTS database is named DSNRTSDB and there is one table space ( DSNRTSTS ) with two tables:
Tables 26.2 and 26.3 describe the columns of these two tables. Each table has a unique index defined on it. Both are defined on the DBID , PSID , and PARTITION columns. The indexes' names are
Table 26.2. SYSIBM.TABLESPACESTATS Columns
Table 26.3. SYSIBM.INDEXSPACESTATS Columns
When Are Real Time Stats Externalized?As soon as RTS is applied (by running the proper version or maintenance level of DB2), DB2 begins to gather real-time statistics. However, the RTS tables must exist in order for DB2 to externalize the real-time statistics that it gathers. After the RTS tables have been created and started, DB2 externalizes real-time statistics to the tables at the following times:
RTS AccuracyIn certain situations, the RTS values might not be 100% accurate. Situations that can cause the real-time statistics to be off include
To fix RTS statistics that are inaccurate, run a REORG , RUNSTATS , or COPY on the objects for which those stats are suspect. CAUTION If you are using DB2 utilities from a third-party vendor other than IBM, be sure that those utilities work with RTS. The third-party utilities should be able both to reset the RTS values and use the RTS stats for recommending when to run utilities. DSNACCOR : The RTS Stored ProcedureIBM supplies a sample stored procedure called DSNACCOR that can be used to query the RTS tables and make recommendations based on the statistics. You can use DSNACCOR to recommend when to run a REORG , take an image copy, or run RUNSTATS . Additionally, DSNACCOR can report on the data set extents of tablespaces and index spaces as well as on objects in a restricted state. You can specify parameters to indicate to DSNACCOR which tablespaces and indexes to analyze, or just run it without parameters to evaluate all tablespaces and index spaces in the subsystem. CAUTION If the RTS values are inaccurate, the recommendations made by DSNACCOR will not be correct. Also, DSNACCOR makes recommendations based on general formulas requiring user input about your maintenance policies. These recommendations might not be accurate for every installation or subsystem. You should consider using DSNACCOR in conjunction with DB2 Control Center. Control Center provides a nice GUI interface to the parameters of DSNACCOR , making it easier to use than directly calling the procedure would be. Using the Real Time StatisticsThe following RTS guidelines and queries can be used to help you identify maintenance and administration that needs to be carried out for database objects in your DB2 subsystems. Checking for ActivityBecause real-time statistics are updated in an ongoing manner as DB2 operates, you can use them to see if any activity has occurred during a specific timeframe. To determine whether any activity has happened in the past several days for a particular tablespace or index, use the UPDATESTATSTIME column. Here is an example checking whether any activity has occurred in the past ten days for a tablespace (just supply the tablespace name): SELECT DBNAME, NAME, PARTITION, UPDATESTATSTIME FROM SYSIBM.TABLESPACESTATS WHERE UPDATESTATSTIME > CURRENT TIMESTAMP - 10 DAYS AND NAME = ?; Basic Tablespace InformationThe RTS tables contain some good basic information about tablespaces. The following query can be run to report on the number of rows, active pages, space used, number of extents, and when the COPY , REORG , LOAD REPLACE , and RUNSTATS were last run: SELECT DBNAME, NAME, PARTITION, TOTALROWS, NACTIVE, SPACE, EXTENTS, UPDATESTATSTIME, STATSLASTTIME, LOADRLASTTIME, REORGLASTTIME, COPYLASTTIME FROM SYSIBM.TABLESPACESTATS ORDER BY DBNAME, NAME, PARTITION; You can add a WHERE clause to this query to limit the output to only a certain database or for specific tablespaces. Pay particular attention to the timestamps indicating the last time that COPY , REORG , and RUNSTATS were run. If the date is sufficiently old, consider further investigating whether you should take an image copy, reorganize the tablespace, or run RUNSTATS . Keep in mind though, that the span of time between utility runs is not the only indicator for when to copy, reorganize, or capture statistics. For example, RUNSTATS might need to be run only once on static data; similar caveats apply to COPY and REORG when data does not change. Reorganizing TablespacesStatistics that can help determine when to reorganize a tablespace include space allocated, extents, number of INSERT s, UPDATE s, and DELETE s since the last REORG or LOAD REPLACE , number of unclustered INSERT s, number of disorganized LOBs, and number of near and far indirect references created since the last REORG . The following query can be used to monitor reorganization RTS statistics: SELECT DBNAME, NAME, PARTITION, SPACE, EXTENTS, REORGLASTTIME, REORGINSERTS, REORGDELETES, REORGUPDATES, REORGINSERTS+REORGDELETES+REORGUPDATES AS TOTAL_CHANGES, REORGDISORGLOB, REORGUNCLUSTINS, REORGMASSDELETE, REORGNEARINDREF, REORGFARINDREF FROM SYSIBM.TABLESPACESTATS ORDER BY DBNAME, NAME, PARTITION; You might want to add a WHERE clause that limits the tablespaces returned to just those that exceed a particular limit. For example,
Another way to get more creative with your RTS queries is to build formulas into them to retrieve only those tablespaces that need to be reorganized. For example, the following query will return only those tablespaces having more than 10% of their rows as near or far indirect references: SELECT DBNAME, NAME, PARTITION, SPACE, EXTENTS FROM SYSIBM.TABLESPACESTATS WHERE TOTALROWS > 0 AND (((REORGNEARINDREF + REORGFARINDREF)*100)/TOTALROWS) > 10 ORDER BY DBNAME, NAME, PARTITION; Of course, you can change the percentage as you wish. After running the query, you have a list of tablespaces meeting your criteria for reorganization. Examining the Impact of a ProgramYou can use the TOTALROWS column of SYSIBM.TABLESPACESTATS to determine how many rows were impacted by a particular program or process. Simply check TOTALROWS for the tablespace both before and after the process; the difference between the values is the number of rows impacted. When to Run RUNSTATS for a TablespaceThere are also statistics to help in determining when RUNSTATS should be executed. Run the following query to show the number of INSERT s, UPDATE s, and DELETE s since the last RUNSTATS execution: SELECT DBNAME, NAME, PARTITION, STATSLASTTIME, STATSINSERTS, STATSDELETES, STATSUPDATES, STATSINSERTS+STATSDELETES+STATSUPDATES AS TOTAL_CHANGES, STATSMASSDELETE FROM SYSIBM.TABLESPACESTATS ORDER BY DBNAME, NAME, PARTITION; When to Take an Image Copy for a TablespaceYou can issue the following query to report on statistics that will help you to determine whether a COPY is required: SELECT DBNAME, NAME, PARTITION, COPYLASTTIME, COPYUPDATEDPAGES, COPYCHANGES, COPYUPDATELRSN, COPYUPDATETIME FROM SYSIBM.TABLESPACESTATS ORDER BY DBNAME, NAME, PARTITION; Basically, as the number of distinct updated pages and changes since the last COPY execution increases, the need to take an image copy increases . A good rule of thumb to follow is when the percentage of updated pages since the last COPY is more than 25% of the active pages, then it is time to COPY the tablespace. You can add the following WHERE clause to the previous query to limit the output to only these tablespaces: WHERE ((COPYUPDATEDPAGES*100) / NACTIVE) > 25 Basic Index Space InformationDo not forget that there are also RTS statistics gathered on indexes. The following query can be run to report on the number of rows, active pages, space used, number of extents, and when the COPY , REORG , LOAD REPLACE , and RUNSTATS were last run: SELECT DBNAME, INDEXSPACE, PARTITION, TOTALENTRIES, NLEVELS, NACTIVE, SPACE, EXTENTS, UPDATESTATSTIME, LOADRLASTTIME, REBUILDLASTTIME, REORGLASTTIME, STATSLASTTIME, COPYLASTTIME FROM SYSIBM.INDEXSPACESTATS ORDER BY DBNAME, INDEXSPACE, PARTITION; Reorganizing Index SpacesJust like the tablespace stats, there are index space statistics that can be used to determine when to reorganize indexes. These statistics include the last time REBUILD , REORG , or LOAD REPLACE occurred, as well as statistics showing the number of INSERT s and DELETE s since the last REORG or REBUILD . RTS does not skimp in the details. You get both real and pseudo DELETE s, as well as both singleton and mass DELETE information. RTS also tracks both the number of index levels and index page split information resulting in near and far indirect references since the last REORG , REBUILD INDEX , or LOAD REPLACE . The following query can be used to return this information: SELECT DBNAME, INDEXSPACE, PARTITION, REORGLASTTIME, LOADRLASTTIME, REBUILDLASTTIME, TOTALENTRIES, NACTIVE, SPACE, EXTENTS, NLEVELS, REORGNUMLEVELS, REORGINSERTS, REORGAPPENDINSERT, REORGDELETES, REORGPSEUDODELETES, REORGMASSDELETE, REORGLEAFNEAR, REORGLEAFFAR FROM SYSIBM.INDEXSPACESTATS ORDER BY DBNAME, INDEXSPACE, PARTITION; These statistics can be examined after running jobs or processes that cause heavy data modification. NOTE Pay particular attention to the REORGAPPENDINSERT column. It contains the number of inserts into an index since the last REORG for which the index key was higher than any existing key value. If this column consistently grows, you have identified an object where data is inserted using an ascending key sequence. Think about lowering the free space for such objects, because the free space is wasted space if inserts are always done in ascending key sequence. When to Run RUNSTATS for an Index SpaceRTS provides index space statistics to help determine when to run RUNSTATS similar to the tablespace statistics. Run the following query to show the number of INSERT s, UPDATE s, and DELETE s since the last RUNSTATS execution: SELECT DBNAME, NAME, PARTITION, STATSLASTTIME, STATSINSERTS, STATSDELETES, STATSMASSDELETE FROM SYSIBM.TABLESPACESTATS ORDER BY DBNAME, NAME, PARTITION; |
< Day Day Up > |