zoukankan      html  css  js  c++  java
  • oracle查看表空间和物理文件大小

    查看各表空间的使用情况
    
    select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",
        round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"
        from
        (select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
        (select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
        where a.tablespace_name=b.tablespace_name
        order by ((a.bytes-b.bytes)/a.bytes) desc
    select * from dba_data_files
    order by tablespace_name, file_name;

    select tablespace_name,dba_tablespaces.* from dba_tablespaces

    表真实占用的空间

    select OWNER, t.segment_name, t.segment_type,  
    sum(t.bytes / 1024 / 1024/1024) USED_G
    from dba_segments t
    where t.owner LIKE '%ODS%'
    AND SEGMENT_NAME NOT LIKE 'BIN$%'
    group by OWNER, t.segment_name, t.segment_type
    order by OWNER, USED_G desc;

     

    --1、查看表空间的名称及大小   
    select   t.tablespace_name,   round(sum(bytes/(1024*1024)),0)   ts_size   
    from   dba_tablespaces   t,   dba_data_files   d   
    where   t.tablespace_name   =   d.tablespace_name   
    group   by   t.tablespace_name;   
    --2、查看表空间物理文件的名称及大小   
    select   tablespace_name,   file_id,   file_name,   
    round(bytes/(1024*1024),0)   total_space   
    from   dba_data_files   
    order   by   tablespace_name;   
    alter tablespace {表空间名字} add datafile '物理数据文件路径' SIZE 『初始大小M』 AUTOEXTEND ON NEXT 『自动扩展大小M』
    
    alter tablespace SDK_TB add datafile '/oradata/ORA11G/sdk_tb2.dbf' size 1000m autoextend on next 200m

     如果datafile加错到表空间,执行删除

    Alter tablespace SDK_TB drop datafile '/oradata/ORA11G/a_tb04.dbf';
    或者
    alter database datafile '/oradata/ORA11G/a_tb04.dbf' offline drop;

    查看临时表空间

    select * from dba_temp_files
    where tablespace_name = 'DEV_TEMP2'
    order by tablespace_name, file_name; 

    添加临时表空间文件

    alter tablespace  DEV_TEMP2 add tempfile '/data/phonedb/datafile/dev_temp3.dbf' size 1000m autoextend on next 200m

    修改用户默认表空间

    alter user user_name default tablespace dev_tb;
    alter user user_name temporary tablespace  dev_temp;

    查看数据文件是否有数据:

    只需查看数据文件中是否包含extent段。如果有extent(索引段,数据段)段,则说明数据文件中有数据。
    使用dba_extents视图和dba_data_files视图进行连接查询。

    select t.file_name,t1.owner,t1.segment_name,t1.segment_type,t1.tablespace_name from dba_data_files t,dba_extents t1 where t.file_id=t1.file_id and file_name='你要查询的数据文件路径';
  • 相关阅读:
    小心SQL SERVER 2014新特性——基数评估引起一些性能问题
    SQL SERVER使用ODBC 驱动建立的链接服务器调用存储过程时参数不能为NULL值
    Windows Server 2012 Recycle Bin corrupted
    SQL SERVER CHAR ( integer_expression )各版本返回值差异的案例
    SQL Server 2008 R2 升级到 Service Pack 3后Report Builder启动不了
    MySQL如何导出带日期格式的文件
    ORACLE TO_CHAR函数格式化数字的出现空格的原因
    Linux监控工具介绍系列——smem
    Linux命令学习总结:dos2unix
    Linux命令学习总结:hexdump
  • 原文地址:https://www.cnblogs.com/linn/p/4422024.html
Copyright © 2011-2022 走看看