zoukankan      html  css  js  c++  java
  • oracle 表空间操作

    1.oracle 查看表空间使用情况

    1)使用sysdba进入sqlplus 
    --查询表空间使用情况
    SELECT UPPER(F.TABLESPACE_NAME) "表空间名",
      D.TOT_GROOTTE_MB "表空间大小(M)",
      D.TOT_GROOTTE_MB - F.TOTAL_BYTES "已使用空间(M)",
      TO_CHAR(ROUND((D.TOT_GROOTTE_MB - F.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,2),'990.99') || '%' "使用比",
      F.TOTAL_BYTES "空闲空间(M)",
      F.MAX_BYTES "最大块(M)"
      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 1;
    --查询表空间的free space
    select tablespace_name,
      count(*) as extends,
      round(sum(bytes) / 1024 / 1024, 2) as MB,
      sum(blocks) as blocks
      from dba_free_space
      group by tablespace_name;
    --查询表空间的总容量
    select tablespace_name, sum(bytes) / 1024 / 1024 as MB
      from dba_data_files
      group by tablespace_name;
    
    --查询表空间使用率
      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;
    

    2.oracle 扩展表空间

    1 第一步:查看表空间的名字及文件所在位置:
    select tablespace_name, file_id, file_name,round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name
    
    2 第二步:增大所需表空间大小:
    alter database datafile '表空间位置'resize 新的尺寸
    例如:
    alter database datafile 'oracleoradataanita_2008.dbf' resize 4000m
    
    3 第三步:设置表空间自动扩展
    alter database datafile 'oracleoradataanita_2008.dbf' autoextend on next 100m maxsize 10000m
    
    4 查表空间下有哪些表
    select TABLE_NAME,TABLESPACE_NAME from  dba_tables where TABLESPACE_NAME like '%TBS_PORTAL%';
    
    //以具体用户进入数据库
    5. select segment_name from user_segmant where segmant_type='TBS_PORTAL';
    desc dba_segmant;
    --查看当前用户每个表占用空间的大小:
    Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents Group By Segment_Name;
    --查看每个表空间占用空间的大小:
    Select Tablespace_Name,Sum(bytes)/1024/1024 From Dba_Segments Group By Tablespace_Name
    --查看表占用的容量	
    select a.segment_name,a.BYTES /1024 /1024 as M from user_segments a where a.segment_type='TABLE' and a.TABLESPACE_NAME='TBS_PORTAL'
    order by M desc ;	
    
    select a.segment_name,a.BYTES /1024 /1024 as M 
    from user_segments a where a.segment_type='TABLE'
    order by M desc ;
    
    Select Segment_Name,Sum(bytes)/1024/1024 From User_Extents Group By Segment_Name;
    

    3.oracle 删除表空间释放空间

    SQL> alter table tb_im_req_msg enable row movement;
    Table altered.
    SQL> alter table tb_im_req_msg shrink space;
    Table altered.
    

    4.oracle UNDO表空间

    1)查看当前的undo表空间
    Show parameter undo
    Show parameter undo_tablespace
    
    2)显示数据库的所有UNDO表空间.
    SELECT tablespace_name FROM dba_tablespaces WHERE contents='UNDO';
    
    3)切换UNDO表空间.
    alter system set undo_tablespace=undotbs02 scope=both;
    
    
  • 相关阅读:
    关于android listview去掉分割线
    关于android在Service中弹出Dialog对话框
    Java SimpleDateFormat 函数
    关于Android使TextView可以滚动的设置
    关于Android(Java)创建匿名线程
    关于解决 Failed to prepare partial IU:
    毕业设计进度:2月4日
    毕业设计进度:2月3日
    毕业设计进度:2月2日
    毕业设计进度:2月1日
  • 原文地址:https://www.cnblogs.com/songjinduo/p/4672952.html
Copyright © 2011-2022 走看看