Oracle Tablespace High Water Mark (HWM) Query

๐Ÿ” Purpose:

  • To calculate the High Water Mark (HWM) in GB for each data file.

  • The HWM is the highest block ever used by an object in the tablespace.

๐Ÿงพ Query:

            SELECT 
                 a.tablespace_name,
                 a.file_name,
                ((b.maximum + c.blocks - 1) * d.db_block_size) / 1024 / 1024 / 1024 AS highwater_in_GB
            FROM 
                dba_data_files a,
                (SELECT file_id, MAX(block_id) AS maximum
                FROM dba_extents
     GROUP BY file_id) b,
                dba_extents c,
                    (SELECT value AS db_block_size
                     FROM v$parameter
                     WHERE name = 'db_block_size') d
      WHERE 
                a.file_id = b.file_id
                AND c.file_id = b.file_id
                AND c.block_id = b.maximum
      ORDER BY 
                a.tablespace_name, 
                a.file_name;

๐Ÿ“Œ Use Case:

  • Identify data files with significant free space beyond HWM for resizing or reclaiming space.

  • Useful before performing operations like shrink, transport, or reorganization.

Comments

Popular posts from this blog

Managing Oracle Data Files – Resizing and Adding

Oracle Database Basic Consepts (Start / Stop / Check Database Status)

Kubernetes Administration – Essential Commands for IFS Cloud