Skip to content

Commit f0c1b58

Browse files
committed
v4.5.0 Fix v4.4.1 upgrade. Better compatibility with generated columns. See CHANGELOG for more details.
1 parent 63328c5 commit f0c1b58

23 files changed

+9063
-1677
lines changed

CHANGELOG.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
4.5.0
2+
NEW FEATURES
3+
============
4+
-- Officially supported minimal version is now PostgreSQL 9.6. PostgreSQL 9.6 support will be ending the next pg_partman release after PostgreSQL 14 is released.
5+
6+
-- Removed p_debug from functions changed in this update. Slowly migrating all functions away from parameter to using debug logging level instead.
7+
8+
BUG FIXES
9+
=========
10+
-- Fixed issue when upgrading from 4.4.0 to 4.4.1 on PG10 and below. Upgrade path now goes directly from 4.4.0 to 4.5.0 and skips 4.4.1. All changes in 4.4.1 have been included in 4.5.0 where necessary. (Github Issue #342)
11+
12+
-- Added the parameter `p_ignored_columns` to partition_data_time(), partition_data_id(), partition_data_proc(), undo_partition() and undo_partition_proc(). The parameter is an array that can list one or more columns to ignore their values when moving the data. This allows for moving data out of the default/parent table when generated columns are in use. (Github Issue #336)
13+
14+
-- Fixed the p_start_partition parameter working properly with id->timestamp sub-partitioning. (Github Issue #341)
15+
16+
117
4.4.1
218
NEW FEATURES
319
============

META.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pg_partman",
33
"abstract": "Extension to manage partitioned tables by time or ID",
4-
"version": "4.4.1",
4+
"version": "4.5.0",
55
"maintainer": [
66
"Keith Fiske <[email protected]>"
77
],
@@ -11,7 +11,7 @@
1111
"prereqs": {
1212
"runtime": {
1313
"requires": {
14-
"PostgreSQL": "9.4.0"
14+
"PostgreSQL": "9.6.0"
1515
},
1616
"recommends": {
1717
"pg_jobmon": "1.3.2"
@@ -20,9 +20,9 @@
2020
},
2121
"provides": {
2222
"pg_partman": {
23-
"file": "sql/pg_partman--4.4.1.sql",
23+
"file": "sql/pg_partman--4.5.0.sql",
2424
"docfile": "doc/pg_partman.md",
25-
"version": "4.4.1",
25+
"version": "4.5.0",
2626
"abstract": "Extension to manage partitioned tables by time or ID"
2727
}
2828
},

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ INSTALLATION
2121
------------
2222
Requirement:
2323

24-
* PostgreSQL >= 9.5
24+
* PostgreSQL >= 9.6
2525

2626
Recommended:
2727

doc/pg_partman.md

Lines changed: 21 additions & 17 deletions
Large diffs are not rendered by default.

pg_partman.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
default_version = '4.4.1'
1+
default_version = '4.5.0'
22
comment = 'Extension to manage partitioned tables by time or ID'
33
relocatable = false

sql/functions/apply_constraints.sql

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE FUNCTION @[email protected]_constraints(p_parent_table text, p_child_table text DEFAULT NULL, p_analyze boolean DEFAULT FALSE, p_job_id bigint DEFAULT NULL, p_debug boolean DEFAULT FALSE) RETURNS void
1+
CREATE FUNCTION @[email protected]_constraints(p_parent_table text, p_child_table text DEFAULT NULL, p_analyze boolean DEFAULT FALSE, p_job_id bigint DEFAULT NULL) RETURNS void
22
LANGUAGE plpgsql
33
AS $$
44
DECLARE
@@ -74,9 +74,7 @@ WHERE parent_table = p_parent_table
7474
AND constraint_cols IS NOT NULL;
7575

7676
IF v_constraint_cols IS NULL THEN
77-
IF p_debug THEN
78-
RAISE NOTICE 'Given parent table (%) not set up for constraint management (constraint_cols is NULL)', p_parent_table;
79-
END IF;
77+
RAISE DEBUG 'Given parent table (%) not set up for constraint management (constraint_cols is NULL)', p_parent_table;
8078
-- Returns silently to allow this function to be simply called by maintenance processes without having to check if config options are set.
8179
RETURN;
8280
END IF;
@@ -124,9 +122,7 @@ IF p_child_table IS NULL THEN
124122

125123
v_child_tablename := @[email protected]_name_length(v_parent_tablename, v_partition_suffix, TRUE);
126124

127-
IF p_debug THEN
128-
RAISE NOTICE 'apply_constraint: v_parent_tablename: % , v_partition_suffix: %', v_parent_tablename, v_partition_suffix;
129-
END IF;
125+
RAISE DEBUG 'apply_constraint: v_parent_tablename: % , v_partition_suffix: %', v_parent_tablename, v_partition_suffix;
130126

131127
IF v_jobmon_schema IS NOT NULL THEN
132128
PERFORM update_step(v_step_id, 'OK', format('Target child table: %s.%s', v_parent_schema, v_child_tablename));
@@ -147,9 +143,7 @@ IF v_child_exists IS NULL THEN
147143
PERFORM close_job(v_job_id);
148144
END IF;
149145
END IF;
150-
IF p_debug THEN
151-
RAISE NOTICE 'Target child table (%) does not exist. Skipping constraint creation.', v_child_tablename;
152-
END IF;
146+
RAISE DEBUG 'Target child table (%) does not exist. Skipping constraint creation.', v_child_tablename;
153147
EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', v_old_search_path, 'false');
154148
RETURN;
155149
ELSE
@@ -182,9 +176,7 @@ LOOP
182176
IF v_jobmon_schema IS NOT NULL THEN
183177
PERFORM update_step(v_step_id, 'NOTICE', format('Partman managed constraint already exists on this table (%s) and column (%s). Skipping creation.', v_child_tablename, v_col));
184178
END IF;
185-
IF p_debug THEN
186-
RAISE NOTICE 'Partman managed constraint already exists on this table (%) and column (%). Skipping creation.', v_child_tablename, v_col ;
187-
END IF;
179+
RAISE DEBUG 'Partman managed constraint already exists on this table (%) and column (%). Skipping creation.', v_child_tablename, v_col ;
188180
CONTINUE;
189181
END IF;
190182

@@ -207,18 +199,14 @@ LOOP
207199
v_sql := format('%s NOT VALID', v_sql);
208200
END IF;
209201

210-
IF p_debug THEN
211-
RAISE NOTICE 'Constraint creation query: %', v_sql;
212-
END IF;
202+
RAISE DEBUG 'Constraint creation query: %', v_sql;
213203
EXECUTE v_sql;
214204

215205
IF v_jobmon_schema IS NOT NULL THEN
216206
PERFORM update_step(v_step_id, 'OK', format('New constraint created: %s', v_sql));
217207
END IF;
218208
ELSE
219-
IF p_debug THEN
220-
RAISE NOTICE 'Given column (%) contains all NULLs. No constraint created', v_col;
221-
END IF;
209+
RAISE DEBUG 'Given column (%) contains all NULLs. No constraint created', v_col;
222210
IF v_jobmon_schema IS NOT NULL THEN
223211
PERFORM update_step(v_step_id, 'NOTICE', format('Given column (%s) contains all NULLs. No constraint created', v_col));
224212
END IF;
@@ -230,10 +218,7 @@ IF p_analyze THEN
230218
IF v_jobmon_schema IS NOT NULL THEN
231219
v_step_id := add_step(v_job_id, format('Applying additional constraints: Running analyze on partition set: %s', v_parent_table));
232220
END IF;
233-
IF p_debug THEN
234-
RAISE NOTICE 'Running analyze on partition set: %', v_parent_table;
235-
END IF;
236-
221+
RAISE DEBUG 'Running analyze on partition set: %', v_parent_table;
237222
EXECUTE format('ANALYZE %I.%I', v_parent_schema, v_parent_tablename);
238223

239224
IF v_jobmon_schema IS NOT NULL THEN
@@ -270,4 +255,3 @@ HINT: %', ex_message, ex_context, ex_detail, ex_hint;
270255
END
271256
$$;
272257

273-

sql/functions/create_parent.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ CREATE FUNCTION @[email protected]_parent(
1313
, p_publications text[] DEFAULT NULL
1414
, p_trigger_return_null boolean DEFAULT true
1515
, p_template_table text DEFAULT NULL
16-
, p_jobmon boolean DEFAULT true
17-
, p_debug boolean DEFAULT false)
16+
, p_jobmon boolean DEFAULT true)
1817
RETURNS boolean
1918
LANGUAGE plpgsql
2019
AS $$

sql/functions/create_partition_id.sql

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE FUNCTION @[email protected]_partition_id(p_parent_table text, p_partition_ids bigint[], p_analyze boolean DEFAULT true, p_debug boolean DEFAULT false) RETURNS boolean
1+
CREATE FUNCTION @[email protected]_partition_id(p_parent_table text, p_partition_ids bigint[], p_analyze boolean DEFAULT true, p_start_partition text DEFAULT NULL) RETURNS boolean
22
LANGUAGE plpgsql
33
AS $$
44
DECLARE
@@ -175,9 +175,7 @@ FOREACH v_id IN ARRAY p_partition_ids LOOP
175175
END IF;
176176
END IF;
177177

178-
IF p_debug THEN
179-
RAISE NOTICE 'create_partition_id v_sql: %', v_sql;
180-
END IF;
178+
RAISE DEBUG 'create_partition_id v_sql: %', v_sql;
181179
EXECUTE v_sql;
182180

183181
IF v_partition_type = 'native' THEN
@@ -284,7 +282,8 @@ FOREACH v_id IN ARRAY p_partition_ids LOOP
284282
, p_inherit_fk := %L
285283
, p_epoch := %L
286284
, p_template_table := %L
287-
, p_jobmon := %L )'
285+
, p_jobmon := %L
286+
, p_start_partition := %L )'
288287
, v_parent_schema||'.'||v_partition_name
289288
, v_row.sub_control
290289
, v_row.sub_partition_type
@@ -295,7 +294,9 @@ FOREACH v_id IN ARRAY p_partition_ids LOOP
295294
, v_row.sub_inherit_fk
296295
, v_row.sub_epoch
297296
, v_row.sub_template_table
298-
, v_row.sub_jobmon);
297+
, v_row.sub_jobmon
298+
, p_start_partition);
299+
RAISE DEBUG 'create_partition_id (create_parent loop): %', v_sql;
299300
EXECUTE v_sql;
300301

