Replicating Partitioned Tables
You can use Spock to replicate partitioned tables; by default, when adding a partitioned table to a replication set, it will include all of its current partitions. If you add partitions later, you will need to use the partition_add
function to add them to your replication sets. The DDL for the partitioned and partitions must be present on the subscriber nodes (like a non-partitioned table).
When you remove a partitioned table from a replication set, by default, the partitions of the table will also be removed.
Replication of partitioned tables is a bit different from normal tables. When doing initial synchronization, we query the partitioned table (or parent) to get all the rows for synchronization purposes and don't synchronize the individual partitions. After the initial sync of data, the normal operations resume and the partitions start replicating like normal tables.
If you add individual partitions to the replication set, they will be replicated like regular tables (to the table of the same name as the partition on the subscriber). This has performance advantages when partitioning definition is the same on both provider and subscriber, as the partitioning logic does not have to be executed.
Note: There is an exception to individual partition replication: individual partitions won't sync up the existing data. It's equivalent to setting synchronize_data = false
.
When partitions are replicated through a partitioned table, the exception is the TRUNCATE
command which always replicates with the list of affected tables or partitions.
Additionally, row_filter
can also be used with partitioned tables, as well as with individual partitions.