While a hallmark feature of PostgreSQL is streaming replication, sometimes data demands a more refined and adaptable replication approach to address different requirements. Logical replication offers a distinct advantage over traditional streaming replication by providing a more detailed and selective approach to data replication, enabling organizations to replicate specific tables selectively and even filter out particular types of data.

In this blog post, we will look into the steps of transforming an existing PostgreSQL streaming replication node into a logical replication node. This method facilitates a smooth transition to logical replication without the need to start from scratch, allowing organizations to harness the enhanced capabilities of logical replication effectively.

Pre-requisites

To switch from the current streaming replication to logical replication, confirm that the primary node fulfills the following prerequisites:

  • Set the wal_level to logical.
  • Adjust max_replication_slots and max_wal_senders as needed.
  • Ensure all tables have a replica identity set.

 Steps to convert streaming replication to logical replication:

The lab setup includes two servers: primary (172.31.46.28) and standby (172.31.39.50), currently configured with streaming replication. The following steps will guide the transition from streaming to logical replication. 

1. Verify that the current streaming replication setup is synchronized and that there is no lag between the primary and standby nodes.

2. Create a logical replication slot on the primary node.

3. Create publication for tables on the primary node.

4. Next, promote the intended standby node to a standalone node.

5. Review the PostgreSQL log file on the promoted standby server and take note of the Log Sequence Number (LSN) associated with the “redo done at” message. In the below log file, the LSN is 0/7000640.

The log entry “redo done at 0/7000640” provides details about the most recently applied transaction location. We utilize this Log Sequence Number (LSN) to progress the logical replication slot created in step two. Consequently, transactions occurring after this point will be applied to the newly promoted node.

6. On the primary server, advance the logical replication slot created in step two.

7. On the standby server, create the subscription for the publication created in step three.

8. At this stage, logical replication will commence, which can be verified by inspecting the replication status on the primary server.

9. It’s important to remove the current physical replication slot to avoid filling up the primary server’s disk.

The steps covered in this process make the transition to logical replication smoother, allowing for selective replication and improved data management across different parts of your database system. This change provides more control over how you manage and share data within PostgreSQL.

Percona Distribution for PostgreSQL provides the best and most critical enterprise components from the open-source community, in a single distribution, designed and tested to work together.

 

Download Percona Distribution for PostgreSQL Today!

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Arnaud Adant

does that support DDL operations ?

Lalit Choudhary

No, PostgreSQL Logical replication has this limitation: Database schema and DDL commands are not replicated.