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.