将大 psql 表导出为 JSON
我如何将大表导出到 json,但输出文件超过 1Gb
copy (SELECT json_agg(export_data)::text FROM "table_name" export_data) TO '{{ path_name }}/{{ table_name }}.json' with csv quote E'\t' encoding 'UTF8'
我收到:内存不足,无法将包含 1073741822 字节的字符串缓冲区扩大 1 个字节。
表列: | |
---|---|
第一个 | uuid |
第二个 | 时间戳 |
3 个 | uuid |
4 个 | 时间戳 |
5 个 | uuid |
6 | 个int4 |
7 个 | 文本 |
8 个 | uuid |
9 个 | int4 |
10 | 个uuid |
11 个 | uuid |
12 | varchar(50) |
也许有一种方法可以按行分割输出?
how i can export big table to json, but output file is over 1Gb
copy (SELECT json_agg(export_data)::text FROM "table_name" export_data) TO '{{ path_name }}/{{ table_name }}.json' with csv quote E'\t' encoding 'UTF8'
I receive: out of memory, Cannot enlarge string buffer containing 1073741822 bytes by 1 more bytes.
Table column: | |
---|---|
First | uuid |
Second | timestamp |
Three | uuid |
Four | timestamp |
Five | uuid |
Six | int4 |
Seven | text |
Eight | uuid |
Nine | int4 |
Ten | uuid |
Eleven | uuid |
Twelve | varchar(50) |
Maybe there is a way to split the output by lines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将表分成几个部分并分别导出每个部分:
假设大小与行数成正比,并确定总行数的 n 分之一是合理的大小。然后,您可以执行如下所示的过程,并将获得 n 个结果文件:
Splitting the table into several parts and exporting each part separately :
Let's assume that the size is proportional to the number of rows and decide that one n-th of the total number of rows is a reasonnable size. You can then execute a procedure like the following one and will get n resulting files :