You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: contrib/pg_pathman/README.md
+37-17Lines changed: 37 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,12 @@
5
5
6
6
The `pg_pathman` module provides optimized partitioning mechanism and functions to manage partitions.
7
7
8
-
The extension is compatible with PostgreSQL 9.5 (9.6 support is coming soon).
8
+
The extension is compatible with PostgreSQL 9.5+.
9
9
10
10
## Overview
11
11
**Partitioning** means splitting one large table into smaller pieces. Each row in such table is moved to a single partition according to the partitioning key. PostgreSQL supports partitioning via table inheritance: each partition must be created as a child table with CHECK CONSTRAINT. For example:
12
12
13
-
```
13
+
```plpgsql
14
14
CREATETABLEtest (id SERIALPRIMARY KEY, title TEXT);
15
15
CREATETABLEtest_1 (CHECK ( id >=100AND id <200 )) INHERITS (test);
16
16
CREATETABLEtest_2 (CHECK ( id >=200AND id <300 )) INHERITS (test);
@@ -25,7 +25,7 @@ VARIABLE OP CONST
25
25
```
26
26
where `VARIABLE` is a partitioning key, `OP` is a comparison operator (supported operators are =, <, <=, >, >=), `CONST` is a scalar value. For example:
27
27
28
-
```
28
+
```plpgsql
29
29
WHERE id =150
30
30
```
31
31
@@ -36,6 +36,22 @@ Based on the partitioning type and condition's operator, `pg_pathman` searches f
36
36
37
37
More interesting features are yet to come. Stay tuned!
38
38
39
+
## Feature highlights
40
+
41
+
* HASH and RANGE partitioning schemes;
42
+
* Both automatic and manual partition management;
43
+
* Support for integer, floating point, date and other types, including domains;
44
+
* Effective query planning for partitioned tables (JOINs, subselects etc);
45
+
*`RuntimeAppend` & `RuntimeMergeAppend` custom plan nodes to pick partitions at runtime;
46
+
*`PartitionFilter`: an efficient drop-in replacement for INSERT triggers;
47
+
* Automatic partition creation for new INSERTed data (only for RANGE partitioning);
48
+
* Improved `COPY FROM\TO` statement that is able to insert rows directly into partitions;
49
+
* UPDATE triggers generation out of the box (will be replaced with custom nodes too);
50
+
* User-defined callbacks for partition creation event handling;
51
+
* Non-blocking concurrent table partitioning;
52
+
* FDW support (foreign partitions);
53
+
* Various GUC toggles and configurable settings.
54
+
39
55
## Roadmap
40
56
41
57
* Implement LIST partitioning scheme;
@@ -75,15 +91,15 @@ Performs HASH partitioning for `relation` by integer key `attribute`. The `parti
75
91
create_range_partitions(relation REGCLASS,
76
92
attribute TEXT,
77
93
start_value ANYELEMENT,
78
-
interval ANYELEMENT,
79
-
count INTEGER DEFAULT NULL
94
+
p_interval ANYELEMENT,
95
+
p_countINTEGER DEFAULT NULL
80
96
partition_data BOOLEAN DEFAULT TRUE)
81
97
82
98
create_range_partitions(relation REGCLASS,
83
99
attribute TEXT,
84
100
start_value ANYELEMENT,
85
-
interval INTERVAL,
86
-
count INTEGER DEFAULT NULL,
101
+
p_interval INTERVAL,
102
+
p_countINTEGER DEFAULT NULL,
87
103
partition_data BOOLEAN DEFAULT TRUE)
88
104
```
89
105
Performs RANGE partitioning for `relation` by partitioning key `attribute`. `start_value` argument specifies initial value, `interval` sets the range of values in a single partition, `count` is the number of premade partitions (if not set then pathman tries to determine it based on attribute values). Partition creation callback is invoked for each partition if set beforehand.
Performs RANGE-partitioning from specified range for `relation` by partitioning key `attribute`. Partition creation callback is invoked for each partition if set beforehand.
107
123
108
124
### Data migration
109
125
110
126
```plpgsql
111
-
partition_table_concurrently(relation REGCLASS)
127
+
partition_table_concurrently(relation REGCLASS,
128
+
batch_size INTEGER DEFAULT 1000,
129
+
sleep_time FLOAT8 DEFAULT 1.0)
112
130
```
113
-
Starts a background worker to move data from parent table to partitions. The worker utilizes short transactions to copy small batches of data (up to 10K rows per transaction) and thus doesn't significantly interfere with user's activity.
131
+
Starts a background worker to move data from parent table to partitions. The worker utilizes short transactions to copy small batches of data (up to 10K rows per transaction) and thus doesn't significantly interfere with user's activity. If the worker is unable to lock rows of a batch, it sleeps for `sleep_time` seconds before the next attempt and tries again up to 60 times, and quits if it's still unable to lock the batch.
114
132
115
133
```plpgsql
116
134
stop_concurrent_part_task(relation REGCLASS)
@@ -130,25 +148,25 @@ Same as above, but for a RANGE-partitioned table.
130
148
### Post-creation partition management
131
149
```plpgsql
132
150
split_range_partition(partition REGCLASS,
133
-
value ANYELEMENT,
151
+
split_value ANYELEMENT,
134
152
partition_name TEXT DEFAULT NULL)
135
153
```
136
-
Split RANGE `partition` in two by `value`. Partition creation callback is invoked for a new partition if available.
154
+
Split RANGE `partition` in two by `split_value`. Partition creation callback is invoked for a new partition if available.
Merge two adjacent RANGE partitions. First, data from `partition2` is copied to `partition1`, then `partition2` is removed.
142
160
143
161
```plpgsql
144
-
append_range_partition(p_relation REGCLASS,
162
+
append_range_partition(parent REGCLASS,
145
163
partition_name TEXT DEFAULT NULL,
146
164
tablespace TEXT DEFAULT NULL)
147
165
```
148
166
Append new RANGE partition with `pathman_config.range_interval` as interval.
149
167
150
168
```plpgsql
151
-
prepend_range_partition(p_relation REGCLASS,
169
+
prepend_range_partition(parent REGCLASS,
152
170
partition_name TEXT DEFAULT NULL,
153
171
tablespace TEXT DEFAULT NULL)
154
172
```
@@ -462,6 +480,8 @@ NOTICE: 100 rows copied from part_test_2
462
480
(3 rows)
463
481
```
464
482
483
+
- You can turn foreign tables into partitions using the `attach_range_partition()` function. Rows that were meant to be inserted into parent will be redirected to foreign partitions (as usual, PartitionFilter will be involved), though by default it is prohibited to insert rows into partitions provided not by `postgres_fdw`. Only superuser is allowed to set `pg_pathman.insert_into_fdw` GUC variable.
484
+
465
485
### HASH partitioning
466
486
Consider an example of HASH partitioning. First create a table with some integer column:
467
487
```plpgsql
@@ -587,7 +607,7 @@ EXPLAIN SELECT * FROM journal WHERE dt >= '2015-06-01' AND dt < '2015-06-03';
587
607
### Disabling `pg_pathman`
588
608
There are several user-accessible [GUC](https://www.postgresql.org/docs/9.5/static/config-setting.html) variables designed to toggle the whole module or specific custom nodes on and off:
0 commit comments