Frequently used Tablespace and datafile commands

Oracle database is divided into one are more logical storage unit called tablespace 

Tablespaces are divided into logical unit of storage called segments

Segments are divided into Extents

Extents are a collection of blocks

Tablespace Types:

  1. System tablespace
  2. Sysaux tablespace
  3. Temp tablespace
  4. Undo tablespace 

System tablespace

  •           System tablespace is first tablespace created at db creation
  •           It’s required all databases
  •           It’s containing data dictionary and the system rollback segments

Sysaux tablespace

  • Sysaux tablespace store the non-sys-related tables and indexes
  • It’s contains all performance related operations like awr,ash report generation

 

Temp tablespace

  • Temp tablespace are used to store the data with sorting operations
  • Can’t contain any permanent objects
  • Temp tbs need to create special type of keywords

EX:

          Create Temporary tablespace <tbs_name> TEMPFILE <location> size 100m;

Undo tablespace

  • Undo tablespace are used to store before image
  • Data can be used to undo transaction

         

TABLESPCE Views:-

DBA_TABLESPACE

V$TABLESPACE 

DATAFILE Views

DBA_DATA_FILES

V$DATAFILE

TEMP FILE Views

DBA_TEMP_FILES

V$TEMPFILE


Maximum Datafile size for SMALL File normal table space

DB Block Size

Maximum Data file Size

2k

4194303 *2k Block Size=8GB

4k

4194303 *4k Block Size=16GB

8k

4194303 *8k Block Size=32GB

16k

4194303 *16k Block Size=64GB

32k

4194303 *22k Block Size=128GB

 

Maximum Datafile size for BIG File normal table space

DB Block Size

Maximum Data file Size

2k

4194303 *2k Block Size=8 TB

4k

4194303 *4k Block Size=16 TB

8k

4194303 *8k Block Size=32 TB

16k

4194303 *16k Block Size=64 TB

32k

4194303 *22k Block Size=128 TB

  

Check BLOCK_SIZE


SQL> show parameter DB_BLOCK_SIZE;

 NAME                                         TYPE          VALUE

------------------------------------------------------------------

db_block_size                              integer         8192

 

Create Tablespace:-

SQL> Create tablespace JIO datafile'/u01/oracle/DEV/db/data/test01.dbf' size 100m;

(O/P) 

Tablespace created.

Create tablespace with Extra parameters:-

SQL> Create tablespace AIRTEL  datafile '/u01/oracle/DEV/db/data/test201.dbf' size 100m 

autoextend on

next 512k

maxsize 500m; 

(O/P)

Tablespace created.

 

Add new datafile :-

SQL> Alter tablespace JIO

          add datafile'/u01/oracle/JIO/db/data/test02.dbf'

          size 50m;

(O/P)

Tablespace altered.

How to Check datafile size

select file_name,sum(bytes)/1024/1024 from dba_data_files where tablespace_name='< tablespace_name >' group by file_name;

SELECT FILE#, STATUS, ENABLED, CHECKPOINT_CHANGE#, BYTES, CREATE_BYTES, NAME FROM V$DATAFILE;

Manually Resizing a Datafile

SQL> Alter database

     datafile '/u01/oracle/DEV/db/data/test02.dbf'

     resize 500m;

(O/P)

Database altered.

Rename Tablespace

SQL> Alter tablespace test2 rename to testdbf;

(O/P)

Tablespace altered.

Drop tablespace

SQL> DROP TABLESPACE TEST

INCLUDING CONTENTS AND DATAFILES; 

(O/P) 

Tablespace dropped.

Drop specific datafile from tablespace:-

SQL> Alter tablespace test

    drop datafile '/u01/oracle/DEV/db/data/test02.dbf';

(O/P)

Tablespace altered.

Assign user in particular tablespace:-

 SQL> create user HDFC identified by HDFC      

          default tablespace test;

(O/P)

User created.

Take tablespace Offline:-

 SQL> alter tablespace testtbs offline;

(O/P)

Tablespace altered.

