gpt4 book ai didi

postgresql - 如何找出 Postgres 允许的最长查询字符串长度?

转载 作者:行者123 更新时间:2023-11-29 13:17:36 27 4
gpt4 key购买 nike

我发现了一些关于查询最大大小的零散信息,从 20mb 到超过 1gb 不等。

我有一个很长的查询字符串,要在表中插入大约 20 万行。在调试输出中,我看到该字符串的长度为 39759604 个字符,大小约为 38mb。

执行此查询会导致连接终止,然后数据库进入恢复模式。

如果我通过减少其中的数据来减小查询字符串的大小,查询将成功运行。

我有 16Gb 的 RAM,并且看到其中的 9 个已被使用。

这是 Postgres 日志的输出:

2017-10-13 12:51:03.110 UTC [1] LOG:  server process (PID 93) was terminated by signal 9: Killed 
2017-10-13 12:51:03.110 UTC [1] DETAIL: Failed process was running: INSERT INTO stats(...) VALUES ...
2017-10-13 12:51:03.115 UTC [1] LOG: terminating any other active server processes
2017-10-13 12:51:03.115 UTC [116] WARNING: terminating connection because of crash of another server process
2017-10-13 12:51:03.115 UTC [116] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2017-10-13 12:51:03.115 UTC [116] HINT: In a moment you should be able to reconnect to the database and repeat your command.

我如何知道在特定情况下可以使用的最大查询大小?

最佳答案

我会尝试另一种方法,而不是尝试调整语句的最大长度。如果生成语句,则可以生成 csv(或者可能已经有了)。将 csv 加载到表中比多行 INSERT 快得多。

如果您在加载数据之前需要进行一些转换,您可以COPY FROM csv 到临时辅助表,然后INSERT INTO orig SELECT transfor FROM temp。或者甚至尝试一些专为此类任务设计的工具,例如: http://pgloader.io/howto/pgloader.1.html

-l , --load-lisp-file : Specify a lisp to compile and load into the pgloader image before reading the commands, allowing to define extra transformation function. Those functions should be defined in the pgloader.transforms package. This option can appear more than once in the command line.

更新另外,回答原帖:https://dba.stackexchange.com/a/131425/30035

So a query is limited to 1 gigabyte (2^30) in size, minus 1 byte for a terminating null byte.

但我认为您会在 SQL 长度之前达到其他限制

关于postgresql - 如何找出 Postgres 允许的最长查询字符串长度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46730302/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com