Saturday, January 13, 2018

Managing Tablespaces : #4

View information about Tablespace & Datafiles 


Oracle has provided many Data dictionaries to view information about tablespaces and datafiles. Some of them are:

To view information about Tablespaces in a database give the following query

SQL> select * from dba_tablespaces
SQL> select * from v$tablespace;

To view information about Datafiles
SQL> select * from dba_data_files;
SQL> select * from v$datafile;

To view information about Tempfiles
SQL> select * from dba_temp_files;
SQL> select * from v$tempfile;

To view information about free space in datafiles
SQL> select * from dba_free_space;

To view information about free space in tempfiles
SQL> select * from V$TEMP_SPACE_HEADER;

Check the details of the datafiles for a particular TableSpace which needs attention.
Datafiles of a particular TableSpace:
------------------------------------
set pages 500 lines 500
col tablespace_name for a30
col CREATION_TIME for a15
col file_name for a70
select dd.tablespace_name TABLESPACE_NAME,dd.file_name,dd.bytes/1024/1024 Size_MB,dd.autoextensible,dd.maxbytes/1024/1024 MAXSIZE_MB,df.CREATION_TIME
from dba_data_files dd, v$datafile df where df.name=dd.file_name and tablespace_name='&TABLESPACENAME' order by 1,2,6;


Check the tablespace Utilization.

Tablespace Utilization Script including AUTOEXTEND (IN GB)
----------------------------------------------------------
$ sqlplus "/as sysdba"

set pages 500 lines 3276
col tablespace_name format a30
col TABLESPACE_NAME heading "Tablespace|Name"
col Allocated_size heading "Allocated|Size(GB)" form 99999999.99
col Current_size heading "Current|Size(GB)" form 99999999.99
col Used_size heading "Used|Size(GB)" form 99999999.99
col Available_size heading "Available|Size(GB)" form 99999999.99
col Pct_used heading "%Used (vs)|(Allocated)" form 99999999.99

select a.tablespace_name
        ,a.alloc_size/1024/1024/1024 Allocated_size
        ,a.cur_size/1024/1024/1024 Current_Size
        ,(u.used+a.file_count*65536)/1024/1024/1024 Used_size
        ,(a.alloc_size-(u.used+a.file_count*65536))/1024/1024/1024 Available_size
        ,((u.used+a.file_count*65536)*100)/a.alloc_size Pct_used
from     dba_tablespaces t
        ,(select t1.tablespace_name
        ,nvl(sum(s.bytes),0) used
        from  dba_segments s
        ,dba_tablespaces t1
         where t1.tablespace_name=s.tablespace_name(+)
         group by t1.tablespace_name) u
        ,(select d.tablespace_name
        ,sum(greatest(d.bytes,nvl(d.maxbytes,0))) alloc_size
        ,sum(d.bytes) cur_size
        ,count(*) file_count
        from dba_data_files d
        group by d.tablespace_name) a
where t.tablespace_name=u.tablespace_name
and t.tablespace_name=a.tablespace_name
order by t.tablespace_name
/

Tablespace Utilization Script (including AUTOEXTEND) for generating report of more than 80 % used tablespaces (IN GB)
---------------------------------------------------------------------------------------------------------------------
set pages 500 lines 3276
col tablespace_name format a30
col TABLESPACE_NAME heading "Tablespace|Name"
col Allocated_size heading "Allocated|Size(GB)" form 99999999.99
col Current_size heading "Current|Size(GB)" form 99999999.99
col Used_size heading "Used|Size(GB)" form 99999999.99
col Available_size heading "Available|Size(GB)" form 99999999.99
col Pct_used heading "%Used (vs)|(Allocated)" form 99999999.99

select a.tablespace_name
        ,a.alloc_size/1024/1024/1024 Allocated_size
        ,a.cur_size/1024/1024/1024 Current_Size
        ,(u.used+a.file_count*65536)/1024/1024/1024 Used_size
        ,(a.alloc_size-(u.used+a.file_count*65536))/1024/1024/1024 Available_size
        ,((u.used+a.file_count*65536)*100)/a.alloc_size Pct_used
from     dba_tablespaces t
        ,(select t1.tablespace_name
        ,nvl(sum(s.bytes),0) used
        from  dba_segments s
        ,dba_tablespaces t1
         where t1.tablespace_name=s.tablespace_name(+)
         group by t1.tablespace_name) u
        ,(select d.tablespace_name
        ,sum(greatest(d.bytes,nvl(d.maxbytes,0))) alloc_size
        ,sum(d.bytes) cur_size
        ,count(*) file_count
        from dba_data_files d
        group by d.tablespace_name) a
