TABLESPACE MANAGEMENT
List All Tablespaces in the Database
Queries
select file_name,tablespace_name from dba_data_files;
Find the Used & free space
Script:
Reference : http://www.orafaq.com/wiki/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;
HOW TO ADD DATAFILE TO TABLESPACE
First Check if we have free space in the file system
Second add the datafile
Verify if the datafile is added.
Commands & Queries.
df -h /filesystemname
alter tablespace users add datafile '<location>' size 10m;
select file_name,tablespace_name,bytes/1024/1024 from dba_data_files where tablespace_name='USERS';
BYTES - SIZE OF THE DATAFILE
CREATE A NEW TABLESPACE
COMMANDS
create tablespace test datafile '/appl/oradata/test01.dbf' size 10m autoextend on maxsize 3000m;
select tablespace_name, max_size
from dba_tablespaces where tablespace_name='TEST';
AUTOEXTENSBILE = YES specifies the file can be extended if 10MB of space is full provided we have space in filesystem.
MAXSIZE - maximum size of the datafile
No comments:
Post a Comment