Listen Software’s How To: Tablespaces

Adding a datafile

Indented lines in the following example are intended to be continuations of the lines above them. The lines are wrapped here for page formatting purposes. -Ed.

alter tablespace 
   user_data
add datafile 
   'e:{sid}datausr2.dbf' 
   size 30M;

Autoextend

alter tablespace user_data autoextend off;

Next and Maxsize are set to zero.

alter tablespace user_data
add datafile 'e:{sid}datausr2.dbf';

alter tablespace user_data autoextend on max_size=40M;

Sets the maximum disk space allowed for automatic extension of the datafile.

Taking the Tablespace Online and Offline

Online

alter tablespace user_data online;

Offline

alter tablespace user_data offline;

Hot Backup of a Tablespace

alter tablespace user_data begin backup;

alter tablespace user_data end backup;

This option does not prevent user from performing transactions.

Tablespace Coalese

alter tablespace user_data coalesce;

Coalesing gathers free segments. SMON usual cleans up free space.

Calculate Tablespace Size for Multiple Datafiles

Tablespace Byte Size
1 tablespace – multiple datafiles

Contribution by Stephen Mitchell

SELECT dfs.tablespace_name tablespace_name,
ddf.total_size total_size,
ddf.total_size - dfs.total_free total_used,
dfs.total_free total_free,
(ddf.total_size - dfs.total_free) / ddf.total_size * 100 cap,
dfs.total_chunks total_chunks,
dfs.largest_chunk largest_chunk
FROM (SELECT a.tablespace_name,
      SUM(a.bytes) / 1024 / 1024 total_free,
      COUNT(a.bytes) total_chunks,
      MAX(a.bytes) / 1024 / 1024 largest_chunk
      FROM dba_free_space a
      GROUP BY a.tablespace_name) dfs,
     (SELECT b.tablespace_name,
      SUM(b.bytes) / 1024 / 1024 total_size
      FROM dba_data_files b
      GROUP BY b.tablespace_name) ddf
WHERE dfs.tablespace_name = ddf.tablespace_name
ORDER BY dfs.tablespace_name

Get the Free Newsletter!

Subscribe to Cloud Insider for top news, trends & analysis

Latest Articles