Replicating postgres partitioned tables v7
Both PostgreSQL and EDB Postgres Advanced Server support partitioned tables, which you can replicate with Replication Server in either a single-master or multi-master replication system.
The following are the partitioning techniques:
- EDB Postgres Advanced Server partitioning compatible with Oracle databases
- Postgres declarative partitioning (applies to both PostgreSQL and EDB Postgres Advanced Server version 10 and later)
- Postgres table inheritance (applies to both PostgreSQL and EDB Postgres Advanced Server)
If you're using EDB Postgres Advanced Server, you can create partitioned tables using the CREATE TABLE
statement with partitioning syntax compatible with Oracle databases. For information on partitioning compatible with Oracle databases, see Database Compatibility
Table Partitioning Guide.
If you're using version 10 or later of PostgreSQL or EDB Postgres Advanced Server, you can use declarative partitioning to create partitioned tables. The CREATE TABLE
syntax for creating a declarative partitioned table is similar to the partitioning compatible with Oracle databases. However, you must create the individual partitions of the declarative partitioned table separately with their own CREATE TABLE
statements.
For information on declarative partitioning and table inheritance, see the [PostgreSQL core documentation] (https://www.postgresql.org/docs/current/static/ddl-partitioning.html).
Regardless of the partitioning method, the resulting partitioned table is made up of a parent table with a set of child tables.
You can accomplish replication of these Postgres partitioned tables in a single-master or multi-master replication system in the same manner.
Note the following general restrictions when the publication contains a partitioned table:
- You can't use SQL Server as a subscription database.
- When using table inheritance, the subscription databases must be Postgres. They can't be Oracle or SQL Server.
All three partitioning techniques are shown on the emp table. The partitioned table is then used in a publication of a multi-master replication system in the following sections:
- For creating a publication in Postgres 9.x, see Creating a Postgres 9.x partitioned table publication.
- For creating a publication in Postgres 10 or later, see Creating a Postgres version 10 or later partitioned table publication.
The following creates the partitioned table in EDB Postgres Advanced Server using partitioning compatible with Oracle databases:
The following creates the partitioned table in PostgreSQL or EDB Postgres Advanced Server 10 or later using declarative partitioning:
Note
When creating a declarative partitioned table to replicate using Replication Server, you must include the PRIMARY KEY
in the CREATE TABLE
statements of the individual partitions, not in the CREATE TABLE
statement of the parent table being partitioned.
The following creates the partitioned table in PostgreSQL or EDB Postgres Advanced Server using table inheritance:
The following shows the types of SQL queries that you can make on the parent and child tables to show which tables contain the rows.
Querying the parent table, emp, with the asterisk appended to the table name in the SELECT statement
, shows the rows in the parent and child tables. This is the default behavior if the asterisk is omitted.
The following queries show how the rows are physically divided among the child tables. The use of the ONLY
keyword results in rows only in the specified table of the SELECT
statement and not from any of its children.
Creating a Postgres version 10 or later partitioned table publication shows creating the publication when using partitioning compatible with Oracle databases or declarative partitioning on a Postgres 10 or later database server.
Creating a Postgres version 10 or later partitioned table publication
Create the publication using either partitioning compatible with Oracle databases or Postgres declarative partitioning on a Postgres 10 or later database server.
Note
If you're using table inheritance, you must use the process described in Creating a Postgres 9.x partitioned table publication even when creating the publication on a Postgres 10 or later database server.
The following restrictions apply when the publication contains a table with partitioning compatible with Oracle databases or declarative partitioning:
- You must select the log-based method of synchronization replication for the publication database. You can't use the trigger-based method.
- In a single-master replication system, the subscription databases must be Postgres version 10 or later. You can't use Oracle and SQL Server as a subscription database.
- In a multi-master replication system, all primary nodes must be Postgres version 10 or later with the same compatibility mode as the primary definition node (that is, either compatible with native PostgreSQL or compatible with Oracle databases). For more information on the multi-master replication system compatibility modes, see Permitted MMR database server configurations.
Follow the steps in Creating a publication to create a primary definition node along with a publication containing the partitioned table. (For a single-master replication system, create the publication database along with the publication following the steps in Creating a publication.)
When creating the publication, only the parent table appears and is selected.
The following shows the resulting replication tree for the partitioned table in the primary definition node:
Create more primary nodes as described in Creating more primary nodes. (For a single-master replication system, create the subscription database and subscription following the steps in Creating a subscription.)
The following shows the resulting multi-master replication system after you add another primary node.
You can now keep the partitioned table synchronized on the primary nodes of the multi-master replication system.