MySQL 计算表中BLOB列的总数据大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10648809/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:26:28  来源:igfitidea点击:

Calculating total data size of BLOB column in a table

mysqlblob

提问by jatinpreet

I have a table with large amounts of BLOB data in a column. I am writing a utility to dump the data to file system. But before dumping, I need to check if necessary space is available on the disk to export all the blob fields throughout the table.

我有一列中有大量 BLOB 数据的表。我正在编写一个实用程序来将数据转储到文件系统。但在转储之前,我需要检查磁盘上是否有必要的空间来导出整个表中的所有 blob 字段。

Please suggest an efficient approach to get size of all the blob fields in the table.

请提出一种有效的方法来获取表中所有 blob 字段的大小。

回答by Bud Damyanov

You can use the MySQL function OCTET_LENGTH(your_column_name). See herefor more details.

您可以使用 MySQL 函数OCTET_LENGTH(your_column_name)。请参阅此处了解更多详情。

回答by juergen d

select sum(length(blob_column)) as total_size 
from your_table

回答by Olofu Mark

select sum(length(blob_column_name)) from desired_tablename;

回答by voinageo

Sadly this is DB specific at best.

可悲的是,这充其量是特定于数据库的。

To get the total size of a table with blobs in Oracle I use the following: https://blog.voina.org/?p=374

要在 Oracle 中获取带有 blob 的表的总大小,我使用以下命令:https://blog.voina.org/?p =374

Sadly this does not work in DB2 I still have to find an alternative.

遗憾的是,这在 DB2 中不起作用,我仍然必须找到替代方案。

The simple

简单的

select sum(length(blob_column)) as total_size 
from your_table

is not a correct query as is not going to estimate correctly the blob size based on the reference to the blob that is stored in your blob column. You have to get the actual allocated size on disk for the blobs from the blob repository.

不是正确的查询,因为不会根据对存储在 blob 列中的 blob 的引用正确估计 blob 大小。您必须从 blob 存储库中获取 blob 在磁盘上的实际分配大小。