Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
ef8c60a
feat(ingest/postgres): add include_table_partitions to skip table par…
NehaGslab Nov 26, 2026
0fd3867
Merge branch 'master' into feat-postgres-skip-partitioned-tables
NehaGslab Nov 26, 2026
5f14d9d
test(ingest/postgres): cover profiling when table partitions are skipped
NehaGslab Nov 26, 2026
e7b817c
refactor(ingest/postgres): list table partitions once per schema
NehaGslab Nov 26, 2026
9fcf221
Merge branch 'master' into feat-postgres-skip-partitioned-tables
NehaGslab Nov 26, 2026
ba1fb30
Merge branch 'feat-postgres-skip-partitioned-tables' of https://githu…
NehaGslab Nov 26, 2026
2a361dd
Merge branch 'master' into feat-postgres-skip-partitioned-tables
NehaGslab Nov 27, 2026
a58e435
test(ingest/postgres): check partition cache is keyed by database and…
NehaGslab Nov 27, 2026
7c10ae5
refactor(ingest/postgres): limit partition query to tables
NehaGslab Nov 27, 2026
6ba0388
fix(ingest/postgres): point partition-listing warning at the likely c…
NehaGslab Nov 27, 2026
83f6ff7
test(ingest/postgres): assert exact table list in default partitions …
NehaGslab Nov 27, 2026
408d62e
test(ingest/postgres): cover sub-partitions in partition integration …
NehaGslab Nov 27, 2026
006211a
refactor(ingest/postgres): shorten partition cache comment
NehaGslab Nov 27, 2026
bd8a695
Merge branch 'master' into feat-postgres-skip-partitioned-tables
NehaGslab Nov 27, 2026
9fdb8da
Merge branch 'feat-postgres-skip-partitioned-tables' of https://githu…
NehaGslab Nov 27, 2026
3712d43
docs(ingest/postgres): clarify relkind p in partition query docstring
NehaGslab Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions metadata-ingestion/docs/sources/postgres/postgres_post.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ Navigate to a dataset in DataHub and check the "Lineage" tab. You should see ups
- Run ingestion daily or weekly to capture lineage from new queries
- More frequent ingestion provides more up-to-date lineage graphs

#### Partitioned tables

By default, each partition of a declaratively partitioned table (`PARTITION BY`, PostgreSQL 10+) is ingested as its own dataset, alongside the parent table. For tables partitioned by day or month, this can add hundreds of near-duplicate datasets.

To ingest only the parent table and skip its partitions, set `include_table_partitions` to `false`:

```yaml
source:
type: postgres
config:
# ...
include_table_partitions: false
```

Partitions are detected through `pg_class.relispartition`, so new partitions are skipped automatically without updating `table_pattern`. Sub-partitions are skipped too. The ingestion report lists skipped partitions under `num_table_partitions_skipped` and `table_partitions_skipped`.

Child tables created with table inheritance (`INHERITS`) are not partitions and are always ingested. Use `table_pattern` to exclude them.

If stateful ingestion with `remove_stale_metadata` is enabled, turning this option off soft-deletes partitions that earlier runs ingested.

The CockroachDB and TimescaleDB sources inherit this option. TimescaleDB hypertable chunks are inheritance children, not partitions, so they are still ingested. On CockroachDB, partition detection may fail; the source then logs a warning and ingests all tables.

### Limitations

