收縮空間方法:
一.不删除資料,收縮表空間的資料檔案大小,釋放磁盤空間
查詢對應表所在的表空間
select OWNER,SEGMENT_NAME,TABLESPACE_NAME,BYTES/1024/1024 from dba_segments where segment_name=upper
('t_opt_job_process_log');
檢視表空間對應的資料檔案大小
select FILE_NAME,FILE_ID,TABLESPACE_NAME,BYTES/1024/1024 mb,BLOCKS from dba_data_files where
TABLESPACE_NAME='TFR_DATA';
檢視資料檔案中資料處在最大位置
select max(block_id) from dba_extents where file_id=9;
計算表空間實際需要多大空間
select 1354880*8/1024 from dual;
設定表空間大小為該值
ALTER DATABASE DATAFILE '/u01/oradata/FOSSDB/datafile/o1_mf_tfr_data_9ymk9p5n_.dbf' RESIZE 10600M;
二.以上方法收縮能力有限的前提下,進行删除資料收縮
删除資料有兩種方式:
(1)删除全表資料,且立即釋放空間
truncate table tfr.t_opt_job_process_log;
(2)删除部分資料,收縮表空間
delete from tfr.t_opt_job_process_log where ...;
1.把表移動至一個空間夠的表空間裡,會立即釋放删除掉的資料占用空間
alter table tfr.t_opt_job_process_log move tablespace PKP_DATA;
再将表移動回來即可(不移回來也行)
alter table tfr.t_opt_job_process_log move tablespace TFR_DATA;
2.或者使用以下指令手工釋放空間
alter table tfr.t_opt_job_process_log enable row movement;
alter table tfr.t_opt_job_process_log shrink space;
檢視表空間中表的大小
select segment_name,
tablespace_name,
bytes B,
bytes / 1024 KB,
bytes / 1024 / 1024 MB from dba_segments where segment_type = 'TABLE'
and tablespace_name = 'USERS' order by bytes desc;
檢視表空間中有哪些表
Select Table_Name, Tablespace_Name
From Dba_Tables
Where Tablespace_Name = 'TFR_DATA';
Select *
Where Tablespace_Name = 'USERS';這樣可以看到表是哪個使用者的
<a href="http://s1.51cto.com/wyfs02/M01/82/88/wKiom1dX49zCC-EuAACxPHEoBWI075.png-wh_500x0-wm_3-wmp_4-s_389008914.png" target="_blank"></a>
檢視表空間-可以檢視到表空間檔案
select b.file_name 實體檔案名,
b.tablespace_name 表空間,
b.bytes/1024/1024 大小M,
(b.bytes-sum(nvl(a.bytes,0)))/1024/1024 已使用M,
substr((b.bytes-sum(nvl(a.bytes,0)))/(b.bytes)*100,1,5) 使用率
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_name,b.bytes
order by b.tablespace_name
http://blog.csdn.net/starnight_cbj/article/details/6792364-表空間更多内容
檢視表空間-檢視每個表空間總大小和使用情況
SELECT a.tablespace_name , total / (1024 * 1024*1024 ) sizeG,
free / (1024 * 1024 *1024) freeG, (total - free) / (1024 * 1024*1024 ) UsedG,
round((total - free) / total, 4) * 100 Perc
FROM (SELECT tablespace_name, SUM(bytes) free FROM dba_free_space GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) total FROM dba_data_files GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name
order by a.tablespace_name;
--删除空的表空間,但是不包含實體檔案
drop tablespace tablespace_name;
--删除非空表空間,但是不包含實體檔案
drop tablespace tablespace_name including contents;
--删除空表空間,包含實體檔案
drop tablespace tablespace_name including datafiles;
--删除非空表空間,包含實體檔案
drop tablespace tablespace_name including contents and datafiles;
--如果其他表空間中的表有外鍵等限制關聯到了本表空間中的表的字段,就要加上CASCADE CONSTRAINTS
drop tablespace tablespace_name including contents and datafiles CASCADE CONSTRAINTS;
SELECT a.tablespace_name "表空間名",
total "表空間大小",
free "表空間剩餘大小",
(total - free) "表空間使用大小",
total / (1024 * 1024 * 1024) "表空間大小(G)",
free / (1024 * 1024 * 1024) "表空間剩餘大小(G)",
(total - free) / (1024 * 1024 * 1024) "表空間使用大小(G)",
round((total - free) / total, 4) * 100 "使用率 %"
FROM (SELECT tablespace_name, SUM(bytes) free
FROM dba_free_space
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) total
FROM dba_data_files
GROUP BY tablespace_name) b
檢視SYSTEM這個表空間是否自動增長。。
SELECT file_id, file_name, tablespace_name, autoextensible, increment_by
FROM dba_data_files
WHERE tablespace_name = 'SYSTEM'
order by file_id desc;
擴充表空間
新增加檔案
alter tablespace SYSTEM
add datafile '/usr/kingdee/oradata/smsdb/users03.dbf'
size 500M
autoextend on;
擴充已經有的檔案
alter database datafile '/usr/kingdee/oradata/smsdb/users03.dbf' resize 100000M
設定表空間自動增長
alter database datafile '/u01/oradata/FOSSDB/datafile/o2_mf_bse_data_blh6ov4m_.dbf' autoextend on;
<a href="http://s5.51cto.com/wyfs02/M00/79/8F/wKiom1aUoRjC7Eg2AABnyGWYTGo580.png" target="_blank"></a>
<a href="http://s1.51cto.com/wyfs02/M02/79/42/wKiom1aMw7TT5JovAAHJgbi84f4225.png" target="_blank"></a>
檢視某個表的大小
select G.owner,g.table_name,sum (G.sizeG) totalG
from (
select d.owner,d.segment_name,d.segment_type,d.partition_name,f.table_name,d.tablespace_name,
trunc(d.bytes/1024 /1024/ 1024,2 ) sizeG
from dba_segments d ,
(
select a.owner,a.table_name segment_name,a.table_name from dba_tables a
where a.table_name='T_SRV_WAYBILL_TEST'
union
select b.owner,b.index_name segment_name,b.table_name from dba_indexes b
where b.table_name='T_SRV_WAYBILL_TEST'
select c.owner, c.segment_name,c.table_name from dba_lobs c
where c.table_name='T_SRV_WAYBILL_TEST'
)f
where d.owner=f.owner and d.segment_name =f.segment_name
ORDER BY d.bytes DESC
)G
group by G.owner,G.table_name;
标黑的地方換成你要查詢的表的名字。
本文轉自aaa超超aaa 51CTO部落格,原文連結:http://blog.51cto.com/10983441/1770976