Hi @ Nemanja Simpraga
Yes, Azure Database for PostgreSQL Flexible Server supports logical replication, which allows you to replicate data to a custom PostgreSQL server outside of Azure. Logical replication works by using publications and subscriptions, meaning your Azure PostgreSQL server can act as a publisher, and your external PostgreSQL server can act as a subscriber.
Steps to enable logical replication:
Enable logical replication by setting the wal_level parameter to logical in your Azure PostgreSQL Flexible Server.
Grant replication permissions to the admin user with ALTER ROLE <adminname> WITH REPLICATION;.
Create a publication on your Azure PostgreSQL Flexible Server using:
CREATE PUBLICATION my_publication FOR TABLE my_table;
Set up a subscription on your external PostgreSQL server:
CREATE SUBSCRIPTION my_subscription CONNECTION 'host=<azure_server> dbname=<dbname> user=<user> password=<password>' PUBLICATION my_publication;
Ensure replication slots are properly configured to stream change
Read-Only Replica on Local System:
Since logical replication only replicates data changes, the external PostgreSQL server will need to enforce read-only access manually. You can achieve this by:
- Using database permissions (REVOKE INSERT, UPDATE, DELETE ON ALL TABLES).
Running the replica in a read-only mode using default_transaction_read_only = on.
Please go through these documentations that might help you:
https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-logical
Hope this helps. Do let us know if you any further queries.