Hi,
I reproduced a schema-only dump that fails to restore into an empty database on PostgreSQL master that was previously found in greengage (https://github.com/GreengageDB/greengage/pull/605)
The extension creates a partitioned table and a unique index on it. A partition is then created outside the extension.
To reproduce, place attached test_extension.control, test_extension--1.0.sql files in the server installation’s extension directory and install.
Then run:
CREATE EXTENSION test_extension;
CREATE TABLE foo_part PARTITION OF part FOR VALUES FROM ('2023-01-01') TO ('2023-02-01');
$ createdb idx_dump_test && pg_dump | psql -qbt -d idx_dump_test
This leads to an error like:
ERROR: relation "foo_part_id_date_idx" already exists
STATEMENT: CREATE UNIQUE INDEX foo_part_id_date_idx ON public.foo_part USING btree (id, date);
CREATE EXTENSION creates the parent index. When ALTER TABLE … ATTACH PARTITION runs, it creates a matching child index. The explicit CREATE UNIQUE INDEX then fails because the child index already exists.
I’ve attached a port of the Greengage patch to PostgreSQL master. It skips the child index definition and relies on partition attachment to recreate the index.
Would it make sense for pg_dump to emit the child index definition before ALTER TABLE … ATTACH PARTITION in this case, so that partition attachment can reuse the index? I’d appreciate feedback on whether that ordering would conflict with other restore dependencies.
Thanks,
Alexandra