将 500 万条记录导入 Rails 应用程序

发布于 2024-09-01 05:55:17 字数 165 浏览 4 评论 0原文

我们需要将大量数据(大约500万条记录)导入到rails应用程序下的postgresql数据库中。 数据将以 xml 格式提供,其中的图像采用 Base64 编码。

xml 文件的估计大小为 40GB。 什么样的 xml 解析器可以在 ruby​​ 中处理如此大量的数据?

谢谢。

We need to import large amount of data(about 5 millions records) to the postgresql db under rails application.
Data will be provided in xml format with images inside it encoded with Base64.

Estimated size of the xml file is 40GB.
What xml parser can handle such amount of data in ruby?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扛刀软妹 2024-09-08 05:55:17

您将需要使用某种SAX 解析器。 SAX 解析器不会立即将所有内容加载到内存中。

我不了解 Ruby 解析器,但快速谷歌搜索给出了这篇博文。你可以从那里开始挖掘。

您还可以尝试将 XML 文件拆分成更小的部分,以使其更完整易于管理。

You'll want to use some kind of SAX parser. SAX parsers do not load everything to memory at once.

I don't know about Ruby parsers but quick googling gave this blog post. You could start digging from there.

You could also try to split the XML file to smaller pieces to make it more manageable.

我ぃ本無心為│何有愛 2024-09-08 05:55:17

正如 Juha 所说,您应该使用 XML SAX 解析器。我认为 Libxml 是 ruby​​ 最快的 xml 库。

You should have use XML SAX parser as a Juha said. Libxml is the fastest xml lib for ruby, I think.

小红帽 2024-09-08 05:55:17

您可以将数据转换为 CSV,然后使用 DBMS CSV 加载功能将其加载到数据库中。对于 MySQL 是这样PostgreSQL 就是这个。我不会使用 Ruby 内置的任何东西来加载 40GB 的文件,它对内存来说不太好。最好留给“专业人士”。

You could convert the data to CSV and then load it into your database by using your DBMS CSV loading capabilities. For MySQL it's this and for PostgreSQL it's this. I would not use anything built in Ruby to load a 40GB file, it's not too good with memory. Best left to the "professionals".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文