Re: POC: enable logical decoding when wal_level = 'replica' without a server restart - Mailing list pgsql-hackers
From | Bertrand Drouvot |
---|---|
Subject | Re: POC: enable logical decoding when wal_level = 'replica' without a server restart |
Date | |
Msg-id | Z3fimYj0fbkLmWJb@ip-10-97-1-34.eu-west-3.compute.internal Whole thread Raw |
Responses |
Re: POC: enable logical decoding when wal_level = 'replica' without a server restart
|
List | pgsql-hackers |
Hi, On Mon, Dec 30, 2024 at 10:44:38PM -0600, Masahiko Sawada wrote: > Hi all, > > Logical decoding (and logical replication) are available only when > wal_level = logical. As the documentation says[1], Using the 'logical' > level increases the WAL volume which could negatively affect the > performance. For that reason, users might want to start with using > 'replica', but when they want to use logical decoding they need a > server restart to increase wal_level to 'logical'. My goal is to allow > users who are using 'replica' level to use logical decoding without a > server restart. Thanks for starting that thread and +1 for the idea! > The first idea I came up with is to make the wal_level a PGC_SIGHUP > parameter. However, it affects not only setting 'replica' to 'logical' > but also setting 'minimal' to 'replica' or higher. I'm not sure the > latter case is common and it might require a checkpoint. I don't want > to make the patch complex for uncommon cases. > > The second idea is to somehow allow both WAL-logging logical info and > logical decoding even when wal_level is 'replica'. I've attached a PoC > patch for that. The patch introduces new SQL functions such as > pg_activate_logical_decoding() and pg_deactivate_logical_decoding(). > These functions are available only when wal_level is 'repilca'(or > higher). In pg_activate_logical_decoding(), we set the status of > logical decoding stored on the shared memory from 'disabled' to > 'xlog-logical-info', allowing all processes to write logical > information to WAL records for logical decoding. But the logical > decoding is still not allowed. Once we confirm all in-progress > transactions completed, we switch the status to > 'logical-decoding-ready', meaning that users can create logical > replication slots and use logical decoding. > > Overall, with the patch, there are two ways to enable logical > decoding: setting wal_level to 'logical' and calling > pg_activate_logical_decoding() when wal_level is 'replica'. I left the > 'logical' level for backward compatibility and for users who want to > enable the logical decoding without calling that SQL function. If we > can automatically enable the logical decoding when creating the first > logical replication slot, probably we no longer need the 'logical' > level. There is room to discuss the user interface. Feedback is very > welcome. If we don't want to force wal_level = logical to enable logical decoding (your second idea) then I think that it would be better to "hide" everything behind logical replication slot creation / deletion. That would mean that having at least one logical replication slot created would be synonym to "activate logical decoding" and zero logical replication slot created would be synonym to "deactivate logical decoding". That way: 1. an end user don't need to manipulate new functions and would just rely on replication slots existence 2. we ensure that no extra WAL data is generated if not absolutely "needed" Thoughts? Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
pgsql-hackers by date: