Oracle基礎 01 表空間 tablespace

j04212發表於2014-02-12

--檢視錶空間

select * from dba_tablespaces; 
select * from v$tablespace;

select * from dba_data_files; --檢視資料檔案
select * from v$datafile;

select * from dba_temp_files; --檢視臨時檔案
select * from v$tempfile;


--查預設表空間和臨時表空間

select * from database_properties
where property_name like '%TABLESPACE';

alter user scott default tablespace emp;    --修改soctt預設表空間為emp
grant unlimited tablespace to scott;        --授予scott表空間操縱許可權


--建立表空間emp

create tablespace emp                    
datafile '/u01/app/oracle/db/emp01.dbf' size 50m autoextend on next 10m maxsize unlimited; 
 

--表空間組

select * from dba_tablespace_groups;             --檢視錶空間組

alter tablespace tmp01 tablespace group group1;  --將臨時表空間tmp01新增到表空間組group1
alter tablespace tmp02 tablespace group '';      --將臨時表空間tmp02從表空間組group1中刪除


--表空間離線、線上

alter tablespace emp offline normal;         --表空間歸檔模式離線
alter tablespace emp offline normal for drop;   --表空間非歸檔模式離線(慎用)

alter tablespace emp online;           --表空間線上


--重新命名錶空間

alter tablespace tsname1 rename to tsname2;    --表空間重新命名tsname1 成tsname2


--刪除表空間

drop tablespace emp including contents and datafiles;   --刪除表空間和資料檔案


--資料檔案的移動 

alter tablespace emp offline normal;                                               --先將表空間離線

mv /u01/app/oracle/oradata/dbtest/emp_data.dbf /u01/app/oracle/datafile/           --再移動資料檔案到指定目錄(linux下) 

alter tablespace emp rename datafile'/u01/app/oracle/oradata/dbtest/emp_data.dbf'  
to '/u01/app/oracle/datafile/yd03_data.dbf';                                       --修改控制檔案資訊                                 
alter tablespace emp online;                                                       --再將表空間上線                                                


--增加資料檔案

alter tablespace emp add datafile '/u01/app/oracle/oradata/emp02.dbf'
size 10m;


--增大資料檔案

alter database datafile '/u01/app/oracle/oradata/emp01.dbf' resize 50m;


--刪除資料檔案

alter tablespace emp drop datafile '/u01/app/oracle/emp02.dbf';


--關閉資料檔案自動擴充套件

alter database datafile '/u01/app/oracle/emp01.dbf' autoextend off;

 
--檢視錶空間使用情況語句

select upper(f.tablespace_name) "ts-name",
       d.tot_grootte_mb "ts-bytes(m)",
       d.tot_grootte_mb - f.total_bytes "ts-used (m)",
       f.total_bytes "ts-free(m)",
       to_char(round((d.tot_grootte_mb - f.total_bytes) / d.tot_grootte_mb * 100,
                     2),
               '990.99') "ts-per"
         from (select tablespace_name,
               round(sum(bytes) / (1024 * 1024), 2) total_bytes,
               round(max(bytes) / (1024 * 1024), 2) max_bytes
          from sys.dba_free_space
         group by tablespace_name) f,
       (select dd.tablespace_name,
               round(sum(dd.bytes) / (1024 * 1024), 2) tot_grootte_mb
          from sys.dba_data_files dd
         group by dd.tablespace_name) d
where d.tablespace_name = f.tablespace_name
order by 5 desc;

 

SYS@ test11g> select tablespace_name,sum(bytes)/1024/1024 free_m
  2  from dba_free_space
  3  group by tablespace_name;

TABLESPACE_NAME      FREE_M
---------------- ----------
SYSAUX               35.125
UNDOTBS1                 82
USERS                  .875
SYSTEM               9.8125
EXAMPLE               21.25

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27633655/viewspace-1080292/,如需轉載,請註明出處,否則將追究法律責任。

相關文章