pg_dump restore fails for partitions of extension-owned tables

From: Aleksandra Pervushina <a(dot)pervushina(at)arenadata(dot)io>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: pg_dump restore fails for partitions of extension-owned tables
Date: 2026-11-30 23:44:21
Message-ID: 649411796071133@mail.360.yandex.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers



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

Attachment Content-Type Size
unknown_filename text/html 2.1 KB
test_extension.control application/octet-stream 71 bytes
test_extension--1.0.sql application/x-sql 186 bytes
pg_dump-v1.patch text/x-diff 24.0 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-12-01 00:03:19 Re: Interrupts vs signals
Previous Message Zsolt Parragi 2026-11-30 23:31:20 Re: Safer and simpler HTAB macros (foreach_hash and hash_make), take two