Re: PostgreSql: Canceled on conflict out to old pivot

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: "Wirch, Eduard" <eduard(dot)w(at)smart-host(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: PostgreSql: Canceled on conflict out to old pivot
Date: 2023-11-30 23:35:09
Message-ID: 590f3e4d-a561-43aa-b4a6-ee72387af275@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 30/11/2023 18:24, Wirch, Eduard wrote:
> > > The longest transaction that could occur is 1 min long.
>> I hate to drill on this, but are you very sure about that? A transaction
> in a different database?
>
> Don't be sorry for that, drilling down is important. ;) It took me so
> long to reply because I had to prepare the information carefully. You're
> right, on that day I observed the behavior, there were indeed long
> running transactions in different DBs!

A-ha! :-D

> My understanding of serializable isolation is that only transactions
> which can somehow affect each other can conflict. It should be clear
> for PostgreSql, that transactions belonging to different databases
> cannot affect each other. Why do they cause serializable conflicts?

When the system runs low on the memory reserved to track the potential
conflicts, it "summarizes" old transactions and writes them to disk. The
summarization loses a lot of information: all we actually store on disk
is the commit sequence number of the earliest "out-conflicting"
transaction. We don't store the database oid that the transaction ran in.

The whole SSI mechanism is conservative so that you can get false
serialization errors even when there is no actual problem. This is just
an extreme case of that.

Perhaps we should keep more information in the on-disk summary format.
Preserving the database OID would make a lot of sense, it would be only
4 bytes extra per transaction. But we don't preserve it today.

> If you want something visual, I prepared a SO question with similar
> content like this mail, but added an image of the tx flow:
> https://stackoverflow.com/questions/77544821/postgresql-canceled-on-conflict-out-to-old-pivot <https://stackoverflow.com/questions/77544821/postgresql-canceled-on-conflict-out-to-old-pivot>

Nice graphs!

--
Heikki Linnakangas
Neon (https://neon.tech)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2023-11-30 23:36:13 Re: Refactoring backend fork+exec code
Previous Message Tom Lane 2023-11-30 23:04:57 Re: should check collations when creating partitioned index