1. Query to get TABLE SPACES Information
Table DBA_TABLESPACES describes all tablespaces in the database.
· Tablespace Name - Name of the tablespace
· Initial Extent - Default initial extent size
· Next Extent - Default incremental extent size
· Min Extents - Default minimum number of extents
· Max Extents - Default maximum number of extents
· PCT Increase - Default percent increase for extent size
· Status - Tablespace status: ONLINE, OFFLINE, or INVALID
.
select TABLESPACE_NAME, INITIAL_EXTENT, NEXT_EXTENT, MIN_EXTENTS, MAX_EXTENTS,PCT_INCREASE,STATU
from dba_tablespacesorder by TABLESPACE_NAME
2. Query to get DATA FILES Information
Table DBA_DATA_FILES describes all data files in the database
· FILE_NAME Name of the database file along with the path
· FILE_ID File identifier number of the database file
· TABLESPACE_NAME Name of the tablespace to which the file belongs
· BYTES Size of the file in bytes
· BLOCKS Size of the file in Oracle blocks
· STATUS File status: AVAILABLE or INVALID
· AUTOEXTENSIBLE Auto extensible indicator
· MAXBYTES Maximum file size in bytes
· MAXBLOCKS Maximum file size in blocks
· INCREMENT_BY Number of tablespace blocks used as auto extension increment. Block size is contained in the BLOCK_SIZE column of the DBA_TABLESPACES view.
· USER_BYTES The size of the file available for user data. The actual size of the file minus theUSER_BYTES value is used to store file related metadata.
· ONLINE_STATUS Online status of the file:
3. Query to get DBA FREE SPACE Information
Table DBA_FREE_SPACE describes the free extents in the tablespaces accessible to the current user
· TABLESPACE_NAME Name of the tablespace containing the extent
· FILE_ID File identifier number of the file containing the extent
· BLOCK_ID Starting block number of the extent
· BYTES Size of the extent (in bytes)
· BLOCKS Size of the extent (in Oracle blocks)
4. Query to get TABLESPACE USAGE Information
·TABLESPACE_NAME - Name of the tablespace
·Bytes Used - Size of the file in bytes
·Bytes Free - Size of free space in bytes
·Largest - Largest free space in bytes
·Percent Used - Percentage of tablespace that is being used
select a.TABLESPACE_NAME, a.BYTES bytes_used, b.BYTES bytes_free, b.largest, round(((a.BYTES-b.BYTES)/a.BYTES)*100,2)||'%' percent_used
from ( select TABLESPACE_NAME, sum(BYTES) BYTES from dba_data_files group by TABLESPACE_NAME) a,
( select TABLESPACE_NAME, sum(BYTES) BYTES ,max(BYTES) largest from dba_free_space group by TABLESPACE_NAME) b where a.TABLESPACE_NAME=b.TABLESPACE_NAME
order by ((a.BYTES-b.BYTES)/a.BYTES) desc
N.B. - Above query may not display information about some Tablespace because table DBA_FREE_SPACE may not contain information of a table space, if a datafile or entire tablespace is offline in a locally managed tablespace or a tablespace is full.
If Percent Used more than 85% we have to take care of it.
5. DDL Query to increase TABLESPACE
A. Increase table space by creating a data file (*dbf) and associate with table space.
1. Find datafile storage path (one way by querying dba_data_files. FILE_NAME concern with the data file storage path)
2. Chose a unique datafile(.dbf) name that doesn’t exists in database (By querying dba_data_files)
3. Chose one TABLESPACE whose size you need to increase
4. Chose the initial size of datafile you need to create (K, M, G, and T i.e. KB, MB…….)
5. Chose either Automatically extend datafile when full (AUTOEXTEND) or not if auto extendable then what should be the increment size and what should be the max size (or UNLIMITED)
With AUTOEXTEND property
ALTER TABLESPACE "USERS" ADD DATAFILE '/Oracle/oradata/subhendu/USER05' SIZE 10GAUTOEXTEND ON NEXT 123123K MAXSIZE UNLIMITED
Without AUTOEXTEND property
ALTER TABLESPACE "USERS" ADD DATAFILE '/Oracle/oradata/subhendu/USER05' SIZE 10G
B. Increasing table space by resizing an existing data file (*dbf)
ALTER DATABASE DATAFILE '/Oracle/oradata/subhendu/USER05'
RESIZE 50G;
ALTER DATABASE DATAFILE '/Oracle/oradata/subhendu/USER05' AUTOEXTEND ON NEXT SIZE10G MAXSIZE UNLIMITED;
N.B. - Beware when decrease the size of the datafile with the space that is free between highest used block of the datafile and the last block of the file.