Autopartition v5.8.1
Autopartition allows you to split tables into several partitions. For more information, see Scaling.
bdr.autopartition
The bdr.autopartition function configures automatic RANGE partitioning of a table.
Synopsis
bdr.autopartition(relation regclass, partition_increment text, partition_initial_lowerbound text DEFAULT NULL, partition_autocreate_expression text DEFAULT NULL, minimum_advance_partitions integer DEFAULT 2, maximum_advance_partitions integer DEFAULT 5, data_retention_period interval DEFAULT NULL, managed_locally boolean DEFAULT true, enabled boolean DEFAULT on, analytics_offload_period);
Parameters
relation— Name or Oid of a table.partition_increment— Interval or increment to next partition creation.partition_initial_lowerbound— If the table has no partition, then the first partition with this lower bound andpartition_incrementapart upper bound is created.partition_autocreate_expression— The expression used to detect if it's time to create new partitions.minimum_advance_partitions— The system attempts to always have at leastminimum_advance_partitionspartitions.maximum_advance_partitions— Number of partitions to create in a single go after the number of advance partitions falls belowminimum_advance_partitions.data_retention_period— Interval until older partitions are dropped, if defined. This value must be greater thanmigrate_after_period.managed_locally— Whether partitions are managed locally. Setting this tofalseis not recommended.enabled— Allows activity to be disabled or paused and later resumed or reenabled.analytics_offload_period— Provides support for partition offloading. Reserved for future use.
Examples
Daily partitions, keep data for one month:
CREATE TABLE measurement ( logdate date not null, peaktemp int, unitsales int ) PARTITION BY RANGE (logdate); bdr.autopartition('measurement', '1 day', data_retention_period := '30 days');
Create five advance partitions when only two more partitions remain. Each partition can hold 1 billion orders.
bdr.autopartition('Orders', '1000000000', partition_initial_lowerbound := '0', minimum_advance_partitions := 2, maximum_advance_partitions := 5 );
bdr.drop_autopartition
Use bdr.drop_autopartition() to drop the autopartitioning rule for the
given relation. All pending work items for the relation are deleted, and no new
work items are created.
bdr.drop_autopartition(relation regclass);
Parameters
relation— Name or Oid of a table.
bdr.autopartition_wait_for_partitions
Partition creation is an asynchronous process. AutoPartition provides a set of functions to wait for the partition to be created, locally or on all nodes.
Use bdr.autopartition_wait_for_partitions() to wait for the creation of
partitions on the local node. The function takes the partitioned table name and
a partition key column value and waits until the partition that holds that
value is created.
The function waits only for the partitions to be created locally. It doesn't guarantee that the partitions also exists on the remote nodes.
To wait for the partition to be created on all PGD nodes, use the
bdr.autopartition_wait_for_partitions_on_all_nodes() function. This function
internally checks local as well as all remote nodes and waits until the
partition is created everywhere.