Skip to content

Commit 20ca4d2

Browse files
committed
v4.0.0 Initial release for PG11 support. Major security requirement changes. See CHANGELOG for full details.
1 parent 79e0c48 commit 20ca4d2

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

doc/pg_partman.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ As a note for people that were not aware, you can name arguments in function cal
112112
* p_parent_table - the existing parent table. MUST be schema qualified, even if in public schema.
113113
* p_control - the column that the partitioning will be based on. Must be a time or integer based column.
114114
* p_type - one of the following values to set the partitioning type that will be used:
115+
+ **native**
116+
- Use the native partitioning methods that are built into PostgreSQL 10+.
117+
- For PG11+, it is highly recommended that native partitioning be used over trigger-based partitioning. PG10 is still lacking significant features for native partitioning, so please see notes above for more info.
118+
- Provides significantly better write & read performance than "partman" partitioning.
119+
- Child table creation is kept up to date by running `run_maintenance(_proc)`. There is no trigger maintenance.
115120
+ **partman**
116121
- Create a trigger-based partition set using pg_partman's method of partitioning.
117122
- Whether it is time or serial based is determined by the control column's data type and if the p_epoch flag is set.
@@ -120,10 +125,6 @@ As a note for people that were not aware, you can name arguments in function cal
120125
- Inserts to the parent table outside the optimize_trigger window will go to the proper child table if it exists, but performance will be degraded due to the higher overhead of handling that condition.
121126
- If the child table does not exist for the value given, the row will go to the parent.
122127
- Child table creation & trigger function is kept up to date by the `run_maintenance()` function.
123-
+ **native**
124-
- Use the native partitioning methods that are built into PostgreSQL 10+.
125-
- Provides significantly better write & read performance than "partman" partitioning, but does not have as much feature support. See notes above for more info.
126-
- Child table creation is kept up to date by the `run_maintenance()`. There is no trigger maintenance.
127128
* `p_interval` - the time or integer range interval for each partition. No matter the partitioning type, value must be given as text. The generic intervals of "yearly -> quarter-hour" are for time partitioning and giving one of these explicit values when using pg_partman's trigger-based partitioning will allow significantly better performance than using an arbitrary time interval. For native partitioning, any interval value is valid and will have the same performance which is always better than trigger-based.
128129
+ *yearly* - One partition per year
129130
+ *quarterly* - One partition per yearly quarter. Partitions are named as YYYYqQ (ex: 2012q4)
@@ -198,7 +199,8 @@ As a note for people that were not aware, you can name arguments in function cal
198199
* `p_source_table` - This option can be used when you need to move data into a natively partitioned set. Pass a schema qualified tablename to this parameter and any data in that table will be MOVED to the partition set designated by p_parent_table, creating any child tables as needed.
199200
* Returns the number of rows that were moved from the parent table to partitions. Returns zero when parent table is empty and partitioning is complete.
200201

201-
*`partition_data_proc (p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_source_table text DEFAULT NULL, p_order text DEFAULT 'ASC', p_lockwait int DEFAULT 0, p_lockwait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)`*
202+
203+
*`partition_data_proc (p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_source_table text DEFAULT NULL, p_order text DEFAULT 'ASC', p_lock_wait int DEFAULT 0, p_lock_wait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)`*
202204

203205
* A procedure that can partition data in distinct commit batches to avoid long running transactions and data contention issues.
204206
* Only works with PostgreSQL 11+
@@ -209,6 +211,8 @@ As a note for people that were not aware, you can name arguments in function cal
209211
* `p_wait` - Cause the procedure to pause for a given number of seconds between commits (batches) to reduce write load
210212
* `p_source_table` - Same as the p_source_table option in the called partitioning function.
211213
* `p_order` - Allows you to specify the order that data is migrated from the parent/default to the children, either ascending (ASC) or descending (DESC). Default is ASC.
214+
* `p_lock_wait` - Parameter passed directly through to the underlying partition_data_*() function. Number of seconds to wait on rows that may be locked by another transaction. Default is to wait forever (0).
215+
* `p_lock_wait_tries` - Parameter to set how many times the procedure will attempt waiting the amount of time set for p_lock_wait. Default is 10 tries.
212216
* `p_quiet` - Procedures cannot return values, so by default it emmits NOTICE's to show progress. Set this option to silence these notices.
213217

214218
*`create_partition_time(p_parent_table text, p_partition_times timestamptz[], p_analyze boolean DEFAULT true, p_debug boolean DEFAULT false) RETURNS boolean`*
@@ -268,7 +272,7 @@ As a note for people that were not aware, you can name arguments in function cal
268272
*`run_maintenance_proc(p_wait int DEFAULT 0, p_analyze boolean DEFAULT NULL, p_jobmon boolean DEFAULT true, p_debug boolean DEFAULT false)`*
269273

