-
Notifications
You must be signed in to change notification settings - Fork 303
Description
Hello.
Using an existing regular table as model I created a partitioned table (no initial partitions). I created also a compatible template.
Then I successfully created a parent table partition with interval 1 month and adjusted retention to 4 months:
This is the result:
parent_table | control | time_encoder | time_decoder | partition_interval | partition_type | premake | automatic_maintenance | template_table | retention | retention_schema | retention_keep_index | retention_keep_table | epoch | constraint_cols | optimize_constraint | infinite_time_partitions | datetime_string | jobmon | sub_partition_set_full | undo_in_progress | inherit_privileges | constraint_valid | ignore_default_data | date_trunc_interval | maintenance_order | retention_keep_publication | maintenance_last_run
------------------+----------+--------------+--------------+--------------------+----------------+---------+-----------------------+---------------------------+-----------+------------------+----------------------+----------------------+-------+-----------------+---------------------+--------------------------+-----------------+--------+------------------------+------------------+--------------------+------------------+---------------------+---------------------+-------------------+----------------------------+----------------------
testnsp.test_tbl | event_ts | | | 1 mon | range | 2 | on | testnsp.test_tbl_template | 4 months | | f | f | none | | 30 | f | YYYYMMDD | t | f | f | f | t | t | | | f |
Now I want to copy data from original table (testnsp.z_test_tbl) with partition_data_proc(), but using '1 day' instead of '1 month' because the source table is large-ish.
If I understood correctly the documentation, that should be possible, for external_source. Yes, I understand, cleaning the default partition cannot be done in smaller intervals. This is not the case here.
So, I try calling partition_data_proc(). Unfortunately:
testdb=> call partman.partition_data_proc(
p_parent_table := 'testnsp.test_tbl'
, p_loop_count := 100
, p_interval := '1 day'
, p_wait := 1
, p_order := 'DESC'
, p_source_table := 'testnsp.z_test_tbl'
);
ERROR: relation "testuat.test_tbl_p20250825" does not exist
LINE 3: INSERT INTO testuat.test_tbl_p20250...
^
QUERY: WITH partition_data AS (
DELETE FROM ONLY testuat.z_test_tbl WHERE event_ts >= '2025-08-25 11:57:18.169+03' AND event_ts < '2025-09-01 00:00:00+03' RETURNING *)
INSERT INTO testuat.test_tbl_p20250825 (id,row_type,event_ts,src_type,src_info) SELECT id,row_type,event_ts,src_type,src_info FROM partition_data
CONTEXT: PL/pgSQL function partman.partition_data_time(text,integer,interval,numeric,text,boolean,text,text[]) line 258 at EXECUTE
SQL statement "SELECT partman.partition_data_time (p_parent_table := 'testuat.test_tbl', p_lock_wait := '0', p_order := 'DESC', p_analyze := false, p_batch_interval := '1 day', p_source_table := 'testuat.z_test_tbl')"
PL/pgSQL function partman.partition_data_proc(text,integer,text,integer,integer,integer,text,text,text[],boolean) line 86 at EXECUTE
It looks like it's trying to access directly some partition by composing the name according to the '1 day' interval, not to the normal interval of the parent_table.
I tried to look into partition_data_time.sql and it seems that around line 223 of the function (line 237 of the file) the v_min_partition_timestamp is not passed through some logic to determine properly the correct partition name.
Something like applying some truncation logic to v_min_partition_timestamp according to the parent_table's interval.
But that is only a guess, as the overall code is too complicated to fix properly without a significant amount of additional investigation.
Thank you for looking into this.
Florin