postgres \copy 文件到 RDS 超时

Zha*_*eng 5 postgresql copy

Postgres 9.3 版,托管在 Amazon RDS 上。我有一个messages包含 10G 数据的表。我psql在 EC2 上使用连接了数据库。然后用

\COPY (select * from messages) TO '/tmp/messages.csv' WITH (FORMAT CSV, FORCE_QUOTE *)
Run Code Online (Sandbox Code Playgroud)

将所有消息复制到 EC2 上的文件中。

然后我尝试将文件复制回表:

\COPY messages FROM '/tmp/messages.csv' WITH (FORMAT CSV)
Run Code Online (Sandbox Code Playgroud)

大约 5 分钟后,我总是收到此错误。这个messages.csv文件大约10G。

connection not open
The connection to the server was lost. Attempting reset: Succeeded.
Run Code Online (Sandbox Code Playgroud)

我尝试了一个愚蠢的解决方案,通过将文件拆分为多个较小的主干来减少输入数据的大小。即每个 400MB。

split -l 1000000 messages.csv messages_
Run Code Online (Sandbox Code Playgroud)

这会创建多个较小的文件,每个文件 400MB。这工作正常。

但是有没有我可以更改的配置来保持大文件的连接?

我尝试设置tcp_keepalives_idle=7200andtcp_keepalives_interval=7200tcp_keepalives_count=5,但连接在 10-15 分钟后仍然丢失。