270274
* For PG11+, this is the preferred method to run partition maintenance vs directly calling the run_maintenance() function.
271-
* This procedure can be called instead of the `run_maintenance()` function to cause PostgreSQL to commit after each partition set's maintenance has finished. This reduces contention issues with long running transactions when there are many partition sets to maintain.
275+
* This procedure can be called instead of the `run_maintenance()` function to cause PostgreSQL to commit after each partition set's maintenance has finished. This greatly reduces contention issues with long running transactions when there are many partition sets to maintain.
272276
* `p_wait` - How many seconds to wait between each partition set's maintenance run. Defaults to 0.
273277
* `p_analyze` - See p_analyze option in run_maintenance.
274278

@@ -376,7 +380,7 @@ undo_partition(p_parent_table text, p_batch_count int DEFAULT 1, p_batch_interva
376380
* Returns the number of partitions undone and the number of rows moved to the parent table. The partitions undone value returns -1 if a problem is encountered.
377381

378382

379-
*`undo_partition_proc(p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_target_table text DEFAULT NULL, p_keep_table boolean DEFAULT true, p_lockwait int DEFAULT 0, p_lockwait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)`*
383+
*`@extschema@.undo_partition_proc(p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_target_table text DEFAULT NULL, p_keep_table boolean DEFAULT true, p_lock_wait int DEFAULT 0, p_lock_wait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)`*
380384

381385
* A procedure that can un-partition data in distinct commit batches to avoid long running transactions and data contention issues.
382386
* Only works with PostgreSQL 11+
@@ -387,6 +391,8 @@ undo_partition(p_parent_table text, p_batch_count int DEFAULT 1, p_batch_interva
387391
* `p_wait` - Cause the procedure to pause for a given number of seconds between commits (batches) to reduce write load
388392
* `p_target_table` - Same as the p_target_table option in the undo_partition() function.
389393
* `p_keep_table` - Same as the p_keep_table option in the undo_partition() function.
394+
* `p_lock_wait` - Parameter passed directly through to the underlying partition_data_*() function. Number of seconds to wait on rows that may be locked by another transaction. Default is to wait forever (0).
395+
* `p_lock_wait_tries` - Parameter to set how many times the procedure will attempt waiting the amount of time set for p_lock_wait. Default is 10 tries.
390396
* `p_quiet` - Procedures cannot return values, so by default it emmits NOTICE's to show progress. Set this option to silence these notices.
391397

392398

sql/procedures/partition_data_proc.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE PROCEDURE @[email protected]_data_proc (p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_source_table text DEFAULT NULL, p_order text DEFAULT 'ASC', p_lockwait int DEFAULT 0, p_lockwait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)
1+
CREATE PROCEDURE @[email protected]_data_proc (p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_source_table text DEFAULT NULL, p_order text DEFAULT 'ASC', p_lock_wait int DEFAULT 0, p_lock_wait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)
22
LANGUAGE plpgsql
33
AS $$
44
DECLARE
@@ -67,7 +67,7 @@ END IF;
6767
*/
6868

6969
v_sql := format('SELECT %I.partition_data_%s (%L, p_lock_wait := %L, p_order := %L, p_analyze := false'
70-
, '@extschema@', v_control_type, p_parent_table, p_lockwait, p_order);
70+
, '@extschema@', v_control_type, p_parent_table, p_lock_wait, p_order);
7171
IF p_interval IS NOT NULL THEN
7272
v_sql := v_sql || format(', p_batch_interval := %L', p_interval);
7373
END IF;
@@ -86,7 +86,7 @@ LOOP
8686
v_lockwait_count := 0;
8787
ELSE
8888
v_lockwait_count := v_lockwait_count + 1;
89-
IF v_lockwait_count > p_lockwait_tries THEN
89+
IF v_lockwait_count > p_lock_wait_tries THEN
9090
RAISE EXCEPTION 'Quitting due to inability to get lock on next batch of rows to be moved';
9191
END IF;
9292
END IF;

sql/procedures/undo_partition_proc.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CREATE PROCEDURE @[email protected]_partition_proc(p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_target_table text DEFAULT NULL, p_keep_table boolean DEFAULT true, p_lockwait int DEFAULT 0, p_lockwait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)
1+
CREATE PROCEDURE @[email protected]_partition_proc(p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_target_table text DEFAULT NULL, p_keep_table boolean DEFAULT true, p_lock_wait int DEFAULT 0, p_lock_wait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)
22
LANGUAGE plpgsql
33
AS $$
44
DECLARE
@@ -70,7 +70,7 @@ END IF;
7070
*/
7171

7272
v_sql := format('SELECT partitions_undone, rows_undone FROM %I.undo_partition (%L, p_keep_table := %L, p_lock_wait := %L'
73-
, '@extschema@', p_parent_table, p_keep_table, p_lockwait);
73+
, '@extschema@', p_parent_table, p_keep_table, p_lock_wait);
7474
IF p_interval IS NOT NULL THEN
7575
v_sql := v_sql || format(', p_batch_interval := %L', p_interval);
7676
END IF;
@@ -90,7 +90,7 @@ LOOP
9090
v_lockwait_count := 0;
9191
ELSE
9292
v_lockwait_count := v_lockwait_count + 1;
93-
IF v_lockwait_count > p_lockwait_tries THEN
93+
IF v_lockwait_count > p_lock_wait_tries THEN
9494
RAISE EXCEPTION 'Quitting due to inability to get lock on next batch of rows to be moved';
9595
END IF;
9696
END IF;

