You are on page 1of 12

DB2 9.

7 New Features Reducing the High Water Mark

Applies to:
All SAP releases on DB2 for Linux, UNIX and Windows Version 9.7. For more information, visit the Landscape Design and Architecture homepage.

Summary
Reclaiming unused storage below the table spaces' high-water mark was a lengthy and sometimes a troublesome task. This involved using a combination of various DB2 tools, which at times, was not fully guaranteed to reduce the high-water mark. Now with DB2 9.7 and table spaces enabled with reclaimable storage, it is possible to easily lower the high-water mark and reclaim the trapped free space. This paper provides an overview of the extent movement process, as well as examples on how to start and monitor the process. Author: Edgar Maniago

Company: SAP Created on: 05 May 2009

Author Bio
Since joining SAP in 2005, Edgar Maniago, a Software Engineer, has been a member of the IBM SAP Integration and Support Centre located in the Toronto IBM Lab. He currently tests, develops and integrates new features of DB2 with SAP. Through his SAP development support role and being a Customer Advocate for IBM, Edgar assists SAP consultants and customers with activities such as troubleshooting and performance optimization.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 1

DB2 9.7 New Features Reducing the High Water Mark

Table of Contents
The High-Water Mark Problem ........................................................................................................................... 3 Reducing the High-Water Mark Pre DB2 9.7...................................................................................................... 4 Reducing the High-Water Mark in DB2 9.7 ........................................................................................................ 4 Extent Movement Overview ............................................................................................................................ 4 Table Space Prerequisites .............................................................................................................................. 5 Reducing the HWM in Automatic Storage Table Spaces ............................................................................... 5 Reducing the HWM in DMS Table Spaces ..................................................................................................... 5 Monitoring the Extent Movement .................................................................................................................... 6 Example: Reducing the HWM with DB2 9.7 ....................................................................................................... 8 Check Table Space for Free Space ................................................................................................................ 8 Determine the Free Pages below the High-Water Mark ................................................................................. 8 Start the Extent Movement and Reclaim Space ............................................................................................. 8 Monitor the Extent Movement ......................................................................................................................... 9 Check the Results ......................................................................................................................................... 10 Related Content ................................................................................................................................................ 11 Copyright........................................................................................................................................................... 12

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 2

DB2 9.7 New Features Reducing the High Water Mark

The High-Water Mark Problem


The table space high-water mark indicates the page number of the highest allocated page in a table space. This is different from the number of used pages, since the actual number of pages in use can be below the high-water mark. For example, the last page in the table space is used, but the rest of the table space is empty, the high-water mark will point to the last page. For example, looking at Figure 1, two tables have been created in one table space. The high-water mark points the last used page. If Table 1 is dropped, there is now some free space within the table space. However, the free space below the high-water mark cannot be reclaimed by DB2 to be used for other table spaces, databases, or even outside of the database. This trapped free space can only be used by the current table space to which the free space belongs.

Figure 1 - High-Water Mark Problem

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 3

DB2 9.7 New Features Reducing the High Water Mark

Reducing the High-Water Mark Pre DB2 9.7


One method is using a combination of db2dart and REORG. Running db2dart with the /LHWM option will provide a report that specifies which tables and in what order to perform the REORG. IBM has a Technote describing this method. However, this can be cumbersome, involve very lengthy system outages, and is not fully guaranteed to work in all cases. For example, if the high-water mark is held by object table data extents, the db2dart/REORG combination is ineffective in lowering the high-water mark.

Reducing the High-Water Mark in DB2 9.7


Extent Movement Overview With DB2 9.7 it is now possible to reduce the high-water mark and reclaim the free space. For example, shown in Figure 2 below, extents (groups of pages) holding the high-water mark can be moved to a new location, lower down in the table space. The table space meta-data is updated to reflect this change and now the free space is located at the end of the table space and can be reclaimed. As mentioned before, previous versions of DB2 could not lower the high-water mark if it is held by object table data extents. However, with DB2 9.7s new extent movement, this is no longer the case and the highwater can be lowered regardless of what is holding the extent.

Figure 2 - Extent Movement

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 4

DB2 9.7 New Features Reducing the High Water Mark

