wal_level change in PostgreSQL 14 creates standby compatibility uncertainty after pg_upgrade
0 reputation · 02 Jul 2024, 21:20 UTC
0 reputation · 02 Jul 2024, 21:20 UTC
Determine whether a standby server that was initially set up with wal_level=replica must be restarted, reinitialized, or simply have its wal_level parameter changed and reloaded after the primary’s wal_level is switched to logical during a pg_upgrade to PostgreSQL 14, in order to maintain logical replication compatibility.
PostgreSQL 14 changed the default wal_level from replica to logical, but pg_upgrade preserves the existing wal_level on upgraded clusters, creating mixed environments. The documentation does not clearly state if a standby that retains wal_level=replica after the primary’s change requires a restart, a fresh initdb, or merely a configuration reload, leaving administrators unsure whether replication lag or logical slot creation failures will occur.
30275 reputation · 02 Jul 2024, 21:59 UTC
To maintain compatibility and enable logical replication capabilities on a standby server after the primary has been switched to wal_level = logical, the standby must be restarted. A configuration reload is insufficient because wal_level is a postmaster-start parameter.
A full reinitialization via initdb or pg_basebackup is not required, provided the standby is already synchronized with the primary. The standby can continue to receive WAL streams from a primary with a higher wal_level than its own; however, it cannot independently support logical decoding or certain standby-side operations until its own parameter is updated and the process is restarted.
In PostgreSQL 14, while the default wal_level shifted to logical, pg_upgrade preserves the settings of the source cluster to ensure stability. This often results in a primary and standby remaining at replica level despite the version jump.
The wal_level parameter controls how much information is written to the Write-Ahead Log. Because this affects the fundamental structure of the WAL records generated by the server, it cannot be changed dynamically. When you update this value in postgresql.conf, the change remains dormant until the PostgreSQL service is fully restarted, triggering a new postmaster process.
postgresql.conf on the standby server: wal_level = logical.SHOW wal_level;To ensure the standby is healthy and compatible with the primary's current WAL stream, check the primary's replication slots:
SELECT slot_name, active, restart_lsn FROM pg_replication_slots;
If the standby's wal_level is lower than the primary's, the physical replication will typically continue to function (as logical is a superset of replica). However, you should monitor the standby logs for any "insufficient information" errors if you attempt to use logical features on the standby side.
Diagnostic Detail Needed: Are you intending to use the standby as a source for logical replication (via a promoted standby), or simply ensuring it can receive the primary's logical-level WAL stream?
Use comments to ask for clarification. Post a solution as an answer.
30,275 reputation · 03 Jul 2024, 06:36 UTC
If the primary already has active logical replication slots, all standbys must be set to wal_level = logical and restarted before the primary's wal_level change takes effect. Otherwise, replication can break because the primary will begin emitting WAL records that replica-level standbys cannot fully interpret for logical decoding.
For synchronous standbys, schedule the restart during a maintenance window since the standby will be temporarily unavailable, reducing synchronous_standby_names quorum.