ITPub博客

首页 > Linux操作系统 > Linux操作系统 > oracle表空间日常操作管理

oracle表空间日常操作管理

原创 Linux操作系统 作者:85579711 时间:2013-08-20 08:47:38 0 删除 编辑
建立表空间
  CREATE TABLESPACE data01
  DATAFILE ‘/oracle/oradata/db/DATA01.dbf‘ SIZE 500M
  UNIFORM. SIZE 128k; #指定区尺寸为128k,如不指定,区尺寸默认为64k
  删除表空间
  DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;
  一、建立表空间
  CREATE TABLESPACE data01
  DATAFILE ‘/oracle/oradata/db/DATA01.dbf‘ SIZE 500M
  UNIFORM. SIZE 128k; #指定区尺寸为128k,如不指定,区尺寸默认为64k
  二、建立UNDO表空间
  CREATE UNDO TABLESPACE UNDOTBS02
  DATAFILE ‘/oracle/oradata/db/UNDOTBS02.dbf‘ SIZE 50M
  #注意:在OPEN状态下某些时刻只能用一个UNDO表空间,如果要用新建的表空间,必须切换到该表空间:
  ALTER SYSTEM SET undo_tablespace=UNDOTBS02;
  三、建立临时表空间
  CREATE TEMPORARY TABLESPACE temp_data
  TEMPFILE ‘/oracle/oradata/db/TEMP_DATA.dbf‘ SIZE 50M
  四、改变表空间状态
  1.使表空间脱机
  ALTER TABLESPACE game OFFLINE;
  如果是意外删除了数据文件,则必须带有RECOVER选项
  ALTER TABLESPACE game OFFLINE FOR RECOVER;
  2.使表空间联机
  ALTER TABLESPACE game ONLINE;
  3.使数据文件脱机
  ALTER DATABASE DATAFILE 3 OFFLINE;
  4.使数据文件联机
  ALTER DATABASE DATAFILE 3 ONLINE;
  5.使表空间只读
  ALTER TABLESPACE game READ ONLY;
  6.使表空间可读写
  ALTER TABLESPACE game READ WRITE;
  五、删除表空间
  DROP TABLESPACE data01 INCLUDING CONTENTS AND DATAFILES;
  六、扩展表空间
  首先查看表空间的名字和所属文件
  select tablespace_name, file_id, file_name,
  round(bytes/(1024*1024),0) total_space
  from dba_data_files
  order by tablespace_name;
  1.增加数据文件
  ALTER TABLESPACE game
  ADD DATAFILE ‘/oracle/oradata/db/GAME02.dbf‘ SIZE 1000M;
  2.手动增加数据文件尺寸
  ALTER DATABASE DATAFILE ‘/oracle/oradata/db/GAME.dbf‘
  RESIZE 4000M;
   3.删除表空间的一个数据文件
     alter tablspace XXXX offline;
      alter database datafile '......' drop including datafile;
      alter tablespace xxx online;
  4.设定数据文件自动扩展
  ALTER DATABASE DATAFILE ‘/oracle/oradata/db/GAME.dbf
  AUTOEXTEND ON NEXT 100M
  MAXSIZE 10000M;
  设定后查看表空间信息
  SELECT A.TABLESPACE_NAME,A.BYTES TOTAL,B.BYTES USED, C.BYTES FREE,
  (B.BYTES*100)/A.BYTES "% USED",(C.BYTES*100)/A.BYTES "% FREE"
  FROM SYS.SM$TS_AVAIL A,SYS.SM$TS_USED B,SYS.SM$TS_FREE C
  WHERE A.TABLESPACE_NAME=B.TABLESPACE_NAME AND A.TABLESPACE_NAME=C.TABLESPACE_NAME;
查询表空间相关信息的SQL:
1.查看表空间及文件大小(含undo表空间)
set linesize 300
set pagesize 500
col file_name format a80
col TABLESPACE_NAME for a30
select tablespace_name,file_id,status,bytes/1024/1024 FileSizeM,file_name
from dba_data_files order by tablespace_name;
 
2.查看表空间大小及利用率
set linesize 200
set pages 2000
col TABLESPACENAME for a30
select substr(a.TABLESPACE_NAME,1,15) TablespaceName,
sum(a.bytes/1024/1024) as "Totle_size(M)",
sum(nvl(b.free_space1/1024/1024,0)) as "Free_space(M)",
sum(a.bytes/1024/1024)-sum(nvl(b.free_space1/1024/1024,0)) as "Used_space(M)",
round((sum(a.bytes/1024/1024)-sum(nvl(b.free_space1/1024/1024,0)))
*100/sum(a.bytes/1024/1024),2) as "Used_percent%" from dba_data_files a,
(select sum(nvl(bytes,0)) free_space1,file_id from dba_free_space
group by file_id) b where a.file_id = b.file_id(+) group by a.TABLESPACE_NAME
order by "Used_percent%";
3.查看临时表空间对应的文件名和大小
col file_name for a50
col TABLESPACE_NAME for a20
select FILE_NAME,TABLESPACE_NAME,BYTES,USER_BYTES from dba_temp_files;
 
4.查看临时表空间对应的文件名和大小
4-1
set lines 200
set pages 2000
SELECT D.TABLESPACE_NAME,SPACE "SUM_SPACE(M)",BLOCKS SUM_BLOCKS,
USED_SPACE "USED_SPACE(M)",ROUND(NVL(USED_SPACE,0)/SPACE*100,2) "USED_RATE(%)",
NVL(FREE_SPACE,0) "FREE_SPACE(M)"
FROM (SELECT TABLESPACE_NAME,ROUND(SUM(BYTES)/(1024*1024),2) SPACE,SUM(BLOCKS) BLOCKS
FROM DBA_TEMP_FILES GROUP BY TABLESPACE_NAME) D,
(SELECT TABLESPACE_NAME,ROUND(SUM(BYTES_USED)/(1024*1024),2)
USED_SPACE,ROUND(SUM(BYTES_FREE)/(1024*1024),2) FREE_SPACE FROM V$TEMP_SPACE_HEADER
GROUP BY TABLESPACE_NAME) F WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+);
 
4-2
set lines 200
set pages 2000
select tablespace_name, file_id, bytes_used, bytes_free from v$temp_space_header ;
 
5.查看用户所使用的临时表空间
select username,default_tablespace,temporary_tablespace from dba_users;
6,system表空间扩充
alter database datafile'/opt/app/oracle/oradata/eomshn/system01.dbf'autoextend on;
alter database datafile'/opt/app/oracle/oradata/eomshn/system01.dbf'resize 1024M;

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29063131/viewspace-768835/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-07-22

  • 博文量
    39
  • 访问量
    99462