【问题标题】:Calculate the size of a table in a schema计算模式中表的大小
【发布时间】:2016-02-26 00:59:02
【问题描述】:

我正在尝试在我的架构中查找表的大小。我尝试通过 dba_extent 查找如下。

select segment_name,sum(bytes)/(1024*1024) size from  dba_extent where segment_type='TABLE'
and segment_name = 'mytablename'
and owner ='myschemaname'
group by segment_name;

它给出的大小为 2 MB,但绝不可能是 2MB,而且我在导出模式时在日志中看到它的大小约为 800MB。当我查询 dba_segments 时,它给出了相同的结果。谁能帮我解决我出错的地方。感谢您的宝贵时间。

【问题讨论】:

  • 哪些日志告诉您该表更大?表中是否有可能有一个不同的段名称的 LOB?
  • 是的,它有blob,我不知道它是否使用其他segment,我怎么知道
  • @JustinCave,它正在使用另一个段。谢谢
  • Possible duplicate?来自另一边但足够相关?

标签: sql oracle


【解决方案1】:

试试下面的 SQL:希望这会有所帮助:)

SELECT 
tbl.NAME AS TableName,
idx.name as indexName,
prts.[Rows],
sum(a.total_pages) as TotalPages, 
sum(a.used_pages) as UsedPages, 
sum(a.data_pages) as DataPages,
(sum(a.total_pages) * 8) / 1024 as TotalSpaceMB, 
(sum(a.used_pages) * 8) / 1024 as UsedSpaceMB, 
(sum(a.data_pages) * 8) / 1024 as DataSpaceMB
FROM 
sys.tables tbl
INNER JOIN 
sys.indexes idx ON tbl.OBJECT_ID = idx.object_id
INNER JOIN 
sys.partitions prts ON idx.object_id = prts.OBJECT_ID AND idx.index_id = prts.index_id
INNER JOIN 
sys.allocation_units a ON prts.partition_id = a.container_id
WHERE 
tbl.NAME NOT LIKE 'dt%' AND
idx.OBJECT_ID > 255 AND 
idx.index_id <= 1
GROUP BY 
tbl.NAME, idx.object_id, idx.index_id, idx.name, prts.[Rows]
ORDER BY 
object_name(idx.object_id)

【讨论】:

  • 以上 SQL 在 SQL-2008 中对我来说工作正常,你在哪个 DB 中尝试?
  • oracle 没有 allocation_units 表,我收到表不存在错误,我正在使用 10g
  • 哦,好吧。以上 SQL 仅适用于 MS-SQL Server。不适用于甲骨文。
  • 问题被标记为oracle
  • 尝试:select segment_name,segment_type,bytes/1024/1024 MB from dba_segments where segment_type='TABLE' and segment_name='';
猜你喜欢
  • 2021-08-25
  • 2014-07-28
  • 2013-04-25
  • 1970-01-01
  • 1970-01-01
  • 2021-01-02
  • 2016-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多