Wednesday, May 7, 2014

How to Reclaim / Resize Table space.

Using this statement you can find how to resize you datafile.

SQL> ALTER DATABASE DATAFILE 'D:\APP\ORADATA\STLBAS\ORBSYS01.DBF' RESIZE 1122M;

Database altered.

Scripts:
-----------

SELECT    'ALTER DATABASE DATAFILE '''
       || FILE_NAME
       || ''' RESIZE '
       || US
       || 'M;'
  FROM (  SELECT DF.TABLESPACE_NAME,
                 DF.FILE_NAME,
                 SUM (DF.BYTES) / 1024 / 1024/1024 "Total Size (MB)",
                 SUM (FS.BYTES) / 1024 / 1024/1024 "Total Free (MB)",
                 ROUND (
                    ( (SUM (DF.BYTES) / 1024 / 1024/1024)
                     - (SUM (FS.BYTES) / 1024 / 1024/1024))
                    + 50)
                    US,
                 TRUNC ( ( (SUM (FS.BYTES) / (SUM (DF.BYTES)) * 100)), 1)
                 || '%'
                    "Free Percent"
            FROM DBA_DATA_FILES DF, DBA_FREE_SPACE FS
           WHERE FS.TABLESPACE_NAME = DF.TABLESPACE_NAME
                 AND DF.TABLESPACE_NAME NOT IN
                        ('USERS', 'UNDOTBS1', 'SYSAUX', 'SYSTEM')
        GROUP BY DF.TABLESPACE_NAME, DF.FILE_NAME
        ORDER BY 1)


Finding Data file Size :
----------------------------

  SELECT DF.TABLESPACE_NAME,
         DF.FILE_NAME,
         ROUND (SUM (DF.BYTES) / 1024 / 1024 / 1024, 2) "Total Size (MB)",
         ROUND (SUM (FS.BYTES) / 1024 / 1024 / 1024, 2) "Total Free (MB)",
         ROUND (
            ( (SUM (DF.BYTES) / 1024 / 1024 / 1024)
             - (SUM (FS.BYTES) / 1024 / 1024 / 1024))
            + 50)
            US,
         TRUNC ( ( (SUM (FS.BYTES) / (SUM (DF.BYTES)) * 100)), 1) || '%'
            "Free Percent"
    FROM DBA_DATA_FILES DF, DBA_FREE_SPACE FS
   WHERE FS.TABLESPACE_NAME = DF.TABLESPACE_NAME
         AND DF.TABLESPACE_NAME NOT IN
                ('USERS', 'UNDOTBS1', 'SYSAUX', 'SYSTEM')
GROUP BY DF.TABLESPACE_NAME, DF.FILE_NAME
ORDER BY 3 DESC

No comments:

Post a Comment