PostgreSQL writes several trancations into loop as one transaction with subtransactions

59 Views Asked by At

Sometimes, if database is big, PostgreSQL writes inserts in loop as a transaction with sub transactions into wal file. For example,

begin
for i in 1..10000000 loop
INSERT INTO src.customers
(id, first_name, last_name, email)
values
(i,'Mark', 'Lion', '[email protected]');
end loop;
end;

Here the upper sql sometimes is written as one big transaction with 10000000 subtransactions into wal, for example:

rmgr: Transaction len (rec/tot): 168000073/168000073, tx: 2884083787, lsn: C1/C486C9B8, prev C1/C486C870, desc: COMMIT 2024-01-17 12:43:35.646805 UTC; subxacts: 2884083788 2884083791 <many of them>

But I expected 10000000 transactions or only one transaction without subtransactions in wal file. Do you know there exists some postgresql parameter to prevent this behaviour?

0

There are 0 best solutions below