点击这里给我发消息 点击这里给我发消息
首页 > 行业资讯 > Oracle>详细内容

Oracle数据库维护常用SQL语句集合

添加时间:2010-1-5
    相关阅读: 数据库 SQL Oracle 维护

  空间状态相关内容

        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;


        3、求表空间的未用空间          col mbytes format 9999.9999
        SELECT Tablespace_Name, SUM(Bytes) / 1024 / 1024 Mbytes
        FROM Dba_Free_Space
        GROUP BY Tablespace_Name;


        4、察看数据库的大小,和空间使用情况          SELECT SUM(Bytes) / (1024 * 1024) AS Free_Space, Tablespace_Name
        FROM Dba_Free_Space
        GROUP BY Tablespace_Name;
        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;


        5、查看表空间的文件使用情况          SELECT b.File_Id 文件id, b.Tablespace_Name 表空间, b.File_Name 物理文件名,
        b.Bytes 总字节数, (b.Bytes - SUM(Nvl(a.Bytes, 0))) 已使用,
        SUM(Nvl(a.Bytes, 0)) 剩余,
        SUM(Nvl(a.Bytes, 0)) / (b.Bytes) * 100 剩余百分比
        FROM Dba_Free_Space a,
        Dba_Data_Files b   where a.File_Id = b.File_Id   group BY b.Tablespace_Name,
        b.File_Name, b.File_Id, b.Bytes   order BY b.Tablespace_Name   
        --/   dba_Free_Space --表空间剩余空间状况
        --   dba_Data_Files --数据文件空间占用情况


        6、 查询表空间的碎片程度         SELECT Tablespace_Name, COUNT(Tablespace_Name)
        FROM Dba_Free_Space
        GROUP BY Tablespace_Name
        HAVING COUNT(Tablespace_Name) > 10;
        alter tablespace name coalesce;
        alter table name deallocate unused;
        create or replace view ts_blocks_v as
        SELECT Tablespace_Name, Block_Id, Bytes, Blocks, 'free space' Segment_Name
        FROM Dba_Free_Space
        UNION ALL
        SELECT Tablespace_Name, Block_Id, Bytes, Blocks, Segment_Name
        FROM Dba_Extents;
        select * from ts_blocks_v;
        SELECT Tablespace_Name, SUM(Bytes), MAX(Bytes), COUNT(Block_Id)
        FROM Dba_Free_Space
        GROUP BY Tablespace_Name;

本文作者:
咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册