From: Andres Freund <andres@anarazel.de>
To: Mariel Cherkassky <mariel.cherkassky@gmail.com>
Cc: pgsql-admin@lists.postgresql.org
Subject: Re: unclear behavior xmax/xmin
Date: Sun, 18 Nov 2018 12:23:59 -0800
Message-ID: <20181118202359.6cwmsig3jsvzxm2x@alap3.anarazel.de> (raw)
In-Reply-To: <CA+t6e1mvt0Fw-d2_vgKHBO=Wn-yFinAq7DTDjC-wbfD=+mmjCA@mail.gmail.com>
References: <CA+t6e1mvt0Fw-d2_vgKHBO=Wn-yFinAq7DTDjC-wbfD=+mmjCA@mail.gmail.com>
Hi,
On 2018-11-18 19:13:28 +0200, Mariel Cherkassky wrote:
> - I started transaction A and deleted one row but I didnt commit.
> Afterwards I rolledback the transaction but the xmax of the row was set to
> the txid of transaction A. I opened a new session and run VACUUM on the
> table. However, that record wasnt deleted but the xmax was still set to
> transaction`s A txid. Is that a bug ?
No. A vacuum will not necessarily immeditely process a row/page if has
recently been modified.
> the vacuum process shouldnt delete
> that row because it has an old xmax (there arent any younger transactions).
> In addition, I'm still capable of seeing the record (because of the
> rollback..) but my txid is bigger then the xmax of the record. ? Is that a
> bug ?
No, it's not. For visiblity checks it's not just the xid that counts,
but also whether this xid committed.
bool
HeapTupleSatisfiesMVCC(HeapTuple htup, Snapshot snapshot,
Buffer buffer)
...
if (!(tuple->t_infomask & HEAP_XMAX_COMMITTED))
{
if (TransactionIdIsCurrentTransactionId(HeapTupleHeaderGetRawXmax(tuple)))
{
if (HeapTupleHeaderGetCmax(tuple) >= snapshot->curcid)
return true; /* deleted after scan started */
else
return false; /* deleted before scan started */
}
if (XidInMVCCSnapshot(HeapTupleHeaderGetRawXmax(tuple), snapshot))
return true;
if (!TransactionIdDidCommit(HeapTupleHeaderGetRawXmax(tuple)))
{
/* it must have aborted or crashed */
SetHintBits(tuple, buffer, HEAP_XMAX_INVALID,
InvalidTransactionId);
return true;
}
> -When I run an update basically its just like running an insert and delete
> (the xmax of the old row is changed to the transaction`s txid and the new
> row contains xmin same as txid of the current transaction and xmax is set
> to 0). However, when I query the table (didnt commit yet) I dont see the
> old record. Is there a way to see it ? Why is that ? I thought that I
> should see the table with a non zero value in the xmax col.
You can use the pageinspect extension to see such rows. We can't
normally show such rows, because it'd violate transactional semantics.
What are you trying to achieve? Just exploring the system?
Greetings,
Andres Freund
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: andres@anarazel.de, mariel.cherkassky@gmail.com
Subject: Re: unclear behavior xmax/xmin
In-Reply-To: <20181118202359.6cwmsig3jsvzxm2x@alap3.anarazel.de>
References: <CA+t6e1mvt0Fw-d2_vgKHBO=Wn-yFinAq7DTDjC-wbfD=+mmjCA@mail.gmail.com> <20181118202359.6cwmsig3jsvzxm2x@alap3.anarazel.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox