My scenario:
- 10 worker
- Database has set 100 max connections
- Every worker has its own DB connection (max. 10 connections)
- Every worker starts a transaction (BEGIN; COMMIT;)
- Every worker inserts data in the same table with bulk insert inside the transaction
- Data to insert e.g. 1 million rows
- Every worker handles 1000 rows (batches of size 1000)
The query of every worker:
BEGIN;
INSERT INTO "test_tbl" ("id",...) VALUES
(...),(...),...[1000 entries]... RETURNING id;
COMMIT;
Table test_tbl
has only constraint PRIMARY KEY (id)
with index CREATE UNIQUE INDEX formulas_pkey ON formulas USING btree (id)
Problem
After many hours of analyzing, it seams that the worker wait that another worker has finished the insert. Why the workers cannot insert new data into same table at the same time?
UPDATE
I have removed all constraints and all indices (primary keys, foreign keys, etc.) but still the same problem. No parallelization.
Added note:
- Data to insert e.g. 1 million rows
- Every worker handles 1000 rows (batches of size 1000)