Postgres insert optimization

前端 未结 7 1621
一个人的身影
一个人的身影 2021-02-04 18:25

I have a script that generates tens of thousands of inserts into a postgres db through a custom ORM. As you can imagine, it\'s quite slow. This is used for development purpose

7条回答
  •  伪装坚强ぢ
    2021-02-04 19:11

    If you are just initializing constant test data, you could also put the test data into a staging table(s), then just copy the table contents, using

    INSERT INTO... SELECT...
    

    that should be about as fast as using COPY (though I did not benchmark it), with the advantage that you can copy using just SQL commands, without the hassle of setting up an external file like for COPY.

提交回复
热议问题