一.問題描述

表空間 Users的97 percent已滿.
表空間 TSP_EMR的85 percent已滿.
表空間 TSP_OUTPADM的85 percent已滿.
二.問題分析
以Users表空間為例,其他類似
USERS表空間是預設使用者表空間,在建立一個使用者并沒有指定此使用者使用表空間時,該使用者所有資訊都會放入到users表空間中,使用查詢表空間語句:
select file_name,tablespace_name,bytes/1024/1024 "bytes MB",maxbytes/1024/1024 "maxbytes MB"
from dba_data_files
where tablespace_name='USERS';
查詢users表空間,發現已占滿 , 使用sql:
select t.TABLE_NAME,t.NUM_ROWS
from all_tables t
where tablespace_name='USERS' order by num_rows desc;
查詢使用USERS表空間的表,按行級降序排序,發現多個表使用USERS表空間,存在大量資料導緻USER表占滿.
三.問題處理
1、擴充表空間:
alter datafile ‘/oracle_data/orcl/users02.dbf’ resize 30G;
2、擴充到最大30G(最大)檔案無法繼續擴充,可增加資料檔案:
alter tablespace users add datafile '/oracle_data/orcl/users27.dbf'
size 1024m autoextend on next 1024m maxsize 30G;
3、truncate删除無用表釋放空間
假如未釋放,對TEST表進行收縮shrink,執行下面三個語句:
啟用行遷移:alter table TEST enable row movement;
shrink表test:alter TABLE TEST shrink SPACE;
關閉行遷移:alter table TEST DISABLE row movement;
注:資料被删除後(無論是 delete 還是 truncate table),資料檔案大小不會縮小, Oracle “高水位”所緻(可以具體了解),想要降低資料檔案大小需降低高水位的正确做法是先降低HWM,再确定實際占有大小,再resize資料檔案,執行如下4個語句:
(1)查詢表空間檔案編号:
select file#, name from v$datafile;
(2)根據檔案 ID 查詢這個資料檔案最大資料塊(data block)的編号:select max(block_id) from dba_extents where file_id=4;
(3)計算該表空間實際占用的空間,先查詢資料塊大小: select value from v$parameter where name='db_block_size',咱預設是8192.
(4)計算實際占用磁盤大小: select 65673 * 8 / 1024 from dual;
(5)把資料檔案大小resize到比實際占用磁盤大小大一些就行了:
alter database datafile '/oracle/oradata/dbaxj/users01.dbf' resize 600m;
這樣資料檔案大小就變小了,節約空間
4、需要使用的表,修改表空間
alter table USSD_UNREPORT_FAIL move tablespace new_tablespace
建表時需養成習慣,指定好表空間
參考:https://blog.csdn.net/u013050593/article/details/77160693