updates/pg_partman--3.2.1--4.0.0.sql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ IF current_setting('server_version_num')::int >= 110000 THEN
6868

6969
-- Syntax check during extension updating doesn't even allow the CREATE PROCEDURE statement to exist. Using dollar quoting w/ EXECUTE to get around it in this conditional IF block.
7070
v_partition_data_sql := $partition_data$
71-
CREATE PROCEDURE @[email protected]_data_proc (p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_source_table text DEFAULT NULL, p_order text DEFAULT 'ASC', p_lockwait int DEFAULT 0, p_lockwait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)
71+
CREATE PROCEDURE @[email protected]_data_proc (p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_source_table text DEFAULT NULL, p_order text DEFAULT 'ASC', p_lock_wait int DEFAULT 0, p_lock_wait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)
7272
LANGUAGE plpgsql
7373
AS $$
7474
DECLARE
@@ -137,7 +137,7 @@ END IF;
137137
*/
138138

139139
v_sql := format('SELECT %I.partition_data_%s (%L, p_lock_wait := %L, p_order := %L, p_analyze := false'
140-
, '@extschema@', v_control_type, p_parent_table, p_lockwait, p_order);
140+
, '@extschema@', v_control_type, p_parent_table, p_lock_wait, p_order);
141141
IF p_interval IS NOT NULL THEN
142142
v_sql := v_sql || format(', p_batch_interval := %L', p_interval);
143143
END IF;
@@ -156,7 +156,7 @@ LOOP
156156
v_lockwait_count := 0;
157157
ELSE
158158
v_lockwait_count := v_lockwait_count + 1;
159-
IF v_lockwait_count > p_lockwait_tries THEN
159+
IF v_lockwait_count > p_lock_wait_tries THEN
160160
RAISE EXCEPTION 'Quitting due to inability to get lock on next batch of rows to be moved';
161161
END IF;
162162
END IF;
@@ -214,7 +214,7 @@ EXECUTE v_partition_data_sql;
214214

215215

216216
v_undo_partition_sql := $undo_partition$
217-
CREATE PROCEDURE @[email protected]_partition_proc(p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_target_table text DEFAULT NULL, p_keep_table boolean DEFAULT true, p_lockwait int DEFAULT 0, p_lockwait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)
217+
CREATE PROCEDURE @[email protected]_partition_proc(p_parent_table text, p_interval text DEFAULT NULL, p_batch int DEFAULT NULL, p_wait int DEFAULT 1, p_target_table text DEFAULT NULL, p_keep_table boolean DEFAULT true, p_lock_wait int DEFAULT 0, p_lock_wait_tries int DEFAULT 10, p_quiet boolean DEFAULT false)
218218
LANGUAGE plpgsql
219219
AS $$
220220
DECLARE
@@ -286,7 +286,7 @@ END IF;
286286
*/
287287

288288
v_sql := format('SELECT partitions_undone, rows_undone FROM %I.undo_partition (%L, p_keep_table := %L, p_lock_wait := %L'
289-
, '@extschema@', p_parent_table, p_keep_table, p_lockwait);
289+
, '@extschema@', p_parent_table, p_keep_table, p_lock_wait);
290290
IF p_interval IS NOT NULL THEN
291291
v_sql := v_sql || format(', p_batch_interval := %L', p_interval);
292292
END IF;
@@ -306,7 +306,7 @@ LOOP
306306
v_lockwait_count := 0;
307307
ELSE
308308
v_lockwait_count := v_lockwait_count + 1;
309-
IF v_lockwait_count > p_lockwait_tries THEN
309+
IF v_lockwait_count > p_lock_wait_tries THEN
310310
RAISE EXCEPTION 'Quitting due to inability to get lock on next batch of rows to be moved';
311311
END IF;
312312
END IF;

0 commit comments

Comments
 (0)