Table Space Prerequisites Only non-temporary automatic storage or DMS table spaces created in DB2 9.7 can use this feature. Existing automatic storage or DMS table spaces created with an earlier version of DB2 cannot reduce their high-water mark through extent movement. In earlier versions of DB2, the buffer pool services layer had the ability to directly access pages of data on disk and cache the physical location of the object for future reference. As a consequence, pages belonging to the object can no longer be moved from one location to another since the location has been cached. With newly created table spaces in DB2 9.7 direct access to disk no longer takes place. Access is only allowed through the table space meta-data pages. That is, the buffer pool services layer will read the metadata pages to figure out the physical location of the page on disk. Therefore, the high-water mark can be lowered by moving the extents to a new location with the meta-data updated accordingly. Existing table spaces can be replaced by creating a new table space with DB2 9.7. Then the data can be moved either through an online table move to a new table space. Another possibility is to export all the data in the table space and re-import into a new table space using DB2 tools. Reducing the HWM in Automatic Storage Table Spaces After creating new table spaces managed by automatic storage in DB2 9.7, the following command can be used to lower the high-water mark and reclaim the free space:
ALTER TABLESPACE <tsname> REDUCE --+-----------------------------+--'-- <size> --+-------------+--+--' | +----- K -----+ | | +----- M -----+ | | +----- G -----+ | | '-- PERCENT --' | '--- MAX ---------------------' '--- STOP --------------------'

Once the above command has been executed, the extent movement operation will run asynchronously. To monitor the progress, see the section Monitoring the Extent Movement below. If the MAX option is specified, the database manager will try to reduce the high-water mark as much as possible, followed by a reduction in the container size. With the SIZE option, the database manager will try to reduce the table space by the specified amount. The extent movement operation can be stopped by re-running the ALTER..REDUCE STOP command. All extents that have been moved will be committed, the high-water mark will be reduced to its value at the time of the abort and containers will be reduced. Reducing the HWM in DMS Table Spaces After creating new DMS table spaces in DB2 9.7, the following command is used to lower the high-water mark of DMS table spaces:
ALTER TABLESPACE <tsname> LOWER HIGH WATER MARK --+----------+--'-- STOP --'

After running the above command, the extent movement operation will run asynchronously. To monitor the progress, see the section Monitoring the Extent Movement below. Once the high-water mark has been reduced the free space can now be reclaimed by calling the regular REDUCE options of the ALTER TABLESPACE command.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 5

DB2 9.7 New Features Reducing the High Water Mark

Monitoring the Extent Movement The extent movement operations can be monitored through the two new table functions MON_GET_TABLESPACE and MON_GET_EXTENT_MOVEMENT_STATUS. The table function MON_GET_TABLESPACE returns the same information (and more) as the now deprecated table space snapshot. The following is returned by the table function: Column name
TBSP_NAME TBSP_TYPE

Description Table space name. Table space type. Only DMS table spaces can have their high-water mark lowered through extent movement. Table space state. A state of MOVE_IN_PROGRESS is shown if the extent movement is in progress. The total number of pages that are currently used. The total number of pages that are currently free. The total number of pages in a table space. The page in the table space that is holding the highwater mark. Reclaimable space enabled. A value of 1 indicates that the table space is enabled for reclaimable storage.

TBSP_STATE

TBSP_USED_PAGES TBSP_FREE_PAGES TBSP_TOTAL_PAGES TBSP_PAGE_TOP

RECLAIMABLE_SPACE_ENABLED

Not all the columns of MON_GET_TABLESPACE are shown in the above table, only the monitor elements related to the table space pages and extents. The table function MON_GET_EXTENT_MOVEMENT_STATUS is used to monitor the asynchronous extent movement. The following is returned by the table function: Column name
TBSP_NAME CURRENT_EXTENT LAST_EXTENT NUM_EXTENTS_MOVED

Description Table space name. The extent currently being moved. The last extent that was moved. The number of extents that have already been moved during the current extent movement operation.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 6

DB2 9.7 New Features Reducing the High Water Mark

NUM_EXTENTS_LEFT

The number of extents remaining to be moved during the current extent movement operation. The total elapsed time, in milliseconds, of the current extent movement operation.

TOTAL_MOVE_TIME

