在 PostgreSQL 表上应用 150M 更新的最快方法是什么 [英] What is the fastest way to apply 150M updates on PostgreSQL table

查看:41
本文介绍了在 PostgreSQL 表上应用 150M 更新的最快方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 150M 行的文件,它只用这样的命令更新 postgresql 数据库的一个表:

We have a file of 150M lines which updates only one table of postgresql database with such commands:

UPDATE "events" SET "value_1" = XX, "value_2" = XX, "value_3" = XX, "value_4" = XX WHERE "events"."id" = SOME_ID;

所有 ID 都是唯一的,无法将该更新应用于多个事件.目前,如果我们在 psql 中使用 \i update.sql 运行此更新,则此类更新大约需要几天时间.

All id's are unique, there's no way to apply that update to several events. Currently such update takes approx few days if we run this with \i update.sql in psql.

有没有更快的方法来运行它?

Is there any faster way to run it?

推荐答案

  • 最简单:在\i update.sql

    更好:

    • 将文件拆分为 100000 个更新的部分:
      split -l 100000 -a 6 --additional-suffix=.sql update.sql update-part
    • 并行运行这些更新,每个文件在单个事务中,例如:
      <代码>/bin/ls 更新部分*.sql \|xargs --max-procs=8 --replace psql --single-transaction --file={}

    这篇关于在 PostgreSQL 表上应用 150M 更新的最快方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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