Autopartition v5
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
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_increment
apart 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_partitions
partitions.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
— If true, then the partitions are managed locally.enabled
— Allows activity to be disabled or paused and later resumed or reenabled.
Examples
Daily partitions, keep data for one month:
Create five advance partitions when only two more partitions remain. Each partition can hold 1 billion orders.
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.
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.
Synopsis
Parameters
relation
— Name or Oid of a table.upperbound
— Partition key column value.
bdr.autopartition_wait_for_partitions_on_all_nodes
Synopsis
Parameters
relation
— Name or Oid of a table.upperbound
— Partition key column value.
bdr.autopartition_find_partition
Use the bdr.autopartition_find_partition()
function to find the partition for the
given partition key value. If partition to hold that value doesn't exist, then
the function returns NULL. Otherwise Oid of the partition is returned.
Synopsis
Parameters
relname
— Name of the partitioned table.searchkey
— Partition key value to search.
bdr.autopartition_enable
Use bdr.autopartition_enable
to enable AutoPartitioning on the given table.
If AutoPartitioning is already enabled, then no action occurs. See
bdr.autopartition_disable
to disable AutoPartitioning on the given table.
Synopsis
Parameters
relname
— Name of the relation to enable AutoPartitioning.
bdr.autopartition_disable
Use bdr.autopartition_disable
to disable AutoPartitioning on the given table.
If AutoPartitioning is already disabled, then no action occurs.
Synopsis
Parameters
relname
— Name of the relation to disable AutoPartitioning.
Internal functions
bdr.autopartition_create_partition
AutoPartition uses an internal function
bdr.autopartition_create_partition
to create a standalone
AutoPartition on the parent table.
Synopsis
Parameters
relname
— Name or Oid of the parent table to attach to.partname