LocalTransactionId vs txid_current

Started by Luca Ferrariover 6 years ago2 messagesgeneral
Jump to latest
#1Luca Ferrari
fluca1978@gmail.com

I'm exploring DTrace, and I thought that LocalTransactionId as
described in <https://www.postgresql.org/docs/12/dynamic-trace.html&gt;
would have a relationship with txid_current(), but apparently I'm not
getting it:

template1=# begin;
template1=# select txid_current();
txid_current
--------------
488
template1=# commit;

but DTrace shows me:

% sudo ./postgresql.d 33381
[TRANSACTION START] 28 postgres (33381) called StartTransaction
[TRANSACTION COMMIT] 28 postgres (33381) called CommitTransaction

with my script being:

{
printf("[TRANSACTION START] %d %s (%d) called %s\n", args[0],
execname, pid, probefunc);
@tx["begin"] = count();
self->tx_ts = timestamp;
}

postgresql$1:::transaction-commit
/self->tx_ts/
{
printf("[TRANSACTION COMMIT] %d %s (%d) called %s\n", args[0],
execname, pid, probefunc);
@tx["commit"] = count();
@tx_secs["commit"] = quantize( ( timestamp - self->tx_ts ) / 1000 );
self->tx_ts = 0;
}

The args[0] is continuously incremented each time a new transaction is
started, even if it is not supposed to get a non-virtual txid:

template1=# begin;
template1=# rollback;

shows:

% sudo ./postgresql.d 33381
[TRANSACTION START] 29 postgres (33381) called StartTransaction

If i restart the server the args[0] starts from 4, that reminds me
about the min xid available.
Any way to get from LocalTransactionId to txid_current (if assigned)?

Thanks,
Luca

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Luca Ferrari (#1)
Re: LocalTransactionId vs txid_current

Luca Ferrari <fluca1978@gmail.com> writes:

I'm exploring DTrace, and I thought that LocalTransactionId as
described in <https://www.postgresql.org/docs/12/dynamic-trace.html&gt;
would have a relationship with txid_current(),

It does not. txid_current returns a globally valid transaction ID,
while local transaction IDs are just taken from a counter within
the session and have no meaning to other sessions.

regards, tom lane