301302
UPDATE @[email protected]_config SET
@@ -320,7 +321,7 @@ FOREACH v_id IN ARRAY p_partition_ids LOOP
320321
END LOOP; -- end sub partitioning LOOP
321322

322323
-- Manage additonal constraints if set
323-
PERFORM @[email protected]_constraints(p_parent_table, p_job_id := v_job_id, p_debug := p_debug);
324+
PERFORM @[email protected]_constraints(p_parent_table, p_job_id := v_job_id);
324325

325326
IF v_publications IS NOT NULL THEN
326327
-- NOTE: Publications currently not supported on parent table, but are supported on the table partitions if individually assigned.

sql/functions/create_partition_time.sql

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE FUNCTION @[email protected]_partition_time(p_parent_table text, p_partition_times timestamptz[], p_analyze boolean DEFAULT true, p_debug boolean DEFAULT false)
1+
CREATE FUNCTION @[email protected]_partition_time(p_parent_table text, p_partition_times timestamptz[], p_analyze boolean DEFAULT true, p_start_partition text DEFAULT NULL)
22
RETURNS boolean
33
LANGUAGE plpgsql
44
AS $$
@@ -123,9 +123,7 @@ v_partition_expression := CASE
123123
WHEN v_epoch = 'milliseconds' THEN format('to_timestamp((%I/1000)::float)', v_control)
124124
ELSE format('%I', v_control)
125125
END;
126-
IF p_debug THEN
127-
RAISE NOTICE 'create_partition_time: v_partition_expression: %', v_partition_expression;
128-
END IF;
126+
RAISE DEBUG 'create_partition_time: v_partition_expression: %', v_partition_expression;
129127

130128
FOREACH v_time IN ARRAY p_partition_times LOOP
131129
v_partition_timestamp_start := v_time;
@@ -221,9 +219,7 @@ FOREACH v_time IN ARRAY p_partition_times LOOP
221219
END IF;
222220
END IF;
223221

224-
IF p_debug THEN
225-
RAISE NOTICE 'create_partition_time v_sql: %', v_sql;
226-
END IF;
222+
RAISE DEBUG 'create_partition_time v_sql: %', v_sql;
227223
EXECUTE v_sql;
228224

229225

@@ -390,7 +386,8 @@ FOREACH v_time IN ARRAY p_partition_times LOOP
390386
, p_inherit_fk := %L
391387
, p_epoch := %L
392388
, p_template_table := %L
393-
, p_jobmon := %L )'
389+
, p_jobmon := %L
390+
, p_start_partition := %L )'
394391
, v_parent_schema||'.'||v_partition_name
395392
, v_row.sub_control
396393
, v_row.sub_partition_type
@@ -401,10 +398,10 @@ FOREACH v_time IN ARRAY p_partition_times LOOP
401398
, v_row.sub_inherit_fk
402399
, v_row.sub_epoch
403400
, v_row.sub_template_table
404-
, v_row.sub_jobmon);
405-
IF p_debug THEN
406-
RAISE NOTICE 'create_partition_time (create_parent loop): %', v_sql;
407-
END IF;
401+
, v_row.sub_jobmon
402+
, p_start_partition);
403+
404+
RAISE DEBUG 'create_partition_time (create_parent loop): %', v_sql;
408405
EXECUTE v_sql;
409406

