Report
pg_dump omits rows of partitioned extension configuration tables
- Severity
- 70
- Blamed commit
- f0e44751d7175fa3394da2c8f85e3ceb3cdbfe63
On 11 branches
REL_10_STABLE, REL_11_STABLE, REL_12_STABLE, REL_13_STABLE, REL_14_STABLE, REL_15_STABLE, REL_16_STABLE, REL_17_STABLE, REL_18_STABLE, REL_19_STABLE, master
Summary
pg_extension_config_dump accepts a partitioned table, but pg_dump then writes no rows for that table or its partitions. Restoring the dump recreates the extension's empty partitions and the user rows are gone. Registering an ordinary inheritance parent still dumps only that parent's own rows. The lost rows are silent. Severity 70.
The early return that skips partitioned tables is present on master and REL_14 through REL_19. This patch is against master and was not applied to those stable branches.
Reproduction
Create a SQL-only extension whose script defines a list-partitioned table z_cfg (k int, v text), partitions z_cfg1 for value 1 and z_cfg2 for value 2, and calls pg_extension_config_dump on z_cfg with an empty condition. After CREATE EXTENSION, insert (1, 'user1') and (2, 'user2').
pg_dump emits CREATE EXTENSION and no COPY for z_cfg, z_cfg1, or z_cfg2. Loading the script into a new database leaves z_cfg empty. The source table had both rows.
A WHERE condition is not an exception. Register a second partitioned table with pg_extension_config_dump and the condition WHERE v <> 'skip', then insert a row that matches and a row that does not. Unpatched pg_dump emits neither row. An inheritance parent registered the same way does dump its own row, and a child created outside the extension is dumped as a normal table.
Diagnosis
pg_extension_config_dump checks that the relation exists and belongs to the extension being created. It does not inspect relkind, so a partitioned table is recorded in pg_extension.extconfig. processExtensionTables asks makeTableDataInfo to dump each registered relation. makeTableDataInfo returns immediately for a partitioned table. That is correct for an ordinary dump: each partition is copied on its own, and copying the parent as well would duplicate rows. COPY TO of a partitioned table on a current server does walk its children, but pg_dump cannot rely on that. The WHERE condition has to be applied to each partition, and the dump must keep working against servers whose COPY of a parent does not include children.
Partitions created in the extension script are extension members. pg_dump does not emit their definitions, and it does not mark them for a data dump except in binary upgrade. Their rows are therefore in neither the parent's COPY nor a partition COPY. The stored WHERE condition is never attached, because no data object is created.
An inheritance parent is a normal table and has its own heap. makeTableDataInfo dumps that heap only. Children are not partitions and must not be pulled in by the configuration entry. When a child is created outside the extension it is an ordinary table and is dumped in full.
The skip was added with table partitioning in f0e44751d7175fa3394da2c8f85e3ceb3cdbfe63. The same return is present on master and REL_14 through REL_19.
Fix
After inheritance links are filled in, a registered partitioned table is expanded to its partitions. Each leaf that would not otherwise be dumped gets a data object, and the registered WHERE condition is applied to that leaf. Intermediate partitioned parents are walked and not copied. A leaf that already has a data component keeps its ordinary dump. That covers partitions created outside the extension and binary-upgrade members, so a filtered configuration copy cannot replace a full copy and drop rows. Inheritance parents are not expanded.
The regression test builds a throwaway extension, then dumps and restores member partitions, a nested partition, a WHERE filter, a partition added outside the extension, an inheritance parent, and an ordinary configuration table.