Skip to content

Commit 0b6565a

Browse files
committed
v4.5.1 Fix security vulnerability and id sub-partitioning. See CHANGELOG for more details.
1 parent f0c1b58 commit 0b6565a

File tree

11 files changed

+2206
-21
lines changed

11 files changed

+2206
-21
lines changed

CHANGELOG.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
4.5.1
2+
NEW FEATURES
3+
============
4+
-- Allow relation options set on the template table to be inherited on the child table. As of PG13 and earlier, relation options set on the parent are not being set on the child tables. Unknown if PG14 will handle this yet or not (Github PR #348).
5+
6+
BUG FIXES
7+
=========
8+
-- Fixed security issue that could allow arbitrary code execution using SECURITY DEFINER functions. Set explicit search_path to avoid this. Thanks to Github user @tapioaiven of Aiven Ltd for reporting the issue.
9+
10+
-- Fixed several bugs in sub-partitioning when using a mixture of epoch and regular integer partitioning in the same partition set (Github Issue #357).
11+
12+
13+
114
4.5.0
215
NEW FEATURES
316
============

META.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "pg_partman",
33
"abstract": "Extension to manage partitioned tables by time or ID",
4-
"version": "4.5.0",
4+
"version": "4.5.1",
55
"maintainer": [
6-
"Keith Fiske <keith@omniti.com>"
6+
"Keith Fiske <keith@keithf4.com>"
77
],
88
"license": "postgresql",
99
"generated_by": "Keith Fiske",
@@ -20,19 +20,19 @@
2020
},
2121
"provides": {
2222
"pg_partman": {
23-
"file": "sql/pg_partman--4.5.0.sql",
23+
"file": "sql/pg_partman--4.5.1.sql",
2424
"docfile": "doc/pg_partman.md",
25-
"version": "4.5.0",
25+
"version": "4.5.1",
2626
"abstract": "Extension to manage partitioned tables by time or ID"
2727
}
2828
},
2929
"resources": {
3030
"bugtracker": {
31-
"web": "https://github.com/keithf4/pg_partman/issues"
31+
"web": "https://github.com/pgpartman/pg_partman/issues"
3232
},
3333
"repository": {
34-
"url": "git://github.com/keithf4/pg_partman.git" ,
35-
"web": "https://github.com/keithf4/pg_partman",
34+
"url": "git://github.com/pgpartman/pg_partman.git" ,
35+
"web": "https://github.com/pgpartman/pg_partman",
3636
"type": "git"
3737
}
3838
},

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.5.0'
1+
default_version = '4.5.1'
22
comment = 'Extension to manage partitioned tables by time or ID'
33
relocatable = false

sql/functions/check_name_length.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CREATE FUNCTION @[email protected]_name_length (p_object_name text, p_suffix text DEFAULT NULL, p_table_partition boolean DEFAULT FALSE) RETURNS text
22
LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER
3+
SET search_path TO pg_catalog, pg_temp
34
AS $$
45
DECLARE
56
v_new_length int;

sql/functions/create_parent.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ v_datetime_string text;
3232
v_default_partition text;
3333
v_higher_control_type text;
3434
v_higher_parent_control text;
35+
v_higher_parent_epoch text;
3536
v_higher_parent_schema text := split_part(p_parent_table, '.', 1);
3637
v_higher_parent_table text := split_part(p_parent_table, '.', 2);
3738
v_id_interval bigint;
@@ -562,8 +563,8 @@ IF v_control_type = 'id' AND p_epoch = 'none' THEN
562563
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
563564
WHERE n.nspname = v_higher_parent_schema::name
564565
AND c.relname = v_higher_parent_table::name
565-
) SELECT n.nspname, c.relname, p.control
566-
INTO v_higher_parent_schema, v_higher_parent_table, v_higher_parent_control
566+
) SELECT n.nspname, c.relname, p.control, p.epoch
567+
INTO v_higher_parent_schema, v_higher_parent_table, v_higher_parent_control, v_higher_parent_epoch
567568
FROM pg_catalog.pg_class c
568569
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
569570
JOIN top_oid t ON c.oid = t.top_parent_oid
@@ -572,7 +573,7 @@ IF v_control_type = 'id' AND p_epoch = 'none' THEN
572573
IF v_higher_parent_table IS NOT NULL THEN
573574
SELECT general_type INTO v_higher_control_type
574575
FROM @[email protected]_control_type(v_higher_parent_schema, v_higher_parent_table, v_higher_parent_control);
575-
IF v_higher_control_type <> 'id' THEN
576+
IF v_higher_control_type <> 'id' or (v_higher_control_type = 'id' AND v_higher_parent_epoch <> 'none') THEN
576577
-- The parent above the p_parent_table parameter is not partitioned by ID
577578
-- so don't check for max values in parents that aren't partitioned by ID.
578579
-- This avoids missing child tables in subpartition sets that have differing ID data

