Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the limit on the number of rows that can be inserted in a single insert statement with PostgreSQL 9.4?

Tags:

sql

postgresql

PostgreSQL 9.4 accepts multiple rows as values blocks in a single insert statement. What is the maximum number of rows that can be inserted this way?

like image 989
fields Avatar asked Dec 11 '15 19:12

fields


People also ask

Do we have any limit on the number of rows that can be inserted into the database?

INSERT VALUES limit is 1000, but it could be overriden with INSERT INTO SELECT FROM VALUES, as for second question in SQL world vast majority of statements are all-or-nothing.


1 Answers

It depends on how your sample "row" looks like. In general, RAM and swap of your Postgres box will be your limit before you get out-of-memory error. For bulk insert it's recommended to:

  • use COPY instead of INSERT,
  • disable indexes, replication if it takes place
  • tune database configuration settings in postgresql.conf, increase (maintenance_work_mem,checkpoint_segments)

Full list of suggestions can be found in Populating a Database article. In addition to this, Managing Kernel Resources and Resource Consumption articles are worth checking.

like image 192
Dmitry S Avatar answered Sep 25 '22 15:09

Dmitry S