Not all the columns of MON_GET_EXTENT_MOVEMENT_STATUS are shown in the table above. The table space snapshot is deprecated with DB2 9.7. Therefore the table spaces states have not been updated to reflect the new state of MOVE_IN_PROGRESS. For example, the following is returned while the extent movement is in progress:
db2 get snapshot for tablespaces on LRP Tablespace name Tablespace ID Tablespace Type Tablespace Content Type Tablespace Page size (bytes) Tablespace Extent size (pages) Automatic Prefetch size enabled Buffer pool ID currently in use Buffer pool ID next startup Using automatic storage Auto-resize enabled File system caching Tablespace State Detailed explanation: Tablespace Prefetch size (pages) = = = = = = = = = = = = = EXTENTREMAP 1 Database managed space All permanent data. Large table space. 16384 2 Yes 1 1 Yes Yes No 0x'00080000'

= 8

As shown above, the table space state shows a 0x0008000 and the detailed explanation field is blank. Therefore, it is best to use the new table functions to monitor the extent movement.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 7

DB2 9.7 New Features Reducing the High Water Mark

Example: Reducing the HWM with DB2 9.7


The following example will check an automatic storage table space for free space, reduce the high-water mark and reclaim the free space. The example also shows how to monitor the extent movement operation. Check Table Space for Free Space Check the table space to see if there is free space that can be reclaimed using MON_GET_TABLESPACE table function:
db2 "select varchar(tbsp_name, 15) as tbsp_name, tbsp_type, reclaimable_space_enabled, tbsp_free_pages from table (mon_get_tablespace('EXTENTRE MAP',-2)) as t" TBSP_NAME TBSP_TYPE RECLAIMABLE_SPACE_ENABLED TBSP_FREE_PAGES --------------- ---------- ------------------------- -------------------EXTENTREMAP DMS 1 6526 1 record(s) selected.

We see that this automatic storage table space has 6526 free pages and that it is enabled for reclaimable storage. Determine the Free Pages below the High-Water Mark Now check to see how many free pages are above and below the high-water mark using the MON_GET_TABLESPACE table function:
db2 "select varchar(tbsp_name, 15) as tbsp_name, tbsp_free_pages, tbsp_total_pages, tbsp_page_top from table (mon_get_tablespace('EXTENTREMAP',-2)) as t" TBSP_NAME TBSP_FREE_PAGES TBSP_TOTAL_PAGES TBSP_PAGE_TOP --------------- -------------------- -------------------- -------------------EXTENTREMAP 6526 3538280 3536394 1 record(s) selected.

Looking at the column TBSP_PAGE_TOP, we see that the high-water mark is 3536394 pages. Looking at the column TBSP_TOTAL_PAGES, we see that the total pages used by the table space is 3538280. So there are only 1886 free pages above the high-water mark and 4640 free pages below the high-water mark. With older versions of DB2, those 4640 pages would be trapped since the high-water mark cannot be lowered. Since this table space has been created with DB2 9.7 and it is enabled for reclaimable storage, the highwater mark can be reduced through extent movement. Start the Extent Movement and Reclaim Space The extent movement can be triggered by calling the ALTER TABLESPACE command:
db2 alter tablespace extentremap reduce max DB20000I The SQL command completed successfully.

The above command will reduce the high-water and reclaim the maximum amount of space. After entering the command, it will return immediately and the process will run asynchronously. The extent movement can then be monitored through the new table functions.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 8

DB2 9.7 New Features Reducing the High Water Mark

Monitor the Extent Movement To monitor the asynchronous extent movement, use MON_GET_EXTENT_MOVEMENT_STATUS table function:
db2 "select varchar(tbsp_name,15) as tbsp_name, last_extent, num_extents_moved, num_extents_left, total_move_time from table (mon_get_extent_movement_status('EXTENTREMAP',-1)) AS T"

TBSP_NAME LAST_EXTENT NUM_EXTENTS_MOVED NUM_EXTENTS_LEFT TOTAL_MOVE_TIME --------------- ----------- ----------------- ---------------- -------------------EXTENTREMAP 1753956 14240 471593 276005 1 record(s) selected.

The column NUM_EXTENTS_MOVED shows the number of extents that have already been moved, while the column NUM_EXTENTS_LEFT shows the number of extents remaining that have to be moved. The TOTAL_MOVE_TIME is the total elapsed time, in milliseconds, taken to move the extents. Querying the table space status with the MON_GET_TABLESPACE table function will show that the extent movement is currently in progress:
db2 "select varchar(tbsp_name, 15) as tbsp_name, tbsp_state from table (mon_get_tablespace('EXTENTREMAP',-2)) as t" TBSP_NAME TBSP_STATE --------------- ------------------------EXTENTREMAP MOVE_IN_PROGRESS 1 record(s) selected.