where t.tablespace_name=u.tablespace_name
and ((u.used+a.file_count*65536)*100)/a.alloc_size>80
and t.tablespace_name=a.tablespace_name
order by t.tablespace_name
/

Check the details of the datafiles for a particular TableSpace which needs attention.
Datafiles of a particular TableSpace:
------------------------------------
set pages 500 lines 327
col tablespace_name for a30
col CREATION_TIME for a15
col file_name for a70
select dd.tablespace_name TABLESPACE_NAME,dd.file_name,dd.bytes/1024/1024 Size_MB,dd.autoextensible,dd.maxbytes/1024/1024 MAXSIZE_MB,df.CREATION_TIME
from dba_data_files dd, v$datafile df where df.name=dd.file_name and tablespace_name='&TABLESPACENAME' order by 1,2,6;

Managing Tablespaces : #3

Managing Tablespaces with Oracle Managed Files


Oracle-managed files eliminates the need for you to directly manage the operating system files in an Oracle database. You specify operations in terms of database objects rather than file names. The database internally uses standard file system interfaces to create and delete files as needed for the following database structures:
  • Tablespaces
  • Redo log files
  • Control files
  • Archived logs
  • Block change tracking files
  • Flashback logs
  • RMAN backups
A database can have a mixture of Oracle-managed and unmanaged files. The file system directory specified by either of these parameters must already exist; the database does not create it. The
directory must also have permissions for the database to create the files in it.
The example shows that after DB_CREATE_FILE_DEST is set, the DATAFILE clause can be
omitted from a CREATE TABLESPACE statement. The data file is created in the location
specified by DB_CREATE_FILE_DEST. When you create a tablespace as shown, default values are assigned to all parameters.

when you use an OMF approach, the DB_CREATE_FILE_DEST parameter in the parameter file specifies that datafiles are to be created and defines their location.  The DATAFILE clause to name files is not used because filenames are automatically generated by the Oracle Server, for example, /u01/oracle/ducat/ducat_tbs01.dbf’.
Oracle-managed files have a specific naming format. For example, on Linux and Unix based systems the following format is used:
<destination_prefix>/o1_mf_%t_%u_.dbf
Do not rename an Oracle-managed file. The database identifies an Oracle-managed file based on its name. If you rename the file, the database is no longer able to recognize it as an Oraclemanaged file and will not manage the file accordingly.

Note: By default, ASM uses OMF files, but if you specify an alias name for an ASM data file at tablespace creation time or when adding an ASM data file to an existing tablespace, then that file will not be OMF.
You can also use the ALTER SYSTEM command to dynamically set this parameter in the SPFILE parameter file.

ALTER SYSTEM SET DB_CREATE_FILE_DEST = '/u01/app/oracle/oradata/ducat/';

Additional tablespaces are specified with the CREATE TABLESPACE command shown here that specifies not the datafile name, but the datafile size.  You can also add datafiles with the ALTER TABLESPACE command.

CREATE TABLESPACE ducat_data DATAFILE SIZE 100M;
ALTER TABLESPACE ducat_data ADD DATAFILE;

example:
SQL> show parameter DB_CREATE_FILE_DEST
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest                  string
SQL>
SQL> alter system set db_create_file_dest='/u01/app/oracle/oradata/ducat/omf' scope=both;
System altered.
SQL> show parameter DB_CREATE_FILE_DEST
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_create_file_dest                  string      /u01/app/oracle/oradata/ducat/
                                                 omf
SQL> create tablespace testomf;
Tablespace created.
SQL>

[oracle@localhost omf]$ pwd
/u01/app/oracle/oradata/ducat/omf
[oracle@localhost omf]$ ls -lrt
total 4
drwxr-x--- 3 oracle oinstall 4096 Jan 11 05:00 DUCAT
[oracle@localhost omf]$
[oracle@localhost omf]$ ls -lrt
total 4
drwxr-x--- 3 oracle oinstall 4096 Jan 11 05:00 DUCAT
[oracle@localhost omf]$
[oracle@localhost omf]$
[oracle@localhost omf]$
[oracle@localhost omf]$ cd DUCAT/
[oracle@localhost DUCAT]$ ls -lrt
total 4
drwxr-x--- 2 oracle oinstall 4096 Jan 11 05:00 datafile
[oracle@localhost DUCAT]$ cd datafile/
[oracle@localhost datafile]$ ls -lrt
total 102408
-rw-r----- 1 oracle oinstall 104865792 Jan 11 05:00 o1_mf_testomf_f5f8jkxh_.dbf
[oracle@localhost datafile]$
[oracle@localhost datafile]$ pwd
/u01/app/oracle/oradata/ducat/omf/DUCAT/datafile

