Subject: Fix showing XID of a spectoken lock in an incorrect field of pg_locks view.

From: Masahiko Sawada <[email-masked]>
Date: Wed, 4 Jan 2023 15:45:34 +0900

Hi,

I realized that pg_locks view shows the transaction id of a
speculative token lock in the database field:

postgres(1:509389)=# select * from pg_locks where locktype = 'spectoken';
 locktype  | database | relation | page | tuple | virtualxid |
transactionid | classid | objid | objsubid | virtualtransaction |  pid
  |     mode      | granted | fastpath | waitstart
-----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+--------+---------------+---------+----------+-----------
 spectoken |      741 |          |      |       |            |
      |       3 |     0 |        0 | 3/5                | 509314 |
ExclusiveLock | t       | f        |
(1 row)

It seems to be confusing and the user won't get the result even if
they search it by transactionid = 741. So I've attached the patch to
fix it. With the patch, the pg_locks views shows like:

 locktype  | database | relation | page | tuple | virtualxid |
transactionid | classid | objid | objsubid | virtualtransaction |  pid
  |     mode      | granted | fastpath | waitstart
-----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+--------+---------------+---------+----------+-----------
 spectoken |          |          |      |       |            |
  746 |         |     1 |          | 3/4                | 535618 |
ExclusiveLock | t       | f        |
(1 row)

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com