Oracle:是否可以计算表数据中数据使用的实际存储大小?
我希望能够报告表格中数据使用的实际存储量,以便例如我删除 n 。然后,我可以将数据删除工作的一行(作为数据删除工作的一部分),然后可以重新分析表存储量,以计算数据删除已释放的实际存储量。
我正在使用以下查询,但已经意识到这可能是将分配的存储空间返回到单个表段,而不是实际存储空间,该存储空间正在消耗数据:
SELECT
OWNER "SCHEMA"
,SEGMENT_NAME
,SUM(BYTES) "TOTAL BYTES"
,SUM(BYTES/1024) "TOTAL KB (BINARY)"
,SUM((BYTES/1024)/1024) "TOTAL MB (BINARY)"
,ROUND(SUM(((BYTES/1024)/1024)/1024),6) "TOTAL GB (BINARY)"
FROM dba_segments
WHERE
SEGMENT_TYPE = 'TABLE'
GROUP BY
OWNER
,SEGMENT_NAME
ORDER BY
OWNER
,ROUND (SUM(((BYTES/1024)/1024)/1024),6) desc
oracle
例如,如果我从dba_tables视图中的“块”字段中获取统计数据,然后将其乘以我们分配的块大小(即8个字节),那是给我表的分配或实际数据量吗?
I want to be able to report on the actual storage volume being used by data within a table, so that if for example I then remove n. rows of data (as part of a Data Deletion piece of work), I can then re-analyse the table storage volume to calculate the actual volume of storage that has been freed up by the data removal.
I'm using the following query, but have realised that this is probably returning the allocated storage space to individual table segments, rather than the actual storage space that is being consumed by the data:
SELECT
OWNER "SCHEMA"
,SEGMENT_NAME
,SUM(BYTES) "TOTAL BYTES"
,SUM(BYTES/1024) "TOTAL KB (BINARY)"
,SUM((BYTES/1024)/1024) "TOTAL MB (BINARY)"
,ROUND(SUM(((BYTES/1024)/1024)/1024),6) "TOTAL GB (BINARY)"
FROM dba_segments
WHERE
SEGMENT_TYPE = 'TABLE'
GROUP BY
OWNER
,SEGMENT_NAME
ORDER BY
OWNER
,ROUND (SUM(((BYTES/1024)/1024)/1024),6) desc
The Oracle Database Concepts documentation is really useful, but reading through some of the other documentation available for the various static data dictionary views, it's not immediately clear to me where/what is the best basis for making the calculation I need.
For example, if I take the stat from the 'BLOCKS' field in the DBA_TABLES view, and multiply this by our allocated block size (i.e. 8 bytes), is that giving me the allocated or actual data volume for the table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想要基于 >过程。这将告诉您多少个街区,满是0-25%,满25-50%,满50-75%,并且已满75-100%,并且完全满。我在下面的脚本中使用中点估计值 - 如果您试图通过删除大量数据来确定要创建多少可用空间,则使用乐观或悲观的估计可能更有意义。您还需要针对任何索引,实现的视图等运行相同的过程,这将受到从表中删除数据的影响。
You probably want something based on the
dbms_space.space_usage
procedure. This will tell you how many blocks are 0-25% full, 25-50% full, 50-75% full, and 75-100% full, and completely full. I use the midpoint estimate in the script below-- it may make more sense for you to use an optimistic or a pessimistic estimate if you are trying to determine how much free space you are going to create by removing a lot of data. You'd also need to run the same procedure for any indexes, materialized views, etc. that would be impacted by removing data from the table.