On Tue, Oct 28, 2025 at 02:19:00AM +0100, Mihail Nikalayeu wrote:
> On Mon, Oct 27, 2025 at 7:06 PM Noah Misch <[email protected]> wrote:
> > Yes, I'm happy to push a patch documenting it.  Would you like to propose 
> > the
> > specific doc patch?  I regret lacking the bandwidth to review the fix 
> > patches.
> 
> Of course!
> 
> First version in attachment, waiting for your comment.

Thanks.  Does "ON CONFLICT ON CONSTRAINT constraint_name" avoid the problem w/
concurrent REINDEX CONCURRENTLY?  A search of the thread found no mention of
"ON CONSTRAINT".  It seems safe to assume that clause would avoid problems w/
CREATE INDEX CONCURRENTLY, but that's less certain for REINDEX.

The attached version has these changes:

- Mention ON CONSTRAINT as a workaround.  Will remove if you find or suspect
  it's not effective.
- Limit the doc change to ON CONFLICT.  I think mentioning it at the INDEX
  commands is undue emphasis.
- Use term "unique violation", a term used earlier on the same page, instead
  of "duplicate key ...".
- Remove the internals-focused point about the brief window.
- Remove some detail I considered insufficiently surprising, e.g. the point
  about "compatible with the index being built".
From: Noah Misch <[email protected]>

Doc: cover index CONCURRENTLY causing errors in INSERT ... ON CONFLICT.

Author: Mikhail Nikalayeu <[email protected]>
Reviewed-by: Noah Misch <[email protected]>
Discussion: 
https://postgr.es/m/CANtu0ojXmqjmEzp-=ajsxjsde76iasrghbok0qtyhimb_me...@mail.gmail.com
Backpatch-through: 13

diff --git a/doc/src/sgml/ref/insert.sgml b/doc/src/sgml/ref/insert.sgml
index 3f13991..f88ea78 100644
--- a/doc/src/sgml/ref/insert.sgml
+++ b/doc/src/sgml/ref/insert.sgml
@@ -594,6 +594,17 @@ INSERT INTO <replaceable 
class="parameter">table_name</replaceable> [ AS <replac
     </para>
    </tip>
 
+   <warning>
+    <para>
+      While <command>CREATE INDEX CONCURRENTLY</command> or <command>REINDEX
+      CONCURRENTLY</command> is running on a unique index, <command>INSERT
+      ... ON CONFLICT</command> statements on the same table may unexpectedly
+      fail with a unique violation.  Using <literal>ON CONFLICT ON
+      CONSTRAINT</literal> <replaceable class="parameter">
+      constraint_name</replaceable> avoids this, by disabling inference.
+    </para>
+   </warning>
+
   </refsect2>
  </refsect1>
 

Reply via email to