Re: Any way to speed up INSERT INTO

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Any way to speed up INSERT INTO
Дата
Msg-id 3967140.1646419359@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Any way to speed up INSERT INTO  (aditya desai <admad123@gmail.com>)
Ответы Re: Any way to speed up INSERT INTO  (Bruce Momjian <bruce@momjian.us>)
Re: Any way to speed up INSERT INTO  (Andres Freund <andres@anarazel.de>)
Re: Any way to speed up INSERT INTO  (aditya desai <admad123@gmail.com>)
Список pgsql-performance
aditya desai <admad123@gmail.com> writes:
> One of the service layer app is inserting Millions of records in a table
> but one row at a time. Although COPY is the fastest way to import a file in
> a table. Application has a requirement of processing a row and inserting it
> into a table. Is there any way this INSERT can be tuned by increasing
> parameters? It is taking almost 10 hours for just 2.2 million rows in a
> table. Table does not have any indexes or triggers.

Using a prepared statement for the INSERT would help a little bit.
What would help more, if you don't expect any insertion failures,
is to group multiple inserts per transaction (ie put BEGIN ... COMMIT
around each batch of 100 or 1000 or so insertions).  There's not
going to be any magic bullet that lets you get away without changing
the app, though.

It's quite possible that network round trip costs are a big chunk of your
problem, in which case physically grouping multiple rows into each INSERT
command (... or COPY ...) is the only way to fix it.  But I'd start with
trying to reduce the transaction commit overhead.

            regards, tom lane



В списке pgsql-performance по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: Any way to speed up INSERT INTO
Следующее
От: aditya desai
Дата:
Сообщение: Re: Any way to speed up INSERT INTO