From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: steven.winfield@cantabcapital.com
Subject: BUG #15513: PID=0 in pgrowlocks output when using savepoints
Date: Mon, 19 Nov 2018 12:23:10 +0000
Message-ID: <15513-94a76c56fa3eed61@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 15513
Logged by: Steven Winfield
Email address: steven.winfield@cantabcapital.com
PostgreSQL version: 10.4
Operating system: RHEL 7.5
Description:
CREATE EXTENSION IF NOT EXISTS pgrowlocks;
CREATE TABLE lock_test (id integer, name text);
INSERT INTO lock_test VALUES (1, 'foo');
BEGIN;
SELECT * FROM lock_test WHERE id = 1 FOR KEY SHARE;
SELECT pids FROM pgrowlocks('lock_test');
-- Returns an array with one element - the current backend PID - as
expected
ROLLBACK;
BEGIN;
SAVEPOINT sp;
SELECT * FROM lock_test WHERE id = 1 FOR KEY SHARE;
SELECT pids FROM pgrowlocks('lock_test');
-- Returns an array with a single element - zero. I expected the current
backend PID again.
ROLLBACK;
It looks like this is because in pgrowlocks.c the 'pids' array is filled
using BackendXidGetPid(xmax), whose documentation says:
/*
* BackendXidGetPid -- get a backend's pid given its XID
*
* Returns 0 if not found or it's a prepared transaction. Note that
* it is up to the caller to be sure that the question remains
* meaningful for long enough for the answer to be used ...
*
* Only main transaction Ids are considered. This function is mainly
* useful for determining what backend owns a lock.
*
* Beware that not every xact has an XID assigned. However, as long as
you
* only call this using an XID found on disk, you're safe.
*/
It looks like xmax is coming from disk...
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
...
xmax = HeapTupleHeaderGetRawXmax(tuple->t_data);
...and a savepoint isn't a prepared transaction (is it?), so perhaps xmax is
now not a "main transaction Id"?
Either way, it would be nice if pgrowlocks worked for locks taken inside
savepoints or if the presence of zeros (and their possible meanings) was
explained in the pgrowlocks documentation.
Thanks,
Steven.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, steven.winfield@cantabcapital.com
Subject: Re: BUG #15513: PID=0 in pgrowlocks output when using savepoints
In-Reply-To: <15513-94a76c56fa3eed61@postgresql.org>
References: <15513-94a76c56fa3eed61@postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox