From: | Manuel Rigger <rigger(dot)manuel(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
Subject: | Re: ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation |
Date: | 2019-07-05 23:36:21 |
Message-ID: | CA+u7OA5csC9cE1=+B98WMCuYn61d1eL7hg1_LSgyhBJrd7ZQjA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Okay, thanks for the explanation and sorry for the false alarm!
Best,
Manuel
On Sat, Jul 6, 2019 at 12:52 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> Manuel Rigger <rigger(dot)manuel(at)gmail(dot)com> writes:
> > Consider the following example:
>
> > CREATE TABLE t0(c0 INT);
> > INSERT INTO t0(c0) VALUES(0), (0);
> > CREATE UNIQUE INDEX CONCURRENTLY i0 ON t0(c0);
> > ALTER TABLE t0 SET WITH OIDS; -- expected: no error, actual: ERROR:
> > could not create unique index "i0" DETAIL: Key (c0)=(0) is
> > duplicated.
>
> > The concurrent creation of the UNIQUE INDEX fails, which is expected.
> > However, I would expect that the index is then ignored and that the
> > ALTER TABLE is unaffected.
>
> I'm afraid your expectations are too high. This isn't a bug, although the
> documentation for CREATE INDEX CONCURRENTLY perhaps needs to call out the
> hazard more explicitly. The docs already say
>
> Another caveat when building a unique index concurrently is that the
> uniqueness constraint is already being enforced against other
> transactions when the second table scan begins. This means that
> constraint violations could be reported in other queries prior to the
> index becoming available for use, or even in cases where the index
> build eventually fails. Also, if a failure does occur in the second
> scan, the “invalid” index continues to enforce its uniqueness
> constraint afterwards.
>
> Basically, once an invalid index is in place, it's going to cause you
> problems until you drop it or make it valid. This is the price of
> not taking any exclusive locks in CREATE INDEX CONCURRENTLY: we don't
> really have the option to clean up nicely after failure, because
> that'd require an exclusive table lock :-(
>
> regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | David G. Johnston | 2019-07-06 07:41:42 | Re: BUG #15898: pg_dump error not able to restore complete dump |
Previous Message | Tom Lane | 2019-07-05 22:52:04 | Re: ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation |