Skip to content

Commit

Permalink
v1.8.3 Fixed bug with undoing time-custom partition sets. Fixed mista…
Browse files Browse the repository at this point in the history
…ke in settings in sub-partition config table. See CHANGELOG for more info
  • Loading branch information
keithf4 committed Mar 17, 2015
1 parent fedc077 commit f63023f
Show file tree
Hide file tree
Showing 9 changed files with 1,158 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG → CHANGELOG.txt
@@ -1,3 +1,10 @@
1.8.3
-- Fix both the retention system and the undo partitioning functions/scripts not cleaning up the custom_time_partitions table when using a custom time interval (Github Issue #49).
-- When using sub-partitioning, the call to create_parent() that is within create_partition_id() & create_partition_time() was passing 2 of the parameters through incorrectly. p_use_run_maintenance was being fed to p_inherit_fk and vice versa, so the inherit_fk and use_run_maintenance columns in part_config & part_config_sub may be reversed. Since these are both boolean parameters, no error was being raised. If you've used sub-partitioning and used anything other than the default values for either of these configuration options, please double-check the part_config & part_config_sub tables to ensure the proper values are there. If you did not set them specifically, the default values were set for both and things should be fine.
-- If p_use_run_maintenance was set wrong, you likely noticed that new partitons were not getting created for new sub-partition sets. You'll still have to fix any existing config settings, but future ones shoould be fine now.
-- If p_inherit_fk was set wrong, child tables were likely not inheriting FKs or they were inheriting them when you didn't want them to. Again, fix this for existing partition sets by correcting the config table and all future sub-partitions should now be set properly. If you need to generate FKs on child tables that were missing them, you can use the reapply_foreign_keys.py script.


1.8.2
-- Fixed a bug in sub-partitioning that would cause child tables outside of the time boundaries of the parent partitions to be created when using time->time sub-partitioning. A user encountered the error when doing weekly->daily subpartitioning, but it was possible it could have happened in other interval combinations I had not tested as well (Github Issue #47).
-- Updated reapply_indexes.py script to, by default, only add new indexes and drop ones that don't exist on the parent. Previously it would drop all indexes on all children and recreate them to match the parent. Now it only does the minimal amount of work to make the children match the parent. An additional option (--recreate_all/-R) was added to allow the old behavior of redoing all indexes from scratch if desired (Github Issue #41)
Expand Down
6 changes: 3 additions & 3 deletions META.json
@@ -1,7 +1,7 @@
{
"name": "pg_partman",
"abstract": "Extension to manage partitioned tables by time or ID",
"version": "1.8.2",
"version": "1.8.3",
"maintainer": [
"Keith Fiske <keith@omniti.com>"
],
Expand All @@ -20,9 +20,9 @@
},
"provides": {
"pg_partman": {
"file": "sql/pg_partman--1.8.2.sql",
"file": "sql/pg_partman--1.8.3.sql",
"docfile": "doc/pg_partman.md",
"version": "1.8.2",
"version": "1.8.3",
"abstract": "Extension to manage partitioned tables by time or ID"
}
},
Expand Down
2 changes: 1 addition & 1 deletion pg_partman.control
@@ -1,3 +1,3 @@
default_version = '1.8.2'
default_version = '1.8.3'
comment = 'Extension to manage partitioned tables by time or ID'
relocatable = false
3 changes: 1 addition & 2 deletions sql/functions/create_partition_id.sql
Expand Up @@ -206,8 +206,8 @@ FOREACH v_id IN ARRAY p_partition_ids LOOP
, v_row.sub_part_interval
, v_row.sub_constraint_cols
, v_row.sub_premake
, v_row.sub_inherit_fk
, v_row.sub_use_run_maintenance
, v_row.sub_inherit_fk
, v_row.sub_jobmon);
EXECUTE v_sql;

Expand Down Expand Up @@ -272,4 +272,3 @@ EXCEPTION
END
$$;


2 changes: 1 addition & 1 deletion sql/functions/create_partition_time.sql
Expand Up @@ -282,8 +282,8 @@ FOREACH v_time IN ARRAY p_partition_times LOOP
, v_row.sub_part_interval
, v_row.sub_constraint_cols
, v_row.sub_premake
, v_row.sub_inherit_fk
, v_row.sub_use_run_maintenance
, v_row.sub_inherit_fk
, v_row.sub_jobmon);
EXECUTE v_sql;

Expand Down
4 changes: 4 additions & 0 deletions sql/functions/drop_partition_time.sql
Expand Up @@ -142,6 +142,9 @@ LOOP
IF v_jobmon_schema IS NOT NULL THEN
v_step_id := add_step(v_job_id, 'Uninherit table '||v_child_table||' from '||p_parent_table);
END IF;
IF v_type = 'time-custom' THEN
DELETE FROM @extschema@.custom_time_partitions WHERE parent_table = p_parent_table AND child_table = v_child_table;
END IF;
EXECUTE 'ALTER TABLE '||v_child_table||' NO INHERIT ' || p_parent_table;
IF v_jobmon_schema IS NOT NULL THEN
PERFORM update_step(v_step_id, 'OK', 'Done');
Expand Down Expand Up @@ -221,3 +224,4 @@ EXCEPTION
END
$$;


11 changes: 8 additions & 3 deletions sql/functions/undo_partition_time.sql
Expand Up @@ -30,6 +30,7 @@ v_step_id bigint;
v_sub_count int;
v_total bigint := 0;
v_trig_name text;
v_type text;
v_undo_count int := 0;

BEGIN
Expand All @@ -40,10 +41,12 @@ IF v_adv_lock = 'false' THEN
RETURN 0;
END IF;

SELECT part_interval::interval
SELECT type
, part_interval::interval
, control
, jobmon
INTO v_part_interval
INTO v_type
, v_part_interval
, v_control
, v_jobmon
FROM @extschema@.part_config
Expand Down Expand Up @@ -176,6 +179,9 @@ WHILE v_batch_loop_count < p_batch_count LOOP
PERFORM update_step(v_step_id, 'OK', 'Child table UNINHERITED, not DROPPED. Moved '||v_child_loop_total||' rows to parent');
END IF;
END IF;
IF v_type = 'time-custom' THEN
DELETE FROM @extschema@.custom_time_partitions WHERE parent_table = p_parent_table AND child_table = v_child_table;
END IF;
v_undo_count := v_undo_count + 1;
CONTINUE outer_child_loop;
END IF;
Expand Down Expand Up @@ -262,4 +268,3 @@ EXCEPTION
END
$$;


4 changes: 3 additions & 1 deletion test/test_custom_time/test-time-custom-100years.sql
Expand Up @@ -6,7 +6,7 @@
BEGIN;
SELECT set_config('search_path','partman, public',false);

SELECT plan(128);
SELECT plan(129);
CREATE SCHEMA partman_test;
CREATE SCHEMA partman_retention_test;
CREATE ROLE partman_basic;
Expand Down Expand Up @@ -361,5 +361,7 @@ SELECT hasnt_table('partman_test', 'time_static_table_p'||to_char(date_trunc('ce
SELECT hasnt_table('partman_test', 'time_static_table_p'||to_char(date_trunc('century', CURRENT_TIMESTAMP)-'200 years'::interval, 'YYYY'),
'Check time_static_table_'||to_char(date_trunc('century', CURRENT_TIMESTAMP)-'200 years'::interval, 'YYYY')||' does not exist');

SELECT is_empty('SELECT * FROM custom_time_partitions WHERE parent_table = ''partman_test.time_static_table''', 'Check that custom_time_partitions table is empty');

SELECT * FROM finish();
ROLLBACK;

0 comments on commit f63023f

Please sign in to comment.