You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Partitioned schema dumps can fail to replay or omit indexes when inherited index names change #653
PostgreSQL automatically creates indexes for inherited PRIMARY KEY and UNIQUE constraints when creating a partition.
During dump replay, pgschema can create objects in a different order from the source database. PostgreSQL can therefore assign different names to those inherited indexes.
This can cause a name collision with another index in the dump. Replay can then fail, or PostgreSQL can skip an intended index because its name already exists.
Minimal reproduction
Use two empty databases, source_db and replay_db.
Create this schema in source_db:
CREATETABLEpublic.events (
id integerPRIMARY KEY
) PARTITION BY RANGE (id);
CREATEINDEXevents_leaf_pkeyONpublic.events (id);
CREATETABLEpublic.events_leaf
PARTITION OF public.events
FOR VALUESFROM (0) TO (10);
The standalone parent index occupies events_leaf_pkey. PostgreSQL therefore names the inherited primary-key index on events_leaf as events_leaf_pkey1.
pgschema creates events_leaf before the standalone parent index.
PostgreSQL names the inherited primary-key index events_leaf_pkey.
PostgreSQL skips the subsequent CREATE INDEX IF NOT EXISTS events_leaf_pkey, because that name now exists.
PostgreSQL rejects the subsequent index attachment with SQLSTATE 42809, because the existing index is not the intended partitioned parent index.
A related case can silently omit an index. If a user renames a child's primary-key index and reuses its original name for an index on another column, replay can assign that name back to the primary-key index and skip the other index.
Expected behavior
Dump replay should preserve:
Index names and definitions.
PRIMARY KEY and UNIQUE constraint ownership.
Parent-child index attachments.
Separate standalone indexes, even when their names overlap with names PostgreSQL would otherwise generate.
Replaying a dump into an empty database should reproduce the source schema. A subsequent plan against that dump should contain no changes.
Context
The reproduction concerns the partition-index dump behavior following #643. PR #645 proposes a fix.
Opened following the maintainer's request: #645 (comment)
This issue describes the required behavior without prescribing a particular SQL-generation strategy.
Activity