批量插入 Postgres 的最快方法是什么? [英] What's the fastest way to do a bulk insert into Postgres?

查看:35
本文介绍了批量插入 Postgres 的最快方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要以编程方式将数百万条记录中的 10 条插入 postgres 数据库.目前,我正在单个查询"中执行 1000 条插入语句.

I need to programmatically insert 10's of millions of records into a postgres database. Presently I am executing 1000's of insert statements in a single "query".

有没有更好的方法来做到这一点,一些我不知道的批量插入语句?

Is there a better way to do this, some bulk insert statement I dont know about?

推荐答案

PostgreSQL 有 关于如何最好地最初填充数据库的指南,他们建议使用 COPY 命令用于批量加载行.该指南还有其他一些关于如何加快进程的好技巧,例如在加载数据之前删除索引和外键(然后将它们添加回来).

PostgreSQL has a guide on how to best populate a database initially, and they suggest using the COPY command for bulk loading rows. The guide has some other good tips on how to speed up the process, like removing indexes and foreign keys before loading the data (and adding them back afterwards).

这篇关于批量插入 Postgres 的最快方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