Module behavior is constrained by source APIs, permissions, and metadata exposed by the platform. Refer to capability notes for unsupported or conditional features.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ def _build_pg_stat_filter(

return " AND ".join(filters)

@staticmethod
def get_table_partitions() -> TextClause:
"""List tables in a schema that are partitions of a partitioned table.

relispartition was added in Postgres 10, alongside declarative
partitioning.
"""
return text(
"""
SELECT c.relname AS table_name
FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = :schema
AND c.relispartition
Comment thread
NehaGslab marked this conversation as resolved.
Resolved
"""
)

@staticmethod
def check_pg_stat_statements_enabled() -> TextClause:
"""Check if pg_stat_statements extension is installed."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,17 @@ class PostgresConfig(BasePostgresConfig, BaseUsageConfig):
"Specify regex to match the entire procedure name in database.schema.procedure_name format. e.g. to match all procedures starting with customer in Customer database and public schema, use the regex 'Customer.public.customer.*'",
)

include_table_partitions: bool = Field(
default=True,
description=(
"Ingest each partition of a declaratively partitioned table "
"(PARTITION BY, Postgres 10+) as its own dataset. Set to false to "
"ingest only the parent partitioned table and skip its partitions. "
"Child tables created with table inheritance (INHERITS) are not "
"partitions and are always ingested; use table_pattern to exclude them."
),
)

include_query_lineage: bool = Field(
default=False,
description=(
Expand Down Expand Up @@ -577,6 +588,12 @@ def __init__(self, config: PostgresConfig, ctx: PipelineContext):
config.rds_iam_token_manager()
)

# Partition names per (database, schema). loop_tables and
# loop_profiler_requests both list tables, so caching the first answer
# keeps the two passes consistent (also when listing fails) and lets
# each schema be queried and reported once.
self._table_partitions: Dict[Tuple[str, str], FrozenSet[str]] = {}
Comment thread
NehaGslab marked this conversation as resolved.
Resolved

self.sql_aggregator: Optional[SqlParsingAggregator] = None
if self.config.include_query_lineage:
# Validate graph connection requirement for usage statistics
Expand Down Expand Up @@ -741,6 +758,50 @@ def _get_view_names(self, inspector: Inspector, schema: str) -> List[str]:
name for name in materialized_view_names if name not in known
]

def _get_table_names(self, inspector: Inspector, schema: str) -> List[str]:
table_names = super()._get_table_names(inspector, schema)
if self.config.include_table_partitions:
return table_names

key = (self.get_db_name(inspector), schema)
first_listing = key not in self._table_partitions
if first_listing:
self._table_partitions[key] = self._list_table_partitions(inspector, schema)
partitions = self._table_partitions[key]

kept: List[str] = []
for table in table_names:
if table not in partitions:
kept.append(table)
elif first_listing:
dataset_name = self.get_identifier(
schema=schema, entity=table, inspector=inspector
)
self.report.num_table_partitions_skipped += 1
self.report.table_partitions_skipped.append(dataset_name)
return kept

def _list_table_partitions(
self, inspector: Inspector, schema: str
) -> FrozenSet[str]:
try:
with inspector.engine.connect() as conn:
return frozenset(
row.table_name
for row in conn.execute(
PostgresQuery.get_table_partitions(), {"schema": schema}
)
)
except Exception as e:
self.report.warning(
title="Failed to list table partitions",
message="Partitions in this schema will be ingested and profiled as regular tables. "
"Detecting partitions requires Postgres 10+ and read access to pg_catalog.",
Comment thread
NehaGslab marked this conversation as resolved.
Resolved
context=f"{self.get_db_name(inspector)}.{schema}",
exc=e,
)
return frozenset()

def get_workunits_internal(self) -> Iterable[Union[MetadataWorkUnit, SqlWorkUnit]]:
yield from super().get_workunits_internal()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ def loop_tables(
data_reader = self.make_data_reader(inspector)
with data_reader or contextlib.nullcontext():
try:
for table in inspector.get_table_names(schema):
for table in self._get_table_names(inspector, schema):
dataset_name = self.get_identifier(
schema=schema, entity=table, inspector=inspector
)
Expand Down Expand Up @@ -1226,6 +1226,12 @@ def loop_views(
exc=e,
)

def _get_table_names(self, inspector: Inspector, schema: str) -> List[str]:
"""Names of the tables loop_tables ingests and loop_profiler_requests
profiles. Override to drop table-like objects the dialect lists but the
source should skip (e.g. partitions of a partitioned table)."""
return inspector.get_table_names(schema)

def _get_view_names(self, inspector: Inspector, schema: str) -> List[str]:
"""Names of the views loop_views ingests. Override to add view-like
objects the dialect lists separately (e.g. materialized views)."""
Expand Down Expand Up @@ -1492,7 +1498,7 @@ def loop_profiler_requests(
except NotImplementedError:
logger.debug("Source does not support generating profile candidates.")

for table in inspector.get_table_names(schema):
for table in self._get_table_names(inspector, schema):
dataset_name = self.get_identifier(
schema=schema, entity=table, inspector=inspector
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class SQLSourceReport(
default_factory=LossyList
)

# Partitions dropped by a source's _get_table_names override (e.g. Postgres
# with include_table_partitions disabled). The parent table is still ingested.
num_table_partitions_skipped: int = 0
table_partitions_skipped: LossyList[str] = field(default_factory=LossyList)

def report_entity_scanned(self, name: str, ent_type: str = "table") -> None:
"""
Entity could be a view or a table
Expand Down
Loading