Skip to content

Commit

Permalink
Do not create partitions that are not to be retained
Browse files Browse the repository at this point in the history
I realized this requires tests and possibly other changes, but it's just a start to make the proposal from the pgpartman#649 more concrete.
I did try this and works for my use case.
  • Loading branch information
nicolagi committed Apr 11, 2024
1 parent 72bf68c commit 04a4888
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sql/functions/run_maintenance.sql
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ LOOP
SELECT child_start_time INTO v_last_partition_timestamp
FROM @[email protected]_partition_info(v_parent_schema||'.'||v_last_partition, v_row.partition_interval, v_row.parent_table);

IF v_row.retention IS NOT NULL THEN
v_last_partition_timestamp := greatest(v_last_partition_timestamp, CURRENT_TIMESTAMP - v_row.retention::interval);
END IF;

-- Must be reset to null otherwise if the next partition set in the loop is empty, the previous partition set's value could be used
v_current_partition_timestamp := NULL;

Expand Down

0 comments on commit 04a4888

Please sign in to comment.