Re: Help understanding SIReadLock growing without bound on completed transaction

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: Mike Klaas <mike(at)superhuman(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>, Engineering-archive <engineering-archive(at)superhuman(dot)com>
Subject: Re: Help understanding SIReadLock growing without bound on completed transaction
Date: 2020-05-22 22:15:59
Message-ID: CA+hUKGKaHBNwBr5gzsRj4FubZ_Ga7-Hp6dzWxQHvXwq1RYGJsQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, May 22, 2020 at 7:48 AM Mike Klaas <mike(at)superhuman(dot)com> wrote:
> It's my understanding that these locks should be cleared when there are no conflicting transactions. These locks had existed for > 1 week and we have no transactions that last more than a few seconds (the oldest transaction in pg_stat_activity is always < 1minute old).
> Why would a transaction that is finished continue accumulating locks over time?

Predicate locks are released by ClearOldPredicateLocks(), which
releases SERIALIZABLEXACTs once they are no longer interesting. It
has a conservative idea of what is no longer interesting: it waits
until the lowest xmin across active serializable snapshots is >= the
transaction's finishedBefore xid, which was the system's next xid (an
xid that hasn't been used yet*) at the time the SERIALIZABLEXACT
committed. One implication of this scheme is that SERIALIZABLEXACTs
are cleaned up in commit order. If you somehow got into a state where
a few of them were being kept around for a long time, but others
committed later were being cleaned up (which I suppose must be the
case or your system would be complaining about running out of
SERIALIZABLEXACTs), that might imply that there is a rare leak
somewhere in this scheme. In the past I have wondered if there might
be a problem with wraparound in the xid tracking for finished
transactions, but I haven't worked out the details (transaction ID
wraparound is both figuratively and literally the Ground Hog Day of
PostgreSQL bug surfaces).

*Interestingly, it takes an unlocked view of that value, but that
doesn't seem relevant here; it could see a value that's too low, not
too high.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Suematsu 2020-05-23 08:08:20 libgeotiff missing
Previous Message David G. Johnston 2020-05-22 20:10:46 Re: query, probably needs window functions