- Chuyển đổi tablespace từ phân vùng /u01 sang phân vùng u02 hoặc sang phân vùng tốc độc thâp như SATA bằng cách copy datafile
- Ứng cứu phân vùng /u01 đầy 99, 100% cần chuyển 1 số datafile để tránh đầy sang phân vùng /u02
0.Kiểm tra dung lượng tablespace: 100MB
select round(sum(bytes)/1024/1024, 2) from dba_data_files where tablespace_name like 'DATA2018%' order by file_name desc;
select * from dba_data_files where tablespace_name like 'DATA2018%' order by file_name desc;
1.Read only, Offline tablespace
-- Chuyen tablespace ve che do read only
--alter tablespace DATA2018 read only;
Select 'alter tablespace ' || tablespace_name || ' read only;' from dba_tablespaces where tablespace_name like 'DATA2018';
2.Copy data file sang phân vùng mới
--cp /u01/app/oracle/oradata/orcl/data2018_001.dbf /u02/app/oracle/oradata/orcl/data2018_001.dbf
select 'cp ' || file_name || ' /u02' || substr(file_name,5,50) ||';' from dba_data_files where tablespace_name like 'DATA2018' order by file_name desc;
oracle@$ more cp_df_u02.sh
date;
cp /u01/app/oracle/oradata/orcl/data2018_001.dbf /u02/app/oracle/oradata/orcl/data2018_001.dbf;
date;
3.Offline tablespace (option)
--alter tablespace DATA2018 offline;
Select 'alter tablespace ' || tablespace_name || ' offline;' from dba_tablespaces where tablespace_name like 'DATA2018';
4.Lấy d/s cac data file cần xóa, chạy cuối cùng
--mv /u01/app/oracle/oradata/orcl/data2018_001.dbf /u01/app/oracle/oradata/orcl/data2018_001.dbf.xxx ;
select 'mv ' || file_name || ' ' ||file_name ||'.xxx ;' from dba_data_files where tablespace_name='DATA2018'
5.Rename data files sang đường dẫn mới
--alter tablespace DATA2018 rename datafile '/u01/app/oracle/oradata/orcl/data2018_001.dbf' to '/u02/app/oracle/oradata/orcl/data2018_001.dbf';
select 'alter tablespace ' || tablespace_name|| ' rename datafile ''' || file_name || ''' to ' || '''/u02' || substr(file_name,5,50) ||''';' from dba_data_files
where tablespace_name like 'DATA2018%' order by file_name desc;
6.Online, read only tablespace
--alter tablespace DATA2018 online;
Select 'alter tablespace ' || tablespace_name || ' online;' from dba_tablespaces where tablespace_name like 'DATA2018%';
7.Check 1 partition bất kỳ
--Kiểm tra danh sách file và check point time (cùng thời điểm)
--/u02/app/oracle/oradata/orcl/data2018_001.dbf 6 DATA2018 AVAILABLE 6 ONLINE 1049587 READ ONLY 1065492 1065492 06/09/2018 2:00:42 PM
select a.file_name, a.file_id, a.tablespace_name,a.status,a.relative_fno,a.online_status,
b."CREATION_CHANGE#",b.enabled,b."CHECKPOINT_CHANGE#",b."LAST_CHANGE#",b.checkpoint_time
from dba_data_files a,v$datafile b
where a.file_id=b.file#
and a.tablespace_name in ('DATA2018')
order by tablespace_name,file_name;
Select file_name, tablespace_name from dba_data_files where tablespace_name like 'DATA2018%' order by file_name desc;
select * from dba_segments where tablespace_name like 'DATA2018%' order by segment_type;
-- select du lieu tại 1 partition bất kỳ
Select * from TP1 partition(DATA20180819);
8. Xóa datafile ở đường dẫn cũ
--(Thực hiện theo bước 4)
mv /u01/app/oracle/oradata/orcl/data2018_001.dbf /u01/app/oracle/oradata/orcl/data2018_001.dbf.xxx ;
9.Read write TBS
alter tablespace DATA2018 read write;
0.Kiểm tra dung lượng tablespace: 100MB
select round(sum(bytes)/1024/1024, 2) from dba_data_files where tablespace_name like 'DATA2018%' order by file_name desc;
select * from dba_data_files where tablespace_name like 'DATA2018%' order by file_name desc;
1.Read only, Offline tablespace
-- Chuyen tablespace ve che do read only
--alter tablespace DATA2018 read only;
Select 'alter tablespace ' || tablespace_name || ' read only;' from dba_tablespaces where tablespace_name like 'DATA2018';
2.Copy data file sang phân vùng mới
--cp /u01/app/oracle/oradata/orcl/data2018_001.dbf /u02/app/oracle/oradata/orcl/data2018_001.dbf
select 'cp ' || file_name || ' /u02' || substr(file_name,5,50) ||';' from dba_data_files where tablespace_name like 'DATA2018' order by file_name desc;
oracle@$ more cp_df_u02.sh
date;
cp /u01/app/oracle/oradata/orcl/data2018_001.dbf /u02/app/oracle/oradata/orcl/data2018_001.dbf;
date;
3.Offline tablespace (option)
--alter tablespace DATA2018 offline;
Select 'alter tablespace ' || tablespace_name || ' offline;' from dba_tablespaces where tablespace_name like 'DATA2018';
4.Lấy d/s cac data file cần xóa, chạy cuối cùng
--mv /u01/app/oracle/oradata/orcl/data2018_001.dbf /u01/app/oracle/oradata/orcl/data2018_001.dbf.xxx ;
select 'mv ' || file_name || ' ' ||file_name ||'.xxx ;' from dba_data_files where tablespace_name='DATA2018'
5.Rename data files sang đường dẫn mới
--alter tablespace DATA2018 rename datafile '/u01/app/oracle/oradata/orcl/data2018_001.dbf' to '/u02/app/oracle/oradata/orcl/data2018_001.dbf';
select 'alter tablespace ' || tablespace_name|| ' rename datafile ''' || file_name || ''' to ' || '''/u02' || substr(file_name,5,50) ||''';' from dba_data_files
where tablespace_name like 'DATA2018%' order by file_name desc;
6.Online, read only tablespace
--alter tablespace DATA2018 online;
Select 'alter tablespace ' || tablespace_name || ' online;' from dba_tablespaces where tablespace_name like 'DATA2018%';
7.Check 1 partition bất kỳ
--Kiểm tra danh sách file và check point time (cùng thời điểm)
--/u02/app/oracle/oradata/orcl/data2018_001.dbf 6 DATA2018 AVAILABLE 6 ONLINE 1049587 READ ONLY 1065492 1065492 06/09/2018 2:00:42 PM
select a.file_name, a.file_id, a.tablespace_name,a.status,a.relative_fno,a.online_status,
b."CREATION_CHANGE#",b.enabled,b."CHECKPOINT_CHANGE#",b."LAST_CHANGE#",b.checkpoint_time
from dba_data_files a,v$datafile b
where a.file_id=b.file#
and a.tablespace_name in ('DATA2018')
order by tablespace_name,file_name;
Select file_name, tablespace_name from dba_data_files where tablespace_name like 'DATA2018%' order by file_name desc;
select * from dba_segments where tablespace_name like 'DATA2018%' order by segment_type;
-- select du lieu tại 1 partition bất kỳ
Select * from TP1 partition(DATA20180819);
8. Xóa datafile ở đường dẫn cũ
--(Thực hiện theo bước 4)
mv /u01/app/oracle/oradata/orcl/data2018_001.dbf /u01/app/oracle/oradata/orcl/data2018_001.dbf.xxx ;
9.Read write TBS
alter tablespace DATA2018 read write;