410407
UPDATE @[email protected]_config SET
@@ -425,7 +422,7 @@ FOREACH v_time IN ARRAY p_partition_times LOOP
425422
END LOOP; -- end sub partitioning LOOP
426423

427424
-- Manage additonal constraints if set
428-
PERFORM @[email protected]_constraints(p_parent_table, p_job_id := v_job_id, p_debug := p_debug);
425+
PERFORM @[email protected]_constraints(p_parent_table, p_job_id := v_job_id);
429426

430427
IF v_publications IS NOT NULL THEN
431428
-- NOTE: Publications currently not supported on parent table, but are supported on the table partitions if individually assigned.
@@ -489,4 +486,3 @@ HINT: %', ex_message, ex_context, ex_detail, ex_hint;
489486
END
490487
$$;
491488

492-

sql/functions/create_sub_parent.sql

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ CREATE FUNCTION @[email protected]_sub_parent(
1111
, p_epoch text DEFAULT 'none'
1212
, p_upsert text DEFAULT ''
1313
, p_trigger_return_null boolean DEFAULT true
14-
, p_jobmon boolean DEFAULT true
15-
, p_debug boolean DEFAULT false)
14+
, p_jobmon boolean DEFAULT true)
1615
RETURNS boolean
1716
LANGUAGE plpgsql
1817
AS $$
@@ -198,10 +197,10 @@ LOOP
198197

199198
IF v_child_start_id IS NOT NULL THEN
200199
v_partition_id_array[0] := v_child_start_id;
201-
PERFORM @[email protected]_partition_id(p_top_parent, v_partition_id_array, true);
200+
PERFORM @[email protected]_partition_id(p_top_parent, v_partition_id_array, true, p_start_partition);
202201
ELSIF v_child_start_time IS NOT NULL THEN
203202
v_partition_time_array[0] := v_child_start_time;
204-
PERFORM @[email protected]_partition_time(p_top_parent, v_partition_time_array, true);
203+
PERFORM @[email protected]_partition_time(p_top_parent, v_partition_time_array, true, p_start_partition);
205204
END IF;
206205
ELSE
207206
SELECT a.attname
@@ -241,8 +240,7 @@ LOOP
241240
, p_upsert := %L
242241
, p_trigger_return_null := %L
243242
, p_template_table := %L
244-
, p_jobmon := %L
245-
, p_debug := %L )'
243+
, p_jobmon := %L)'
246244
, v_row.child_schema||'.'||v_row.child_tablename
247245
, p_control
248246
, p_type
@@ -256,8 +254,7 @@ LOOP
256254
, p_upsert
257255
, p_trigger_return_null
258256
, v_template_table
259-
, p_jobmon
260-
, p_debug);
257+
, p_jobmon);
261258
EXECUTE v_sql;
262259
END IF; -- end recreate check
263260

@@ -272,4 +269,3 @@ RETURN v_success;
272269
END
273270
$$;
274271

275-

0 commit comments

Comments
 (0)