Re: SubtransControlLock and performance problems - Mailing list pgsql-performance

From Laurenz Albe
Subject Re: SubtransControlLock and performance problems
Date
Msg-id eec0413432096c46c96580a7776f13a6f27a9858.camel@cybertec.at
Whole thread Raw
In response to SubtransControlLock and performance problems  (Lars Aksel Opsahl <Lars.Opsahl@nibio.no>)
Responses Re: SubtransControlLock and performance problems  (Lars Aksel Opsahl <Lars.Opsahl@nibio.no>)
List pgsql-performance
Lars Aksel Opsahl wrote:
> What happens is that after some minutes the CPU can fall to maybe 20% usage and most of
> the threads are blocked by SubtransControlLock, and when the number SubtransControlLock
> goes down the CPU load increases again. The jobs usually goes through without any errors,
> but it takes to long time because of the SubtransControlLock blocks.

That's typically a sign that you are using more than 64 subtransactions per transaction.

That could either be SAVEPOINT SQL statements or PL/pgSQL code with blocks
containing the EXCEPTION clause.

The data structure in shared memory that holds information for each session
can cache 64 subtransactions, beyond that it has to access "pg_subtrans" to get
the required information, which leads to contention.

Often the problem is caused by a misguided attempt to wrape every single
statement in a subtransaction to emulate the behavior of other database
systems, for example with the "autosave = always" option of the JDBC driver.

The solution is to use fewer subtransactions per transaction.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com




pgsql-performance by date:

Previous
From: Tom Lane
Date:
Subject: Re: Partial index creation always scans the entire table
Next
From: Lars Aksel Opsahl
Date:
Subject: Re: SubtransControlLock and performance problems