Answer the question
In order to leave comments, you need to log in
How to quickly insert many rows in PostgreSQL?
You need to get and insert a lot of data into the database. Approximately 6-7 million lines. I'm getting it from somewhere else. Also, one column has a uniqueness index and such a line can exist. How to implement everything? A DB only for this operation. Insert and store until desired time.
Answer the question
In order to leave comments, you need to log in
If only "insert and store" - I would think, what the hell is stored in the database, if at the "right moment" you can take it from a file, or from somewhere else.
In general, the problem of fast insertion is traditionally solved in three steps - removal of the index, insertion, index overlay. In Postgre, if I remember correctly, the third step breaks into two more: adding the actual index and imposing a constraint on it. Is there something wrong with this path?
Additionally, you can greatly speed up the process if you insert several lines at a time, like
INSERT INTO table (field1, field2, field3) VALUES (value1, value2, value3), (value4, value5, value6), (value7, value8, value9)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question