存档

2012年10月19日 的存档,文章数:1

统计Sybase ASE数据库的数据段和日志段的剩余空间以及剩余率。以下SQL在ASE12.5.1及以上版本通过测试。

 

select convert(char(16),db_name(data_segment.dbid)) DBName
,str(round(total_data_pages / ((1024.0 * 1024) / @@maxpagesize),2),10,2) "Total Data(MB)"
,str(round(free_data_pages / ((1024.0 * 1024) / @@maxpagesize),2),10,2) "Free Data(MB)"
,str(round(total_log_pages / ((1024.0 * 1024) / @@maxpagesize),2),10,2) "Total Log(MB)"
,str(round(free_log_pages / ((1024.0 * 1024) / @@maxpagesize),2),10,2) "Free Log(MB)"
,str( round(100.0 * free_data_pages / total_data_pages ,2),10,2) "Free_Data%"
,str( round(100.0 * free_log_pages / total_log_pages,2),10,2) "Free_Log%"
from
(select dbid,sum(size) total_log_pages,lct_admin("logsegment_freepages", dbid ) free_log_pages
  from master.dbo.sysusages
    where segmap & 4 = 4
    group by dbid
) log_segment
,
(select dbid,sum(size) total_data_pages ,sum(curunreservedpgs(dbid, lstart, unreservedpgs)) free_data_pages
  from master.dbo.sysusages
    where segmap <> 4
    group by dbid
) data_segment
where data_segment.dbid = log_segment.dbid
  --and data_segment.dbid > 3 and data_segment.dbid < 31513
order by data_segment.dbid
go