[oracle@localhost datafile]$


By default, Oracle-managed data files, including those for the SYSTEM and SYSAUX tablespaces, are 100MB and autoextensible.

Setting the DB_CREATE_ONLINE_LOG_DEST_n parameter prevents log files and control files from being located with datafiles – this will reduce I/O contention.
When OMF tablespaces are dropped, their associated datafiles are also deleted at the operating system level.

Managing Tablespaces : #2


Taking tablespaces Offline or Online

You can take an online tablespace offline so that it is temporarily unavailable for general use. The rest of the database remains open and available for users to access data. Conversely, you can bring an offline tablespace online to make the schema objects within the tablespace available to database users. The database must be open to alter the availability of a tablespace.

ALTER TABLESPACE tablespace
{ONLINE |OFFLINE [NORMAL|TEMPORARY|IMMEDIATE|FOR RECOVER]}

NORMAL:  All data blocks for all datafiles that form the tablespace are written from the SGA to the datafiles.  A tablespace that is offline NORMAL does not require any type of recovery when it is brought back online.

TEMPORARY:  A checkpoint is performed for all datafiles in the tablespace.  Any offline files may require media recovery.

IMMEDIATE:  A checkpoint is NOT performed.  Media recovery on the tablespace is required before it is brought back online to synchronize the database objects.

FOR RECOVER:  Used to place a tablespace in offline status to enable point-in-time recovery. The FOR RECOVER setting has been deprecated. The syntax is supported for backward compatibility
The SYSTEM tablespace cannot be taken offline.
We usually take tablespaces offline for maintenance purposes like below
  • Move a datafile without closing the database.
  • Recover an individual tablespace or datafile.
  • Offline tablespace backup – a tablespace can be backed up while online, but offline backup is faster.
To alter the availability of a tablespace, use the ALTER TABLESPACE statement. You must have the ALTER TABLESPACE or MANAGE TABLESPACE system privilege.
To Take a Tablespace Offline give the following command

SQL>alter tablespace ducat offline;

To again bring it back online give the following command.

SQL>alter tablespace ducat online;

To take individual datafile offline type the following command

SQL>alter database datafile ‘/u01/oracle/ducat/ducat_tbs01.dbf’ offline;

Again to bring it back online give the following command

SQL> alter database datafile ‘/u01/oracle/ducat/ducat_tbs01.dbf’ online;

Note: You can’t take individual datafiles offline it the database is running in NOARCHIVELOG mode. If the datafile has become corrupt or missing when the database is running in NOARCHIVELOG mode then you can only drop it by giving the following command

SQL>alter database datafile ‘/u01/oracle/ducat/ducat_tbs01.dbf’ offline for drop;

Making a Tablespace Read /Read Write 

Making a tablespace read-only prevents write operations on the datafiles in the tablespace. The primary purpose of read-only tablespaces is to eliminate the need to perform backup and recovery of large, static portions of a database. Read-only tablespaces also provide a way to protecting historducatl data so that users cannot modify it. Making a tablespace read-only prevents updates on all tables in the tablespace, regardless of a user's update privilege level.
To make a tablespace read only

SQL>alter tablespace ducat read only;

Again to make it read write

SQL>alter tablespace ducat read write;

Renaming Tablespaces

Using the RENAME TO clause of the ALTER TABLESPACE, you can rename a permanent or temporary tablespace. For example, the following statement renames the users tablespace:

SQL> ALTER TABLESPACE users RENAME TO usersts;

The following affect the operation of this statement:
The COMPATIBLE parameter must be set to 10.0 or higher.
If the tablespace being renamed is the SYSTEM tablespace or the SYSAUX tablespace, then it will not be renamed and an error is raised.If any datafile in the tablespace is offline, or if the tablespace is offline, then the tablespace is not renamed and an error is raised.

