我发现了一些关于查询的最大大小的分散信息,它在20mb到1GB之间变化。如何找出Postgres允许的最长查询字符串长度?
我有一个很长的查询字符串是在表中插入约200k行。在调试输出中,我看到字符串长度为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.
我怎么知道是什么最大查询大小我可以在特定情况下使用?
你会考虑重构查询之前打其他限制?我的意思是,它可能取决于内核设置,但也许你更好地改变方法?.. –
我尝试将每行插入查询作为单个命令运行,并且花费的时间更长。 –
所以你有'insert ... VALUES(),(),()...'大小为38 MB ?,然后生成csv,然后'COPY'将会更快更安全我相信 –