Table space snapshots can still be used to monitor the extent movement as well. However, they are deprecated and will be removed in future releases. While the extent movement is taking place, the following is returned:
db2 get snapshot for tablespaces on LRP Tablespace name Tablespace ID Tablespace Type Tablespace Content Type Tablespace Page size (bytes) Tablespace Extent size (pages) Automatic Prefetch size enabled Buffer pool ID currently in use Buffer pool ID next startup Using automatic storage Auto-resize enabled File system caching Tablespace State Detailed explanation: Tablespace Prefetch size (pages) = = = = = = = = = = = = = EXTENTREMAP 1 Database managed space All permanent data. Large table space. 16384 2 Yes 1 1 Yes Yes No 0x'00080000'

= 8

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 9

DB2 9.7 New Features Reducing the High Water Mark

As seen above, the table space state 0x00080000 indicates that the extent movement is in progress. When the extent movement starts, the following is shown in db2diag.log:
2009-04-20-14.02.27.955106-240 I180293615A479 LEVEL: Warning PID : 217256 TID : 12701 PROC : db2sysc 0 INSTANCE: db2lrp NODE : 000 DB : LRP APPHDL : 0-29584 APPID: *LOCAL.DB2.090420180227 AUTHID : DB2LRP EDUID : 12701 EDUNAME: db2agent (LRP) 0 FUNCTION: DB2 UDB, buffer pool services, sqlbExtentMovementEntryPoint, probe:4608 DATA #1 : <preformatted> Extent Movement started on table space 1 ...

After the extent movement has finished, the following can be seen in db2diag.log:
2009-04-20-15.12.41.240096-240 I180299899A562 LEVEL: Warning PID : 217256 TID : 12701 PROC : db2sysc 0 INSTANCE: db2lrp NODE : 000 DB : LRP APPHDL : 0-29584 APPID: *LOCAL.DB2.090420180227 AUTHID : DB2LRP EDUID : 12701 EDUNAME: db2agent (LRP) 0 FUNCTION: DB2 UDB, buffer pool services, sqlbLockAndMoveExtents, probe:3960 DATA #1 : String, 126 bytes The extent movement operation has moved all extents it could. There are no more free extents lower in the tablespace. Exiting.

If we check the table space state, we can see that extent movement has finished:
db2 "select varchar(tbsp_name, 15) as tbsp_name, tbsp_id, tbsp_state from table (mon_get_tablespace('EXTENTREMAP',-2)) as t"

TBSP_NAME TBSP_ID TBSP_STATE --------------- -------------------- ------------------------EXTENTREMAP 1 NORMAL 1 record(s) selected.

Check the Results If we check the table space information, we can see that the high-water mark has been reduced and the space has been reclaimed:
db2 "select varchar(tbsp_name, 15) as tbsp_name, tbsp_free_pages, tbsp_total_pages, tbsp_page_top from table (mon_get_tablespace('EXTENTREMAP',-2)) as t" TBSP_NAME TBSP_FREE_PAGES TBSP_TOTAL_PAGES TBSP_PAGE_TOP --------------- -------------------- -------------------- -------------------EXTENTREMAP 0 2564740 2564712 1 record(s) selected.

The high-water mark has now been lowered from the page 3536394 to 2564712. Space has been reclaimed as seen by the 0 free pages, as well as the decrease in the size of the DMS containers. That is, the total number of pages in the table space has decreased from 3538280 pages to 2564740 pages.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 10

DB2 9.7 New Features Reducing the High Water Mark

Related Content
For more information, visit the Landscape Design and Architecture homepage.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 11

DB2 9.7 New Features Reducing the High Water Mark

Copyright
2009 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, System i, System i5, System p, System p5, System x, System z, System z9, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, POWER5+, OpenPower and PowerPC are trademarks or registered trademarks of IBM Corporation. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. These materials are provided as is without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages. Any software coding and/or code lines/strings (Code) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.

SAP COMMUNITY NETWORK 2009 SAP AG

SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com 12

You might also like