Dropping Tablespaces

You can drop a tablespace and its contents (the segments contained in the tablespace) from the database if the tablespace and its contents are no longer required. You must have the DROP TABLESPACE system privilege to drop a tablespace.
Caution: Once a tablespace has been dropped, the data in the tablespace is not recoverable. Therefore, make sure that all data contained in a tablespace to be dropped will not be required in the future. Also, immediately before and after dropping a tablespace from a database, back up the database completely
To drop a tablespace give the following command.

SQL> drop tablespace ducat;

This will drop the tablespace only if it is empty. If it is not empty and if you want to drop it anyhow then add the following keyword

SQL>drop tablespace ducat including contents;

This will drop the tablespace even if it is not empty. But the datafiles will not be deleted you have to use operating system command to delete the files.But If you include datafiles keyword then, the associated datafiles will also be deleted from the disk.

SQL>drop tablespace ducat including contents and datafiles;

Managing Tablespaces : #1

Create a tablespace you must have the CREATE TABLESPACE privilege.

The full CREATE TABLESPACE (and CREATE TEMPORARY TABLESPACE) command syntax is shown here.


CREATE TABLESPACE tablespace
[DATAFILE clause]
[MINIMUM EXTENT integer[K|M]]
[BLOCKSIZE integer [K]]
[LOGGING|NOLOGGING]
[DEFAULT storage_clause ]
[ONLINE|OFFLINE]
[PERMANENT|TEMPORARY]
[extent_management_clause]
[segment_management_clause]
The clauses are defined as follows:
  • TABLESPACE: This clause specifies the tablespace name.
  • DATAFILE: This clause names the one or more datafiles that will comprise the tablespace and includes the full path,  Example
