COLUMN TABLESPACE_NAME FORMAT A40
COLUM BYTES/1024*1024 FORMAT 999,999,999,999
SELECT FILE_NAME,TABLESPACE_NAME, BYTES/1024*1024
FROM dba_data_files
Archive Log Mode Status
/* log mode of databases */
SELECT name, log_mode FROM v$database;
Find overall size of the database
COLUMN sum(bytes)/1024/1024 FORMAT 999,999,999,999
select sum(bytes)/1024/1024 from dba_data_files;
Size of all TEMP files
select nvl(sum(bytes),0)/1024/1024 from dba_temp_files;
To shrink your current tablespaces to the HWM
select file_name,
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) smallest,
ceil( blocks*&&blksize/1024/1024) currsize,
ceil( blocks*&&blksize/1024/1024) -
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) savings
from dba_data_files a,
( select file_id, max(block_id+blocks-1) hwm
from dba_extents
group by file_id ) b
where a.file_id = b.file_id(+)
/
column cmd format a75 word_wrapped
select 'alter database datafile '''file_name''' resize '
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) 'm;' cmd
from dba_data_files a,
( select file_id, max(block_id+blocks-1) hwm
from dba_extents group by file_id ) b
where a.file_id = b.file_id(+) and
ceil( blocks*&&blksize/1024/1024) -
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) > 0
/
Moving datafiles
- Shutdown database
- Take a full cold backup (optional)
- Copy the datafiles from the existing filesystem to the new one (you can always delete the file from original filesystem later)
- Startup mount instance
- For each datafile, ALTER DATABASE RENAME
TO - ALTER DATABASE OPEN;
- ALTER DATABASE BACKUP CONTROLFILE TO TRACE; -- since we changed the database structure and must preserve it.
- Delete the file(s) from the original filesystem.
Some datafiles can be removed while the database is running, but only if they:
- Are not part of the SYSTEM tablespace
- Do not contain temporary segments
- Do not contain rollback segments
- ALTER TABLESPACE ABC OFFLINE;
- Copy the required files to the new location
- For each datafile, ALTER TABLESPACE ABC ONLINE;
- ALTER DATABASE BACKUP CONTROLFILE TO TRACE;
- Delete the file(s) from the original filesystem.
No comments:
Post a Comment