Skip to content

Commit 0a5611a

Browse files
feat(rdb): logical replication
1 parent 1f2ac31 commit 0a5611a

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
meta:
3+
title: Setting up logical replication as a subscriber in PostgreSQL
4+
description: Learn how to set up and use logical replication as a subscriber in PostgreSQL to migrate your database with zero downtime
5+
content:
6+
h1: Setting up logical replication as a subscriber in PostgreSQL
7+
paragraph: This page explains how to set up and use logical replication as a subscriber in PostgreSQL to migrate your database to Scaleway, with zero downtime and real-time data synchronization
8+
tags: postgresql logical replication subscriber migration database
9+
dates:
10+
validation: 2025-02-20
11+
posted: 2025-02-20
12+
---
13+
14+
The logical replication of databases as a subscriber is available with PostgreSQL 16, which is now supported in Scaleway's Managed Databases for PostgreSQL.
15+
16+
The feature allows you to replicate data from one database to another in real-time, without having to replicate the entire database, and keep them in sync, without having to take the original database offline or lock it for an extended period.
17+
18+
Logical replication is especially useful when migrating your databases to Scaleway's Managed Databases.
19+
20+
By setting up the new database as a subscriber to the original database you can ensure:
21+
- **Zero-downtime migration** - Migrate your data without taking the original database offline. Your applications can continue to write data to the original database while the new database is being populated.
22+
- **Real-time data synchronization** - The subscriber database receives updates in real-time, ensuring that data is consistent between the two databases.
23+
- **Flexible migration window** - You can choose when to switch your application to the new database, without having to worry about data consistency as logical replication ensures that the new database is always up-to-date with the latest changes from the original database.
24+
- **Easy rollback** - If something goes wrong during the migration, such as data corruption, application issues, or other problems, you can point your application back to the original database. Because the subscriber database has been keeping a copy of the data in sync with the publisher, you can avoid data loss or inconsistencies.
25+
26+
27+
## How to set up the subscription
28+
29+
To be able to create a subscription, you must have the privileges of the the pg_create_subscription role, as well as CREATE privileges on the current database.
30+
31+
32+
```
33+
CREATE SUBSCRIPTION subscription_name
34+
CONNECTION 'conninfo'
35+
PUBLICATION publication_name [, ...]
36+
[ WITH ( subscription_parameter [= value] [, ... ] ) ]
37+
```
38+
39+
<Message type="important">
40+
Subscriptions in the same database cannot have the same name.
41+
</Message>
42+
43+
44+
How to set it up:
45+
See  https://www.postgresql.org/docs/16/sql-createsubscription.html to create a subscription on a Managed PostgreSQL and this example:
46+
47+
GRANT pg_create_subscription TO myuser;
48+
CREATE SUBSCRIPTION mysub CONNECTION 'host=212.47.254.155 port=5432 user=repli password=XXXXXXXXX dbname=postgres application_name=mysub' PUBLICATION mypub;
49+
50+
# Get subscription stats
51+
GRANT pg_read_all_stats TO myuser;
52+
SELECT * FROM pg_stat_subscription;
53+
54+
# Get subscription configuration
55+
GRANT pg_read_all_data TO myuser;
56+
SELECT * FROM pg_subscription;
57+
58+
See https://www.postgresql.org/docs/16/sql-createpublication.html on how to set up a publication on your publisher database
59+
60+
Number of subscriptions that can be created per offer: see https://confluence.infra.online.net/spaces/RDB/pages/254436279/Postgres+Logical+Replication#PostgresLogicalReplication-UpdatePostgresQLsettingsbynodetype. From that table, we only want to show the "Node type" and "scw.pg_create_subscription_threshold" (renamed "Max number of subscriptions" in our documentation page) columns.
61+
Messaging to be worked on how to be transparent on this section: https://confluence.infra.online.net/spaces/RDB/pages/254436279/Postgres+Logical+Replication#PostgresLogicalReplication-SubscriptionandpublicIP
62+
63+

0 commit comments

Comments
 (0)