How to Use Logical Replication in pgAdmin4

October 07, 2021

Basic idea

Logical replication follows a publish and subscribe model. In a publisher node, a publication is created, which is a set of changes from a table or a group of tables. In a subscriber node, a subscription is created, which can subscribe to one or more publications.

But why logical replication? Well in traditional replication, the standby server is a bit for bit copy of the leader server but what if you want to copy only some data? Logical replication gives you that flexibility of what should be sent and where to send the data.


How to use logical replication in pgAdmin 4

To use logical replication, you need to connect to the database and you will see two nodes—publication and subscription.
PGAdmin Database list



You can create a publisher using a publication node.

PG Admin creating a publication screens
PGAdmin creating a publication screenshot 2

You can define the publication by giving it a name and then specifying whether you want to publish the data of all the tables. Instead of publishing all the tables, we can also specify a certain set of tables to publish. Not only that, but a publication can choose to limit the changes they publish to any combination of INSERT, UPDATE, DELETE, and TRUNCATE operations.



You can define the subscription by giving the name and connection details. You can also define whether you want to go for SSL or standard connection to connect to the publisher server. 
Then, specify the publications to get the data from. You can subscribe to multiple publications.

Creating a subscription in PGAdmin screenshot
Creating a subscription in PGAdmin screenshot 2

Next, specify the SSL configuration details if you wish to use SSL security for connection with the publisher server. Then you can specify some optional configuration settings, like whether you want to enable or disable the subscription or whether you want to create a slot or not. You can specify the slot name of your choice, but if you choose not to it will default to a subscription name as slot name. Finally, click on the save button to create a subscription.

Creating a Subscription SSL Tab screenshot

Creating a Subscription With tab screenshotPGADmin creating a subscription SQL view

This creates a new subscription subscription1 which will start replicating tables that are part of the publication1 publication. And that’s all that’s needed to get basic replication working. By default, the new subscription will also copy any preexisting data in those tables but you can disable this using the Copy data clause. Note that the definition of the table is not copied at this time, so we need to create the tables ourselves, as the replication worker will produce an error if it can’t find the table locally.

Each subscriber can subscribe to multiple publications, and each publication can publish changes to multiple subscribers. The column names must match, but the order of the columns in the subscriber table don't matter. Additionally, there can be the same or more number of columns in a subscribed table.


Limitation of logical replication

Logical replication has some limitations on which the community is continuously working to overcome. Tables must have the same full qualified name between publication and subscription. Tables must have a primary key or unique key. Bi-directional Replication is not supported and does not replicate schema/DDL. Subscriptions can have more columns or a different order of columns, but the types and column names must match between Publication and Subscription. Superuser privileges are required to add all tables.



Getting logical replication into PostgreSQL was a large undertaking. Logical replication is a very useful feature used to replicate part of data or all data to a replica server from a leader. You can also specify on which action it should replicate the data. You can replicate data between different major versions of PostgreSQL/EDB Postgres Advanced Server. You can send incremental changes in a single database or a subset of a database to other databases.

Read more: How to Get the Most Out of the Schema Diff Tool in pgAdmin 4

Share this

Relevant Blogs

Finding memory leaks in Postgres C code

I spent the last week looking for a memory leak in Postgres’s WAL Sender process. I spent a few days getting more acquainted with Valgrind and gcc/clang sanitizers, but ultimately...
March 27, 2024

Exploring EDB SPL Check: A New Feature in EPAS 16

EDB Postgres Advanced Server (EPAS) has introduced a highly anticipated feature called EDB SPL Check in its 16th version. This extension is a boon for developers working with Stored Procedure...
December 18, 2023

More Blogs

AI, Postgres and You: A Vision for the Future

Let's talk about something I'm very excited about: tech. We’ve all seen tech inventions rise and fall fast in IT, and it's difficult to predict which inventions will make it...
November 14, 2023