天天看點

建立删除表空間以及表空間使用情況查詢

1.1表空間建立

1.1

自己本機環境的路徑

C:\oracle\product\10.2.0\oradata\orcl

create tablespace LTSYSDATA01(表空間名)

datafile 'C:\oracle\product\10.2.0\oradata\orcl\LTSYSDATA01A.DBF' size 1024M

autoextend on next 50M maxsize unlimited logging

extent management local autoallocate

segment space management auto;

1.2修改表空間LTSYSDATA01資料檔案LTSYSDATA01KZ.DBF的大小

alter database datafile 'C:\oracle\product\10.2.0\oradata\orcl\LTSYSDATA01KZ.DBF'  resize 2g;

1.3空間單個資料檔案最大32g,擴充表空間資料檔案語句(允許自動增長):

alter tablespace LTSYSDATA01 add datafile 'C:\oracle\product\10.2.0\oradata\orcl\LTSYSDATA01KZ.DBF' size 1g autoextend on next 500M;

1.4擴充表空間的三種辦法:

1手動增加資料檔案大小

alter database datafile '/home/oracle/ts01.dbf' resize 100m;

2把表空間設定為自動擴充

alter database datafile '/home/oracle/ts01.dbf' autoextend on  next 5m maxsize   unlimited;

3 往表空間增加資料檔案

    alter tablespace ts01 add datafile '/home/oracle/ts02.dbf' size       2m;

2.表空間大小,使用情況查詢

select total.tablespace_name,

      round(total.MB, 2) as Total_MB,

       round(total.MB - free.MB, 2) as Used_MB,

       round((1 - free.MB / total.MB) * 100, 2) || '%' as Used_Pct from

       (select tablespace_name,sum(bytes) / 1024 / 1024 as MB from dba_free_space group by tablespace_name) free,

       (select tablespace_name,sum(bytes) / 1024 / 1024 as MB from dba_data_files group by tablespace_name) total

       where free.tablespace_name = total.tablespace_name  order by tablespace_name desc;

select t1.name,t2.name   --檢視表空間及資料檔案

from v$tablespace t1,v$datafile t2

where t1.ts# = t2.ts#;

SELECT FILE_NAME,TABLESPACE_NAME,AUTOEXTENSIBLE FROM dba_data_files;

3.删除表空間、删除表空間資料檔案以及删除使用者時級聯删除

  1. 删除表空間,

Drop tablespace xxx including contents

  1. 删除表空間及資料檔案

Drop tablespace xxx including contents and datafiles

  1. 删除使用者級聯删除表空間

drop user test cascade

級聯删除該使用者後該使用者對應表空間對應資料檔案使用率下降

A使用者表空間 tablespace1 資料檔案data1.dbf 使用率下降

如果這個使用者使用的表空間 tablespace 沒有其他使用者在用,則可以直接删除該表空間以及該表空 間的資料檔案來釋放空間;如果該表空間被共用,則删除該使用者後可以修改表空間對應資料檔案的大小來釋放空間,不能直接删除表空間以及表空間對用資料檔案。