Re: txid_status returns NULL for recently commited transactions

From: Andres Freund <andres(at)anarazel(dot)de>
To: Michail Nikolaev <michail(dot)nikolaev(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Craig Ringer <craig(at)2ndquadrant(dot)com>, dsarafannikov(at)yandex(dot)ru
Subject: Re: txid_status returns NULL for recently commited transactions
Date: 2018-09-25 17:04:58
Message-ID: 20180925170458.ax2l4kkrg3mg6g5v@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2018-09-25 19:47:40 +0300, Michail Nikolaev wrote:
> I see strange beaviour of txid_status with one of my production servers.

What are you using it for?

> SELECT txid_status(txid_current()) -> NULL

I can't reproduce that...

> SELECT txid_current() -> 4447342811
>
> It also returns null for recent commited and aborted transactions.
>
> SELECT datname, age(datfrozenxid), datfrozenxid FROM pg_database;
> template 0239961994 4207340131
> postgres 289957756 4157344369 <(415)%20734-4369>
> template1 289957661 4157344464 <(415)%20734-4464>
> project 682347934 3764954191

"0239961994" - I can't see how a leading zero is possible.

Your mailer appears to do very annoying things by converting numbers to
phone numbers.

> GDB shows it happens because of TransactionIdPrecedes(xid,
> ShmemVariableCache->oldestClogXid)) at txid.c:155.
>
> xid_epoch = 1
> xid = 150227913
> now_epoch = 1
> now_epoch_last_xid = 150468261
> ShmemVariableCache->oldestClogXid = 2207340131 <(220)%20734-0131>
>
> The strangest thing is ShmemVariableCache->oldestClogXid == 2207340131
> <(220)%20734-0131> which is greater than current xid without an epoch
> (150227913) .

It's from the last epoch. Plain xids are 32bit wide, the epochs deal
with values that are bigger. And 2207340131 is less than 2^31 in the
past.

> Postgres was updated from 9.6 to PostgreSQL 10.4 (Ubuntu
> 10.4-2.pgdg14.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu
> 4.8.4-2ubuntu1~14.04.4) 4.8.4, 64-bit.
>
> Also, another small issue:
>
> On the same database:
> SELECT txid_status(BIGINT '4294967295') -> 'commited'.
> SELECT txid_status(BIGINT '4294967296') -> NULL
>
> Both tx ids are from my head and not valid.
> First 'commited' happends because int32 overflow:
> TransactionIdPrecedes(59856482, 2207340131 <(220)%20734-0131>) == false

Why do you think that is the wrong result?

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michail Nikolaev 2018-09-25 19:22:36 Re: txid_status returns NULL for recently commited transactions
Previous Message Michail Nikolaev 2018-09-25 16:52:55 Re: txid_status returns NULL for recently commited transactions