DATAFILE  '/u01/app/oracle/oradata/ducat/ducat01.dbf' SIZE 50M
  • MINIMUM EXTENT: Every used extent for the tablespace will be a multiple of this integer value. Use either T, G, M or K to specify terabytes, gigabytes, megabytes, or kilobytes.
  • BLOCKSIZE: This specifies a nonstandard block size – this clause can only be used if the DB_CACHE_SIZE parameter is used and at least one DB_nK_CACHE_SIZE parameter is set and the integer value for
    BLOCKSIZE must correspond with one of the DB_nK_CACHE_SIZE parameter settings.
  • LOGGING: This is the default – all tables, indexes, and partitions within a tablespace have modifications written to Online Redo Logs.
  • NOLOGGING: This option is the opposite of LOGGING and is used most often when large direct loads of clean data are done during database creation for systems that are being ported from another file  system or DBMS to Oracle.
  • DEFAULT storage_clause:  This specifies default parameters for objects created inside the tablespace.  Individual storage clauses can be used when objects are created to override the specified DEFAULT.
  • OFFLINE:  This parameter causes a tablespace to be unavailable after creation.
  • PERMANENT:  A permanent tablespace can hold permanent database objects.
  • TEMPORARY:  A temporary tablespace can hold temporary database objects, e.g., segments created during sorts as a result of ORDER BY clauses or JOIN views of multiple tables.  A temporary tablespace cannot be specified for EXTENT MANAGEMENT LOCAL or have the BLOCKSIZE clause specified.
  • extent_management_clause: This clause specifies how the extents of the tablespace are managed
  • segment_management_clause:  This specifies how Oracle will track used and free space in segments in a tablespace that is using free lists or bitmap objects.
  • datafile_clause:  filename [SIZE integer [K|M]  [REUSE] ,[ AUTOEXTEND ON | OFF ]

filename:  includes the path and filename and file size.  ,
REUSE: specified to reuse an existing file.

Tablespaces can be either Locally Managed to Dictionary Managed.  Dictionary managed tablespaces have been deprecated (are no longer used--are obsolete) with Oracle 11g;
however, you may encounter them when working at a site that is using Oracle 10g.
Locally Managed
The extents allocated to a locally managed tablespace are managed through the use of bitmaps.
  • Each bit corresponds to a block or group of blocks (an extent).
  • The bitmap value (on or off) corresponds to whether or not an extent is allocated or free for reuse.
  • Local management is the default for the SYSTEM tablespace beginning with Oracle 10g.
  • When the SYSTEM tablespace is locally managed, the other tablespaces in the database must also be either locally managed or read-only
  • Local management reduces contention for the SYSTEM tablespace because space allocation and deallocation operations for other tablespaces do not need to use data dictionary tables.
  • The LOCAL option is the default so it is normally not specified.
  • With the LOCAL option, you cannot specify any DEFAULT STORAGE, MINIMUM EXTENT, or TEMPORARY clauses.
  • Concurrency and speed of space operations is improved, because space allocations and deallocations modify locally managed resources (bitmaps stored in header files) rather than requiring centrally managed resources such as enqueues Performance is improved, because recursive operations that are sometimes required during dictionary-managed space allocation are eliminated
  • When you create a tablespace, if you do not specify extent management, the default is locally managed.
Extent Management

UNIFORM – a specification of UNIFORM means that the tablespace is managed in uniform extents of the SIZE specified.
  • use UNIFORM to enable exact control over unused space and when you can predict the space that needs to be allocated for an object or objects.
  • Use K, M, G, T, etc  to specify the extent size in kilobytes, megabytes, gigabytes, terabytes, etc.  The default is 1M; however, you can specify the extent size with the SIZE clause of the UNIFORM clause
AUTOALLOCATE - a specification of AUTOALLOCATE instead of UNIFORM, then the tablespace is system managed and you cannot specify extent sizes.
  • AUTOALLOCATE is the default.
  • this simplifies disk space allocation because the database automatically selects the appropriate extent size.
  • this does waste some space but simplifies management of tablespace
  • Tablespaces with AUTOALLOCATE are allocated minimum extent sizes of 64K with a minimum of 5 database blocks per extent
Advantages of Local Management
All of these advantages lead to improved system performance in terms of response time, particularly the elimination of the need to coalesce free extents.
  • Local management avoids recursive space management operations.  This can occur in dictionary managed tablespaces if consuming or releasing space in an extent results in another operation that consumes or releases space in an undo segment or data dictionary table.
  • Because locally managed tablespaces do not record free space in data dictionary tables, they reduce contention on these tables
  • Local management of extents automatically tracks adjacent free space, eliminating the need to coalesce free extents.
  • The sizes of extents that are managed locally can be determined automatically by the system
  • Changes to the extent bitmaps do not generate undo information because they do not update tables in the data dictionary
To create a locally managed tablespace give the following command

SQL> CREATE TABLESPACE ducat DATAFILE '/u01/app/oracle/oradata/ducat/ducat01.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL AUTOALLOCATE;

AUTOALLOCATE causes the tablespace to be system managed with a minimum extent size of 64K.
The alternative to AUTOALLOCATE is UNIFORM. which specifies that the tablespace is managed with extents of uniform size. You can specify that size in the SIZE clause of UNIFORM. If you omit SIZE, then the default size is 1M. The following example creates a Locally managed tablespace with uniform extent size of 256K

SQL> CREATE TABLESPACE ducat DATAFILE '/u01/app/oracle/oradata/ducat/ducat01.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL UNIFORM SIZE 256K;

To Create Dictionary Managed Tablespace

SQL> CREATE TABLESPACE ducat DATAFILE '/u01/app/oracle/oradata/ducat/ducat01.dbf' SIZE 50M EXTENT MANAGEMENT DICTIONARY;

Segment Space Management in Locally Managed Tablespaces

Use the SEGMENT SPACE MANAGEMENT clause to specify how free and used space within a segment is to be managed.  Once established, you cannot alter the segment space management method for a tablespace.
MANUAL:  This setting uses free lists to manage free space within segments.
  • Free lists are lists of data blocks that have space available for inserting rows.
  • You must specify and tune the PCTUSED, FREELISTS, and FREELIST GROUPS storage parameters.
  • MANUAL is usually NOT a good choice
AUTO:  This uses bitmaps to manage free space within segments.
  • This is the default.
  • A bitmap describes the status of each data block within a segment with regard to the data block's ability to have additional rows inserted.
  • Bitmaps allow Oracle to manage free space automatically.
  • Specify automatic segment-space management only for permanent, locally managed tablespaces.
  • Automatic generally delivers better space utilization than manual, and it is self-tuning.
CREATE TABLESPACE ducat DATAFILE '/u01/app/oracle/oradata/ducat01.dbf' SIZE 50M EXTENT MANAGEMENT LOCAL                                                                                       SEGMENT SPACE MANAGEMENT AUTO;

Dictionary Managed Dictionary Managed With this approach the data dictionary contains tables that store information that is used to manage extent allocation and deallocation manually.
The DEFAULT STORAGE clause enables you to customize the allocation of extents.  This provides increased flexibility, but less efficiency than locally managed tablespaces.this example creates a tablespace using all DEFAULT STORAGE clauses.

CREATE TABLESPACE ducat  DATAFILE '/u01/app/oracle/oradata/ducat01.dbf'  SIZE 50M  EXTENT MANAGEMENT DICTIONARY                                                                              DEFAULT STORAGE (    INITIAL 50K    NEXT 50K    MINEXTENTS 2    MAXEXTENTS 50    PCTINCREASE 0);
  • The tablespace will be stored in a single, 50M datafile.
  • The EXTENT MANAGEMENT DICTIONARY clause specifies the management.
All segments created in the tablespace will inherit the default storage parameters unless their storage parameters are specified explicitly to override the default.
The storage parameters specify the following:
  • INITIAL – size in bytes of the first extent in a segment.
  • NEXT – size in bytes of second and subsequent segment extents.
  • PCTINCREASE – percent by which each extent after the second extent grows.
SMON periodically coalesces free space in a dictionary-managed tablespace, but only if the PCTINCREASE setting is NOT zero.
Use ALTER TABLESPACE <tablespacename> COALESCE to manually coalesce adjacent free extents.
  • MINEXTENTS – number of extents allocated at a minimum to each segment upon creation of a segment.
  • MAXEXTENTS – number of extents allocated at a maximum to a segment – you can specify UNLIMITED.
Bigfile Tablespaces (Introduced in Oracle Ver. 10g)
A bigfile tablespace is a tablespace with a single, but very large (up to 4G blocks) datafile. Traditional smallfile tablespaces, in contrast, can contain multiple datafiles, but the files cannot be as large. Bigfile tablespaces can reduce the number of datafiles needed for a database.
  • Normal tablespaces are referred to as Smallfile tablespaces.
  • Bigfile tablespaces save space in the SGA and control file because fewer datafiles need to be tracked
To create a bigfile tablespace give the following command
SQL> CREATE BIGFILE TABLESPACE ducat DATAFILE '/u01/app/oracle/oradata/ducat/ducat01.dbf' SIZE 50G;
Extending the Size of Tablespace and Datafiles

Method #1

You can extend the size of a tablespace by increasing the size of an existing datafile by typing the following command

SQL> alter database ducat DATAFILE '/u01/app/oracle/oradata/ducat/ducat01.dbf' resize 100M;
This will increase the size from 50M to 100M

Method #2

You can also extend the size of a tablespace by adding a new datafile to a tablespace. This is useful if the size of existing datafile is reached o/s file size limit or the drive where the file is existing
does not have free space. To add a new datafile to an existing tablespace give the following command.

SQL> alter tablespace ducat add datafile '/u01/app/oracle/oradata/ducat/ducat02.dbf' size 50M;

Method #3

You can also use auto extend feature of datafile. In this, Oracle will automatically increase the size of a datafile whenever space is required. You can specify by how much size the file should increase and
Maximum size to which it should extend.
To make a existing datafile auto extendable give the following command

SQL> alter database datafile '/u01/app/oracle/oradata/ducat/ducat02.dbf' auto extend ON next 5M maxsize 500M;

You can also make a datafile auto extendable while creating a new tablespace itself by giving the following command.

SQL> create tablespace ducat datafile '/u01/app/oracle/oradata/ducat/ducat02.dbf' size 50M auto extend ON next 5M maxsize 500M;

To decrease the size of a tablespace

You can decrease the size of tablespace by decreasing the datafile associated with it. You decrease a datafile only up to size of empty space in it. To decrease the size of a datafile give the following
command

SQL> alter database datafile '/u01/app/oracle/oradata/ducat/ducat02.dbf'  resize 30M;

Coalescing Tablespaces

A free extent in a dictionary-managed tablespace is made up of a collection of contiguous free blocks. When allocating new extents to a tablespace segment, the database uses the free extent closest in size to the required extent. In some cases, when segments are dropped, their extents are deallocated and marked as free, but adjacent free extents are not immediately recombined into larger free extents. The result is fragmentation that makes allocation of larger extents more difficult.
You should often use the ALTER TABLESPACE ... COALESCE statement to manually coalesce any adjacent free extents. To Coalesce a tablespace give the following command

SQL> alter tablespace ducat coalesce;