Skip to content

Monthly partitions are hour-sensitive #269

Description

@bartoszdabr

Problem

Let's say I've got the following partitioning manager

manager = PostgresPartitioningManager(
    [
        PostgresPartitioningConfig(
            model=MyModel,
            strategy=PostgresCurrentTimePartitioningStrategy(
                size=PostgresTimePartitionSize(months=1),
                count=2,
                max_age=relativedelta(months=1),
            ),
        ),
    ]
)

running pgpartition at 17.11.2025 12:00 UTC results in folowing partitions to be created
python manage.py pgpartition --defer-attach --detach=concurrently

MyModel:
  + 2025_nov (deferred attach)
     name: 2025_nov
     from_values: 2025-11-01 12:00:00
     to_values: 2025-12-01 12:00:00
     size_unit: months
     size_value: 1
  + 2025_dec (deferred attach)
     name: 2025_dec
     from_values: 2025-12-01 12:00:00
     to_values: 2026-01-01 12:00:00
     size_unit: months
     size_value: 1

Now let's skip time to 18.12.2025 08:00 UTC and run the same command to see the results

MyModel:
  - 2025_nov
     name: 2025_nov
     from_values: 2025-11-01 08:00:00
     to_values: 2025-12-01 08:00:00
     size_unit: months
     size_value: 1
  + 2026_jan (deferred attach)
     name: 2026_jan
     from_values: 2026-01-01 08:00:00
     to_values: 2026-02-01 08:00:00
     size_unit: months
     size_value: 1
  ~ 2025_nov (detached concurrently)
     name: 2025_nov
     from_values: 2025-11-01 08:00:00
     to_values: 2025-12-01 08:00:00
     size_unit: months
     size_value: 1

As we see the partition with _jan suffix is overlapping with the previously created one for dec.

Alternatively if we skip time to 18.12.2025 16:00 UTC the results are following

MyModel:
  - 2025_nov
     name: 2025_nov
     from_values: 2025-11-01 16:00:00
     to_values: 2025-12-01 16:00:00
     size_unit: months
     size_value: 1
  + 2026_jan (deferred attach)
     name: 2026_jan
     from_values: 2026-01-01 16:00:00
     to_values: 2026-02-01 16:00:00
     size_unit: months
     size_value: 1
  ~ 2025_nov (detached concurrently)
     name: 2025_nov
     from_values: 2025-11-01 16:00:00
     to_values: 2025-12-01 16:00:00
     size_unit: months
     size_value: 1

now the _jan partition starts at 16:00, while the previous one ends at 12:00 so we have 4 hour hole in our table.

Expectations

I'd expect the partition ranges to be aligned to 00:00 when using monthly-sized ranges.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions