pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: m.walczak@megavision.pl
Subject: BUG #19069: pg_advisory_xact_lock() in a WITH query doesn't work
Date: Thu, 02 Oct 2025 13:11:37 +0000
Message-ID: <19069-f5c72e4e4f921a7c@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      19069
Logged by:          Maciej Walczak
Email address:      m.walczak@megavision.pl
PostgreSQL version: 18.0
Operating system:   Windows 11 Pro 24H2
Description:        

This doesn't actually do any locking:

BEGIN;
WITH my_lock AS (
        SELECT pg_advisory_xact_lock(1)
)
INSERT INTO my_table (...) VALUES (...);
COMMIT;

To reproduce just run this code in two sessions in parallel without
commiting.
Both inserts will immediately complete without blocking.

I'm not sure if this is a bug. If it's not, perhaps the documentation should
be clarified.
Side-effects of WITH queries are mentioned here, so I would expect my code
to work:
https://www.postgresql.org/docs/16/queries-with.html#QUERIES-WITH-CTE-MATERIALIZATION

Tested on Postgres 18.0 and 16.10.



view thread (3+ messages)  latest in thread

Message-ID: <19069-f5c72e4e4f921a7c@postgresql.org>
Permalink:  ../19069-f5c72e4e4f921a7c@postgresql.org/
Also on:    postgresql.org/message-id/19069-f5c72e4e4f921a7c@postgresql.org

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, m.walczak@megavision.pl
  Subject: Re: BUG #19069: pg_advisory_xact_lock() in a WITH query doesn't work
  In-Reply-To: <19069-f5c72e4e4f921a7c@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