sql/functions/create_sub_parent.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ LOOP
176176
RAISE EXCEPTION 'Due to conflicting data boundaries between ISO weeks and any larger interval of time, pg_partman cannot support a sub-partition interval of weekly';
177177
END IF;
178178

179-
ELSIF v_control_parent_type = 'id' AND v_control_sub_type = 'id' THEN
179+
ELSIF v_control_parent_type = 'id' AND v_control_sub_type = 'id' AND v_parent_epoch = 'none' AND p_epoch = 'none' THEN
180180
IF p_interval::bigint >= v_parent_interval::bigint THEN
181181
EXECUTE format('SELECT set_config(%L, %L, %L)', 'search_path', v_old_search_path, 'false');
182182
RAISE EXCEPTION 'Sub-partition interval cannot be greater than or equal to the given parent interval';

sql/functions/inherit_template_properties.sql

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ v_inherit_fk boolean;
1414
v_parent_index_list record;
1515
v_parent_oid oid;
1616
v_parent_table text;
17+
v_relopt record;
1718
v_sql text;
1819
v_template_oid oid;
1920
v_template_schemaname text;
@@ -119,14 +120,14 @@ IF current_setting('server_version_num')::int >= 100000 THEN
119120

120121
IF v_parent_index_list.indisprimary AND v_index_list.indisprimary THEN
121122
IF v_parent_index_list.indkey_names = v_index_list.indkey_names THEN
122-
RAISE DEBUG 'Ignoring duplicate primary key on template table: % ', v_index_list.indkey_names;
123+
RAISE DEBUG 'inherit_template_properties: Ignoring duplicate primary key on template table: % ', v_index_list.indkey_names;
123124
v_dupe_found := true;
124125
CONTINUE; -- only continue within this nested loop
125126
END IF;
126127
END IF;
127128

128129
IF v_parent_index_list.statement = v_index_list.statement THEN
129-
RAISE DEBUG 'Ignoring duplicate index on template table: %', v_index_list.statement;
130+
RAISE DEBUG 'inherit_template_properties: Ignoring duplicate index on template table: %', v_index_list.statement;
130131
v_dupe_found := true;
131132
CONTINUE; -- only continue within this nested loop
132133
END IF;
@@ -147,7 +148,7 @@ IF current_setting('server_version_num')::int >= 100000 THEN
147148
IF v_index_list.tablespace_name IS NOT NULL THEN
148149
v_sql := v_sql || format(' USING INDEX TABLESPACE %I', v_index_list.tablespace_name);
149150
END IF;
150-
RAISE DEBUG 'Create pk: %', v_sql;
151+
RAISE DEBUG 'inherit_template_properties: Create pk: %', v_sql;
151152
EXECUTE v_sql;
152153
ELSE
153154
-- statement column should be just the portion of the index definition that defines what it actually is
@@ -156,7 +157,7 @@ IF current_setting('server_version_num')::int >= 100000 THEN
156157
v_sql := v_sql || format(' TABLESPACE %I', v_index_list.tablespace_name);
157158
END IF;
158159

159-
RAISE DEBUG 'Create index: %', v_sql;
160+
RAISE DEBUG 'inherit_template_properties: Create index: %', v_sql;
160161
EXECUTE v_sql;
161162

