Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
title: Setting up logical replication as a publisher in PostgreSQL
description: Learn how to set up and use logical replication as a publisher in PostgreSQL
tags: postgresql logical replication publisher migration database
dates:
validation: 2025-08-25
posted: 2025-02-20
---
import Requirements from '@macros/iam/requirements.mdx'

The logical replication of databases as a publisher is available with [PostgreSQL 17](/managed-databases-for-postgresql-and-mysql/reference-content/pg-version-updates#postgresql-17), which is supported in Scaleway's Managed Databases for PostgreSQL.

The feature allows you to replicate data from a managed PostgreSQL to another Database Instance (a Managed PostgreSQL in another region, for example).

Replication slots can be created with the `failover` flag, which ensures that replication slots survive failovers. When a secondary node is promoted to primary, the replication slot is automatically available on the new main node.

<Requirements />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- A [Database Instance](/managed-databases-for-postgresql-and-mysql/how-to/create-a-database/) running PostgreSQL 17

## Configuring advanced settings and user rights

As the service uses physical replication to provide High Availability, some parameters must be enabled to allow the logical replication to remain active after the promotion of a secondary node, without disturbing the HA setup. It is essential to ensure these setting are enabled as even Database Instances with in standalone mode can be replaced with temporary replicas.

The [replication slot](https://www.postgresql.org/docs/17/logicaldecoding-explanation.html#LOGICALDECODING-REPLICATION-SLOTS) is an important part of the logical replication. Each subscription receives changes via one replication slot created on the "publishing" node. You have one replication slot available per logical database.

To use replication, users must also have the corresponding rights.

Follow the steps in the [How to configure advanced settings](/managed-databases-for-postgresql-and-mysql/how-to/configure-advanced-settings) documentation page to configure the following settings:

To enable logical replication, you must:

- Enable the `rdb.enable_logical_replication` setting. This automatically changes the `wal_level` settings to `logical`.
- Set `hot_standby_feedback` to `ON`
- Set `sync_replication_slots` to `ON`

Follow the steps in the [How to manage users](/managed-databases-for-postgresql-and-mysql/how-to/manage-users) documentation page to attribute user rights.

To create publications and replication slots, the `replication_user` must:

- Either be an admin user (`rdb_admin`)
- Or be granted the following rights from an `rdb_admin`:
- `ALTER replication_user with REPLICATION`
- `GRANT CREATE ON DATABASE my_database TO my_replication_user;`

## Setting up logical replication

We use an example scenario to show how logical replication can be set up.

1. Create the table and publication on the publisher database.
```sql
CREATE TABLE mytable (id INTEGER PRIMARY KEY, val TEXT);
CREATE PUBLICATION pub FOR TABLE mytable;
```
2. Insert a sample row into the table. This ensures there's data to test the replication with.
```sql
INSERT INTO mytable VALUES (1, 'foo');
```
3. Create the same table structure on the subscriber database. Leave the table empty, as data will be copied into it upon subscription.
```sql
CREATE TABLE mytable (id INTEGER PRIMARY KEY, val TEXT);
```
4. Create a subscription. Two methods are available:
- **Direct subscription with failover** - use this method if your environment supports the failover option in `CREATE SUBSCRIPTION`
- **Creating a replication slot manually on the publisher** -

<Tabs>
<TabsTab label="Set up direct subscription">
```sql
CREATE SUBSCRIPTION sub CONNECTION 'host=myhost port=myport user=myuser dbname=mydb password=mypassword' PUBLICATION pub WITH (failover);
```
</TabsTab>
<TabsTab label="Create replication slot manually">
Some environments do not allow `CREATE SUBSCRIPTION` to auto-create slots due to permissions or configuration. In this case, you can create a slot with failover manually.
1. Create a replication slot on the publisher database.
```sql
SELECT pg_create_logical_replication_slot('sub', 'pgoutput', false, false, true);
```
<Message type="note">
The last `true` in the command above enables the `failover` flag.
</Message>
2. Create the subscription without creating a slot.
```sql
CREATE SUBSCRIPTION sub CONNECTION 'host=myhost port=myport user=myuser dbname=mydb password=mypassword' PUBLICATION pub WITH (enabled=true, create_slot=false, slot_name='sub');
```
<Message type="note">
Refer to the [PostgreSQL documentation](https://www.postgresql.org/docs/current/functions-admin.html#FUNCTIONS-REPLICATION) for more information about `pg_create_logical_replication_slot()`.
</Message>
</TabsTab>
</Tabs>

5. Query the publisher table in the subscriber to test the replication.
```sql
SELECT * FROM mytable;
```

## Limitations

- 100 replication slots are available for each Database Instance.
- 25 out of the 100 slots are reserved for Scaleway's internal systems.
- During the synchronization phase, 2 or more slots might be needed for a subscription.
<Message type="important">
- If you need more than 50 replication slots, [create a support ticket](https://console.scaleway.com/support).
- If the limit is exceeded, your Managed Database service may become compromised.
</Message>

<Message type="tip">
Run the following command to get a list of your replication slots:
```sql
SELECT * FROM pg_replication_slots where slot_type = 'logical';
```
And the following command to check publications:
```sql
SELECT * from pg_publication;
```
</Message>

- If a logical replication is not active but still consumed by a subscription or other tool, PostgreSQL WAL files will accumulate in the primary node, filling up storage. In the worst case scenario, your database can be set to read only mode (check disk full section).
<Message type="tip">
- We recommend you delete any replications that are no longer used.
- If a logical replication is inactive for 24h, it will be automatically removed.
</Message>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dates:
validation: 2025-08-25
posted: 2025-02-20
---
import Requirements from '@macros/iam/requirements.mdx'

The logical replication of databases as a subscriber is available with [PostgreSQL 16](/managed-databases-for-postgresql-and-mysql/reference-content/pg-version-updates#postgresql-16), which is now supported in Scaleway's Managed Databases for PostgreSQL.

Expand All @@ -23,6 +24,11 @@ By setting up the new database as a subscriber to the original database you can
- **Flexible migration windows** - You can choose when to switch your application to the new database, without having to worry about data consistency. Logical replication ensures that the new database is always up-to-date with the latest changes in the original database.
- **Easy rollback** - If you encounter issues during migration, such as data corruption and application issues, you can point your application back to the original database. Since the subscriber database constantly keeps a copy of the data in sync with the publisher, you can avoid data loss or inconsistencies.

<Requirements />

- A Scaleway account logged into the [console](https://console.scaleway.com)
- [Owner](/iam/concepts/#owner) status or [IAM permissions](/iam/concepts/#permission) allowing you to perform actions in the intended Organization
- A [Database Instance](/managed-databases-for-postgresql-and-mysql/how-to/create-a-database/) running PostgreSQL 16 or a higher version

## How to set up the subscription

Expand Down
4 changes: 4 additions & 0 deletions pages/managed-databases-for-postgresql-and-mysql/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ export const managedDatabasesForPostgresqlAndMysqlMenu = {
label: 'Setting up logical replication as a subscriber',
slug: 'logical-replication-as-subscriber',
},
{
label: 'Setting up logical replication as a publisher',
slug: 'logical-replication-as-publisher',
},
{
label:
'Connecting Managed Databases to Kubernetes clusters',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,45 @@ dates:

This page lists updates for PostreSQL versions and their corresponding features that are supported at Scaleway.

## PostgreSQL 17

Find below the features and updates available with PostgreSQL 17.

### Roles

The `RDB` admin role can now assign the following predefined roles:

| Role | Description |
| :--- | :--- |
| `pg_maintain` | Allows executing `VACUUM`, `ANALYZE`, `CLUSTER`, `REFRESH MATERIALIZED VIEW`, `REINDEX`, and `LOCK TABLE` on all relations, simulating `MAINTAIN` rights on those objects, even without having it explicitly. |

### Features

New features are available with PostgreSQL 17:

- The logical [replication of databases as a publisher](/managed-databases-for-postgresql-and-mysql/api-cli/logical-replication-as-publisher) is now supported.

### Extensions

- **PostGIS** - [3.5](https://postgis.net/tags/3.5/)
- **Timescale** - [2.2](https://github.com/timescale/timescaledb/releases/tag/2.21.4)
- **pgRouting** - [3.7.3](https://github.com/pgRouting/pgrouting/releases/tag/v3.7.3)
- **pgvector** - [0.8.1](https://github.com/pgvector/pgvector/releases/tag/v0.8.1)
- **H3 PG** - [4.2.3](https://github.com/zachasme/h3-pg/releases/tag/v4.2.3)

### Advanced settings

These are the new advanced settings available with PostgreSQL 17:

- `allow_alter_system`

Refer to the official [Server configuration](https://www.postgresql.org/docs/17/runtime-config-compatible.html) PostgreSQL documentation for more information.

## PostgreSQL 16

Find below the new features and updates available with PostgreSQL 16.

## Roles
### Roles

The `RDB` admin role can now assign the following predefined roles:

Expand All @@ -32,15 +66,15 @@ The `RDB` admin role can now assign the following predefined roles:
Refer to the official [Predefined Roles](https://www.postgresql.org/docs/16/predefined-roles.html) PostgreSQL documentation for a more detailed description of the roles above.
</Message>

## Features
### Features

New features are available with PostgreSQL 16:

- The logical replication of databases as a subscriber is now supported. Refer to the [Setting up logical replication as a subscriber in PostgreSQL](/managed-databases-for-postgresql-and-mysql/api-cli/logical-replication-as-subscriber) documentation page for more information.
- Passwords are now encrypted using the `SCRAM-SHA-256` setting. If you upgrade your engine and are currently using MD5, you also have to migrate to SCRAM-SHA-256. Refer to the official [Password Authentication](https://www.postgresql.org/docs/current/auth-password.html#AUTH-PASSWORD) PostgreSQL documentation to learn how to do so.
- Support of the Timescale [pre-restore](https://docs.timescale.com/api/latest/administration/#timescaledb_pre_restore) and [post-restore](https://docs.timescale.com/api/latest/administration/#timescaledb_post_restore) features. They allow you to restore the database using `pg_restore`.

## Extensions
### Extensions

The following extensions were also upgraded.

Expand All @@ -51,11 +85,11 @@ The following extensions were also upgraded.
- **pgvector** - [0.8.0](https://github.com/pgvector/pgvector/releases/tag/v0.8.0)
- **H3 PG** - [4.1.4](https://github.com/zachasme/h3-pg/releases/tag/v4.1.4)

## Advanced settings
### Advanced settings

These are the new advanced settings available with PostgreSQL 16:

### Autovaccum
#### Autovaccum

- `autovacuum_vacuum_insert_scale_factor`
- `autovacuum_vacuum_insert_threshold`
Expand All @@ -64,7 +98,7 @@ These are the new advanced settings available with PostgreSQL 16:

Refer to the official [Autovaccum](https://www.postgresql.org/docs/16/routine-vacuuming.html#AUTOVACUUM) PostgreSQL documentation for more information.

### Error reporting and logging
#### Error reporting and logging

- `cron.timezone`
- `log_checkpoints`
Expand All @@ -75,7 +109,7 @@ Refer to the official [Autovaccum](https://www.postgresql.org/docs/16/routine-va

Refer to the official [Error reporting and logging](https://www.postgresql.org/docs/16/runtime-config-logging.html) PostgreSQL documentation for more information.

### PG stats parameters
#### PG stats parameters

- `pg_stat_statements.max`
- `pg_stat_statements.track`
Expand Down