## 3.3.1  Reclaiming Disk Space
Defragmentation of data volumes must be carried out as a routine housekeeping operation to recover disk space or in response to a disk full event.
## Automatic Housekeeping in SAP HANA 2.0 SPS 06
A housekeeping job was introduced in SAP HANA 2.0 SPS 06 in the automatic data volume management process to recover unused space in a data volume caused by fragmentation. The job runs permanently in the background and becomes active when the measured level of fragmentation overhead on the data volume reaches 150% and stops when the overhead is reduced to 120%. See also SAP Note 3100336 -What is fragmentation in context of SAP HANA persistence? .
In previous releases the reclaim process could not handle snapshots which must remain untouched. The housekeeping process now bypasses snapshots and continues to work through the data volume to the end. If free space is found data pages are taken from the end of the volume to fill up the free space thus reducing the total volume.
The feature is enabled by default but in SPS 06 revisions &lt;= 062.00 the full functionality must be enabled by setting a configuration parameter as described in SAP Note 3198269 -Enable Automatic Data Volume Reclaim in SAP HANA 2 SPS06 . The feature can be disabled by setting parameter continuous_reclaim_enabled in service.ini (persistence section) to False .
In a replication scenario automatic reclaim can also be run on connected secondary and tertiary sites by setting the configuration parameter on those systems. It is no longer necessary to run additional defragmentation processes on those systems.
The following monitoring view showing statistics aggregated over all partitions gives insight into the data volume reclaim activity: m_DATA_VOLUME_RECLAIm_STATISTICS.
## General Information
Reclaiming disk space is necessary because the size allocated to a data file is automatically increased as more space is required, but it is not automatically decreased when less space is required. This may create a difference between allocated size and used size.
For more information on data and log volumes refer to:
- Persistent Data Storage in the SAP HANA Database in the SAP HANA Administration Guide .
- SAP Note 1870858 -HANA Alerts related to file system utilization .
For routine monitoring of disk usage the following scripts from SAP Note 1969700 -SQL Statement Collection for SAP HANA may be helpful:
- HANA_Disks_Overview
- HANA_Disks_SuperblockStatistics
- HANA_Tables_ColumnStore_TableSize
- HANA_Tables_TopGrowingTables_Size_History
## Reclaiming Disk Space Command
The RECLAIM DATAVOLUME statement is described in detail in the SAP HANA SQL and System Views Reference . The following example illustrates the usage:
```
alter system reclaim datavolume 'myhost:30003' 120 defragment
```
The example shows a reasonable payload percentage of 120, that is, an overhead of 20% fragmentation is acceptable. Smaller payload percentage values can significantly increase the defragmentation runtime.
The following example lines from the SuperblockStatistics report show a comparison of disk usage before and after defragmentation:
After defragmentation the values for used and allocated disk size are much closer together, the total block count is reduced and the fragmentation percentage is much lower:
## Monitoring the Reclaim Process
No monitoring tool is available to check the progress of the RECLAIM command. The following options may be helpful:
1. Check for savepoint activity to verify that the RECLAIM process is running. This will confirm that savepoints are consistently being written:
select * from m_savepoints
2. Enable the indexserver trace to get information about the operation and estimate the job progress: set trace "pageaccess = info"
## Snapshots: Reasons Why Reclaim May Fail
In some situations where snapshots are being created RECLAIM may fail:
1. In a high availability scenario RECLAIM may not work because data snapshots which are part of the replication process may conflict with the RECLAIM datavolume command. SAP Note 2332284 -Data volume reclaim failed because of snapshot pages gives details of how to temporarily stop the creation of snapshots to avoid this problem.
2. Snapshots related to backups may also prevent RECLAIM from working. SAP Note 2592369 -HANA DataVolume Full describes steps to investigate the age of snapshots by querying the m_SNAPSHOTS view
and, if necessary, to manually delete snapshots using the hdbcons command. It may then be possible to rerun the RECLAIM process.
## Related Information
Persistent Data Storage in the SAP HANA Database