162163
END IF;
@@ -176,7 +177,7 @@ IF current_setting('server_version_num')::int >= 100000 AND current_setting('ser
176177
AND contype = 'f'
177178
LOOP
178179
v_sql := format('ALTER TABLE %I.%I ADD %s', v_child_schema, v_child_tablename, v_fk_list.constraint_def);
179-
RAISE DEBUG 'Create FK: %', v_sql;
180+
RAISE DEBUG 'inherit_template_properties: Create FK: %', v_sql;
180181
EXECUTE v_sql;
181182
END LOOP;
182183
END IF;
@@ -186,7 +187,7 @@ END IF;
186187
-- Tablespace inheritance on PG11 and earlier
187188
IF current_setting('server_version_num')::int < 120000 AND v_template_tablespace IS NOT NULL THEN
188189
v_sql := format('ALTER TABLE %I.%I SET TABLESPACE %I', v_child_schema, v_child_tablename, v_template_tablespace);
189-
RAISE DEBUG 'Alter tablespace: %', v_sql;
190+
RAISE DEBUG 'inherit_template_properties: Alter tablespace: %', v_sql;
190191
EXECUTE v_sql;
191192
END IF;
192193

@@ -206,14 +207,27 @@ AND c.relname = v_child_tablename::name;
206207

207208
IF v_template_unlogged = 'u' AND v_child_unlogged = 'p' THEN
208209
v_sql := format ('ALTER TABLE %I.%I SET UNLOGGED', v_child_schema, v_child_tablename);
209-
RAISE DEBUG 'Alter UNLOGGED: %', v_sql;
210+
RAISE DEBUG 'inherit_template_properties: Alter UNLOGGED: %', v_sql;
210211
EXECUTE v_sql;
211212
ELSIF v_template_unlogged = 'p' AND v_child_unlogged = 'u' THEN
212213
v_sql := format ('ALTER TABLE %I.%I SET LOGGED', v_child_schema, v_child_tablename);
213-
RAISE DEBUG 'Alter UNLOGGED: %', v_sql;
214+
RAISE DEBUG 'inherit_template_properties: Alter UNLOGGED: %', v_sql;
214215
EXECUTE v_sql;
215216
END IF;
216217

218+
-- Relation options are not being inherited for PG <= 13
219+
FOR v_relopt IN
220+
SELECT unnest(reloptions) as value
221+
FROM pg_catalog.pg_class
222+
WHERE oid = v_template_oid
223+
LOOP
224+
v_sql := format('ALTER TABLE %I.%I SET (%s)'
225+
, v_child_schema
226+
, v_child_tablename
227+
, v_relopt.value);
228+
RAISE DEBUG 'inherit_template_properties: Set relopts: %', v_sql;
229+
EXECUTE v_sql;
230+
END LOOP;
217231
RETURN true;
218232

219233
END

sql/tables/tables.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ CHECK (@[email protected]_automatic_maintenance_value(sub_automatic_maintenance))
142142
*/
143143
CREATE FUNCTION @[email protected]_epoch_type (p_type text) RETURNS boolean
144144
LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER
145+
SET search_path TO pg_catalog, pg_temp
145146
AS $$
146147
DECLARE
147148
v_result boolean;
@@ -165,6 +166,7 @@ CHECK (@[email protected]_epoch_type(sub_epoch));
165166
*/
166167
CREATE OR REPLACE FUNCTION @[email protected]_partition_type (p_type text) RETURNS boolean
167168
LANGUAGE plpgsql IMMUTABLE SECURITY DEFINER
169+
SET search_path TO pg_catalog, pg_temp
168170
AS $$
169171
DECLARE
170172
v_result boolean;
@@ -174,6 +176,7 @@ BEGIN
174176
END
175177
$$;
176178

179+
177180
ALTER TABLE @[email protected]_config
178181
ADD CONSTRAINT part_config_type_check
179182
CHECK (@[email protected]_partition_type(partition_type));

test/test_native/generated_col/test-time-daily-generated.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
-- ########## TIME DAILY TESTS ##########
22
-- Other tests:
3-
-- Test using default template table. Initial child tables will have no indexes. New tables after template has indexes added should.
3+
-- Test generated always columns
44

55
\set ON_ERROR_ROLLBACK 1
66
\set ON_ERROR_STOP true

0 commit comments

Comments
 (0)