Take tablespace ONLINE:-

 SQL>  alter tablespace testtbs online;

(O/P)

Tablespace altered.

Check datafile status online (or) offline

SQL> select file#,status from v$datafile;

How to check free and used space per tablespace:

 

SELECT /* + RULE */ df.tablespace_name "Tablespace",

df.bytes / (1024 * 1024) "Size (MB)",

SUM(fs.bytes) / (1024 * 1024) "Free (MB)",

Nvl(Round(SUM(fs.bytes) * 100 / df.bytes),1) "% Free",

Round((df.bytes - SUM(fs.bytes)) * 100 / df.bytes) "% Used"

FROM dba_free_space fs,

(SELECT tablespace_name,SUM(bytes) bytes

FROM dba_data_files

GROUP BY tablespace_name) df

WHERE fs.tablespace_name (+) = df.tablespace_name

GROUP BY df.tablespace_name,df.bytes

UNION ALL

SELECT /* + RULE */ df.tablespace_name tspace,

fs.bytes / (1024 * 1024),

SUM(df.bytes_free) / (1024 * 1024),

Nvl(Round((SUM(fs.bytes) - df.bytes_used) * 100 / fs.bytes), 1),

Round((SUM(fs.bytes) - df.bytes_free) * 100 / fs.bytes)

FROM dba_temp_files fs,

(SELECT tablespace_name,bytes_free,bytes_used

FROM v$temp_space_header

GROUP BY tablespace_name,bytes_free,bytes_used) df

WHERE fs.tablespace_name (+) = df.tablespace_name

GROUP BY df.tablespace_name,fs.bytes,df.bytes_free,df.bytes_used

ORDER BY 4 DESC;

 

 

 

 

Check free and used space particular tablespace:

 

SQL> select a. tablespace_name, 

sum(a.tots)/1024/1024 "Total Size (MB)", 

Sum(a.sumb)/1024/1024 "Total Free (MB)",

sum(a.sumb)*100/sum(a.tots) "% Free", 

Sum(a.tots-a.sumb)*100/sum(a.tots) "% Used", 

sum(a.largest)/1024/1024 "Max Free" 

From 

(

select tablespace_name, 0 tots, 

sum(bytes) sumb, max(bytes) largest 

From dba_free_space a 

group by tablespace_name 

union

select tablespace_name, sum(bytes) tots, 

0,0

from dba_data_files 

group by tablespace_name) a where a.tablespace_name = '&Tablespace_Name' 

group by a.tablespace_name;

Enter value for tablespace name:

old 22: where a.tablespace_name=&Tablespace_Name":

new 22: where a.tablespace_name =

 

 

SQL>set pages 999 lines 100

Col "Tablespace" for a50

Col "Size MB" for 999999999

Col "%Used" for 999

Col "Add (78%)" for 999999

select tsu.tablespace_name "Tablespace",

ceil(tsu.used_mb) "Size MB",

100-floor(tsf.free_mb/tsu.used_mb*100) "%Used",

ceil((tsu.used_mb - tsf.free_mb) / .78) - tsu.used_mb "Add (78%)"

from 

(select tablespace_name, 

sum(bytes)/1024/1024 used_mb

from dba_data_files 

group by tablespace_name) tsu, 

(select ts.tablespace_name,

nvl(sum(bytes)/1024/1024, 0) free_mb

from dba_tablespaces ts, dba_free_space fs

where ts.tablespace_name = fs.tablespace_name (+)

group by ts.tablespace_name) tsf

where tsu.tablespace_name = tsf.tablespace_name (+) and 100 - floor(tsf.free_mb/tsu.used_mb*100) >- 78

and tsf.tablespace_name='&TS'

order by 3,4


Enter value for ts:

old 14: and tsf.tablespace_name"&TS

new 14: and tsf.tablespace_name=

 

 

 

Comments

Popular posts from this blog

How to troubleshoot long running concurrent request in R12.2

How to run Gather Schema Statistics in R12.2

How to compile forms in R12.2