Re: [PATCH] Add pg_current_vxact_id() function to expose virtual transaction IDs

Henson Choi <assam258@gmail.com>

From: Henson Choi <assam258@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Cc: Pavlo Golub <pavlo.golub@gmail.com>
Date: 2025-12-28T13:31:57Z
Lists: pgsql-hackers
I looked into where VXID is actually used:

  SELECT c.relname, a.attname 
  FROM pg_attribute a JOIN pg_class c ON a.attrelid = c.oid 
  WHERE a.attname LIKE '%virtual%' AND a.attnum > 0;

   relname  |      attname       
  ----------+--------------------
   pg_locks | virtualxid
   pg_locks | virtualtransaction

Only pg_locks has it. And you can already get your VXID from there:

  SELECT virtualtransaction FROM pg_locks 
  WHERE pid = pg_backend_pid() LIMIT 1;

This always works since every transaction holds its own VXID lock.

For log correlation, PID works in most cases.

So I'm having trouble seeing a compelling use case. Could you share
a concrete scenario where this function would help?

The patch itself is clean, but I'm not sure about the justification.