pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation
4+ messages / 3 participants
[nested] [flat]
* ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation
@ 2019-07-02 10:06 Manuel Rigger <rigger.manuel@gmail.com>
2019-07-05 22:52 ` Re: ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 4+ messages in thread
From: Manuel Rigger @ 2019-07-02 10:06 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org
Hi everyone,
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. Instead, the ALTER TABLE command results in
the same error as the CREATE INDEX statement.
Other ALTER TABLE commands seem to be unaffected by the invalid index:
ALTER TABLE t0 SET WITHOUT OIDS; -- no error
ALTER TABLE t0 ALTER c0 SET NOT NULL; -- no error
ALTER TABLE t0 ALTER c0 SET DEFAULT 1; -- no error
ALTER TABLE t0 RENAME c0 TO c1; -- no error
As a workaround, the invalid INDEX can be dropped (which is a good
idea anyway, since it consumes space):
DROP INDEX i0;
ALTER TABLE t0 SET WITH OIDS; -- no error
I'm using the following Postgres version: psql (11.4 (Ubuntu
11.4-1.pgdg19.04+1)).
Best,
Manuel
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation
2019-07-02 10:06 ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation Manuel Rigger <rigger.manuel@gmail.com>
@ 2019-07-05 22:52 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-07-05 23:36 ` Re: ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation Manuel Rigger <rigger.manuel@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Tom Lane @ 2019-07-05 22:52 UTC (permalink / raw)
To: Manuel Rigger <rigger.manuel@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org
Manuel Rigger <rigger.manuel@gmail.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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation
2019-07-02 10:06 ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation Manuel Rigger <rigger.manuel@gmail.com>
2019-07-05 22:52 ` Re: ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-07-05 23:36 ` Manuel Rigger <rigger.manuel@gmail.com>
2019-07-08 06:01 ` Re: ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation Michael Paquier <michael@paquier.xyz>
0 siblings, 1 reply; 4+ messages in thread
From: Manuel Rigger @ 2019-07-05 23:36 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
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@sss.pgh.pa.us> wrote:
>
> Manuel Rigger <rigger.manuel@gmail.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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation
2019-07-02 10:06 ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation Manuel Rigger <rigger.manuel@gmail.com>
2019-07-05 22:52 ` Re: ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation Tom Lane <tgl@sss.pgh.pa.us>
2019-07-05 23:36 ` Re: ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation Manuel Rigger <rigger.manuel@gmail.com>
@ 2019-07-08 06:01 ` Michael Paquier <michael@paquier.xyz>
0 siblings, 0 replies; 4+ messages in thread
From: Michael Paquier @ 2019-07-08 06:01 UTC (permalink / raw)
To: Manuel Rigger <rigger.manuel@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
On Sat, Jul 06, 2019 at 01:36:21AM +0200, Manuel Rigger wrote:
> Okay, thanks for the explanation and sorry for the false alarm!
Another thing which you may be interested in is that support for SET
WITH OIDS has been dropped as of v12.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2019-07-08 06:01 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-02 10:06 ALTER TABLE SET WITH OIDS fails after failed CONCURRENTLY index creation Manuel Rigger <rigger.manuel@gmail.com>
2019-07-05 22:52 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-07-05 23:36 ` Manuel Rigger <rigger.manuel@gmail.com>
2019-07-08 06:01 ` Michael Paquier <michael@paquier.xyz>
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