Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vdzz9-007fSo-22 for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Jan 2026 00:04:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdzz7-004vmM-0E for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Jan 2026 00:04:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vdzz6-004vmE-26 for pgsql-hackers@lists.postgresql.org; Fri, 09 Jan 2026 00:04:09 +0000 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdzz6-004ygk-0P for pgsql-hackers@lists.postgresql.org; Fri, 09 Jan 2026 00:04:08 +0000 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-b6ce6d1d3dcso1742231a12.3 for ; Thu, 08 Jan 2026 16:04:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767917047; x=1768521847; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=O0Nkj7Aj8uSozEkXn7AIerBf0lUAtCFg+Phijv/TxwM=; b=HxI8PbQs/lW+ZsDB16kx2ai33nILuc31EU4QZComJlmxyaZmFITjH2ZNBuF65cRcJI eql3Xh0XFJFVQo8jIUTUGUjvKp09D677Xmn5KA6vTiLBcpzRopZNeICJyuFWQ+QQHJi7 wAS/IYIlQEkt1X/hk62An5kLZMujePQ7skpNZTPv2aSHjHzqTeCB/3b4r06q6PlX8vYe ADo77hWhC04Xn1vRfLWSmP16sjI+Vv9VuRhCI7IoSyVTl8nStWeq3DU+8UsfUtjx3WKV cLq36/m2qog01MUcoXepuh2ZGgpRtVV4WUtlDZZ0c/Dw/o29k4ft4pHNJUvTIO2PL4YL B0uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767917047; x=1768521847; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=O0Nkj7Aj8uSozEkXn7AIerBf0lUAtCFg+Phijv/TxwM=; b=hksj/OopPAD2b0d1tcpAH1xh9dEREpQkqgoSh9T9nZeBq1t28R27H5pUVVfojmPebs sbONy3pMTuP6kynBJ7Qni37zhhkJ0dTbGT8E6JXZytkMfl1Z/uip9bPvqaIRc295MQ9L YQ5/i4Rd6oNjRH3IGnN4AS0WkMuyvfszMtbIP+0H0zhnUmF8zaafQD/gnDnmmM8UT+cw /+6CBUb55725W07X3qIfuq+eYGMkHWHWTTTob71JC/HbfZFHi/SjMhx9TWi1jxM5ctVm Uj2q+CAYg7ZGcSG4fnCAtwJX0K4fQzpGpmnZu3l7TVS5b0KCnuM3d9N7CXeZ9BzXbSu0 wRRQ== X-Gm-Message-State: AOJu0YyPCymnpgOJoUO85ZTtZfmN8CsZOfHBtDnNU6BBCPi51V3y6jGD da8F8T8pSRWezSJa+WhVhSq51HRjkj7nXUIMoyzDnm60M5XnJuk298Co4HjGfNrYKqb7Dr8PQPW 9/ffPA3cC2g1GDTiNcosVpsAUa6Ab4TA= X-Gm-Gg: AY/fxX4GdsWrf6E5nZeWxJrLcMTRD7rhKp9b3cPoKQIo0NwGZAxnTNs9lTS0c96b1e5 bzTvViUSGzkK5Dwvm3BhWthKN6/bhX2F47qCtx+JN/vKy60LQNmiSAjhH2kbbabucNP37SX+v9F Kf2TqbgN2QgDl5G9Y6UDC+bBAzJOnk7kI1iyHYFAhCVpTSUHwennfcRzAcMlXu1UriOo0h9VAuh sMa8XlNqT+xgzZAO8k9TxColwrBa2I3Q9SNHgt9qufwI9USTaDXWIvKBafFlPUJ0izz40anzjML gMG2gHwjQZ7IUx+lU20fc3tEMI2BfpIOHzhrEA== X-Google-Smtp-Source: AGHT+IEgi0mOZAQvQBDboZe+iVFD0HxMnF0eCyhlX1lN/z9FNcdvy5TpljtX7CN4gmt8OwwpxQN7xHSmiPLdDyIpaeA= X-Received: by 2002:a05:6a20:7f9a:b0:35d:b5a1:a61d with SMTP id adf61e73a8af0-3898f91b4c0mr7727687637.26.1767917046504; Thu, 08 Jan 2026 16:04:06 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Reply-To: assam258@gmail.com From: Henson Choi Date: Fri, 9 Jan 2026 09:03:55 +0900 X-Gm-Features: AQt7F2rLNOlxQjRJMvynrC-po98SJ0ITaQNHcd1DnxzPp1rtameyPbAy-5DbT6c Message-ID: Subject: Re: Re[2]: [PATCH] Add pg_current_vxact_id() function to expose virtual transaction IDs To: Pavlo Golub Cc: pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000008ca1550647e9433f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000008ca1550647e9433f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Pavlo, 2026=EB=85=84 1=EC=9B=94 6=EC=9D=BC (=ED=99=94) PM 10:32, Pavlo Golub =EB=8B=98=EC=9D=B4 =EC=9E=91=EC=84=B1: > Hello. > > Thanks for the review. > > > > >Only pg_locks has it. And you can already get your VXID from there: > > > > SELECT virtualtransaction FROM pg_locks > > WHERE pid =3D pg_backend_pid() LIMIT 1; > While it is true that pg_locks contains the virtual transaction > information, I believe there are strong technical reasons to expose this > directly via a function. > Agreed. > First of all, querying pg_locks is expensive. By contrast, > pg_current_vxact_id() is a practically free O(1) read from MyProc. > Yes, this is a significant advantage. The function simply reads from MyProc without any locking or iteration. > The %v log placeholder is the specific identifier for individual > transaction executions (including read-only ones where no permanent XID > is assigned). PIDs (%p) are session-scoped and too coarse for helping > debug specific transactions in connection-pooled environments. This > function allows applications to easily obtain the ID needed to correlate > with server logs. > This is a compelling use case. In connection-pooled environments, correlating application-side logs with server logs by VXID is much more precise than using PIDs. > We already provide fast accessors for other identifiers like > pg_backend_pid() and pg_current_xact_id(). Additionally, PostgreSQL > often provides utility functions that overlap with other commands or > views to improve developer experience (e.g., pg_notify() vs NOTIFY, > pg_sleep() vs pg_sleep_for() vs pg_sleep_until()). It feels consistent > to offer a simple accessor rather than requiring a complex query against > a system view. > > I agree. This follows established PostgreSQL patterns. > Best regards, > Pavlo Golub > > Additionally, the implementation is minimal (~20 lines), so the binary size impact is negligible. And since it's a leaf function called only when explicitly invoked by users, it has no impact on the main code path performance. Best regards, Henson --0000000000008ca1550647e9433f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Pavlo,

2026= =EB=85=84 1=EC=9B=94 6=EC=9D=BC (=ED=99=94) PM 10:32, Pavlo Golub <pavlo.golub@cybertec.at>=EB=8B= =98=EC=9D=B4 =EC=9E=91=EC=84=B1:
Hello.

Thanks for the review.

>
>Only pg_locks has it. And you can already get your VXID from there:
>
>=C2=A0 =C2=A0SELECT virtualtransaction FROM pg_locks
>=C2=A0 =C2=A0WHERE pid =3D pg_backend_pid() LIMIT 1;
While it is true that pg_locks contains the virtual transaction
information, I believe there are strong technical reasons to expose this directly via a function.

Agreed.
=C2=A0
First of all, querying pg_locks is expensive. By contrast,
pg_current_vxact_id() is a practically free O(1) read from MyProc.

Yes, this is a significant advantage. The function s= imply reads from
MyProc without any locking or iteration.
=C2=A0= =C2=A0
The %v log placeholder is the specific identifier for individual
transaction executions (including read-only ones where no permanent XID is assigned). PIDs (%p) are session-scoped and too coarse for helping
debug specific transactions in connection-pooled environments. This
function allows applications to easily obtain the ID needed to correlate with server logs.

This is a compelling = use case. In connection-pooled environments,
correlating application-sid= e logs with server logs by VXID is much
more precise than using PIDs.
=C2=A0
We already provide fast accessors for other identifiers like
pg_backend_pid() and pg_current_xact_id(). Additionally, PostgreSQL
often provides utility functions that overlap with other commands or
views to improve developer experience (e.g., pg_notify() vs NOTIFY,
pg_sleep() vs pg_sleep_for() vs pg_sleep_until()). It feels consistent
to offer a simple accessor rather than requiring a complex query against a system view.


I agree. This follows established Post= greSQL patterns.
=C2=A0
Best regards,
Pavlo Golub


Additionally, the implementation is minimal= (~20 lines), so the binary
size impact is negligible. And since it'= s a leaf function called only
when explicitly invoked by users, it has n= o impact on the main code
path performance.
=C2=A0
Best regards,
Henson=C2=A0
--0000000000008ca1550647e9433f--