BUG #15865: ALTER TABLE statements causing "relation already exists" errors when some indexes exist

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: keith(dot)fiske(at)crunchydata(dot)com
Subject: BUG #15865: ALTER TABLE statements causing "relation already exists" errors when some indexes exist
Date: 2019-06-20 20:14:29
Message-ID: 15865-17940eacc8f8b081@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

The following bug has been logged on the website:

Bug reference: 15865
Logged by: Keith Fiske
Email address: keith(dot)fiske(at)crunchydata(dot)com
PostgreSQL version: 11.4
Operating system: CentOS7
Description:

When testing the setup of our monitoring platform, we started running into
an error when using PostgreSQL as a backend for Grafana. We narrowed down
the issue to only occurring with the latest point release of PG,
specifically 11.4, 10.9 and 9.6.14 (previous major versions were not tested
at this time). The issue can be recreated by following the setup steps for
Grafana with a PG backend and it will occur when the Grafana service is
started for the first time and it tries to set up its schema in PG. We do
not see the error occurring with the previous minor versions (11.3, 10.8,
9.6.13).

A standalone, reproducible use-case is as follows. The final, ALTER TABLE
statement (which is generated by Grafana) will cause the error:

-----------------------------
ERROR: relation "UQE_user_login" already exists
-----------------------------

However if each ALTER COLUMN statement is run independently, it seems to
work fine.

-----------------------------
CREATE TABLE public."user" (
id integer NOT NULL,
version integer NOT NULL,
login character varying(190) NOT NULL,
email character varying(190) NOT NULL,
name character varying(255),
password character varying(255),
salt character varying(50),
rands character varying(50),
company character varying(255),
org_id bigint NOT NULL,
is_admin boolean NOT NULL,
email_verified boolean,
theme character varying(255),
created timestamp without time zone NOT NULL,
updated timestamp without time zone NOT NULL,
help_flags1 bigint DEFAULT 0 NOT NULL
);

CREATE SEQUENCE public.user_id_seq1
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER TABLE ONLY public."user" ALTER COLUMN id SET DEFAULT
nextval('public.user_id_seq1'::regclass);

SELECT pg_catalog.setval('public.user_id_seq1', 1, false);

ALTER TABLE ONLY public."user" ADD CONSTRAINT user_pkey1 PRIMARY KEY (id);

CREATE UNIQUE INDEX "UQE_user_email" ON public."user" USING btree (email);

CREATE UNIQUE INDEX "UQE_user_login" ON public."user" USING btree (login);

ALTER TABLE "user" ALTER "login" TYPE VARCHAR(190), ALTER "email" TYPE
VARCHAR(190), ALTER "name" TYPE VARCHAR(255), ALTER "password" TYPE
VARCHAR(255), ALTER "salt" TYPE VARCHAR(50), ALTER "rands" TYPE VARCHAR(50),
ALTER "company" TYPE VARCHAR(255), ALTER "theme" TYPE VARCHAR(255);
-----------------------------

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2019-06-20 20:45:05 Re: BUG #15865: ALTER TABLE statements causing "relation already exists" errors when some indexes exist
Previous Message PG Bug reporting form 2019-06-20 18:46:27 BUG #15864: problems with the instalation of PostgreSQL 9.4

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Gierth 2019-06-20 20:23:25 Re: UCT (Re: pgsql: Update time zone data files to tzdata release 2019a.)
Previous Message Tom Lane 2019-06-20 19:58:51 Re: UCT (Re: pgsql: Update time zone data files to tzdata release 2019a.)