Decoding worker v5.6
PGD provides an option to enable a decoding worker process that performs decoding once, no matter how many nodes are sent data. This option introduces a new process, the WAL decoder, on each PGD node. One WAL sender process still exists for each connection, but these processes now just perform the task of sending and receiving data. Taken together, these changes reduce the CPU overhead of larger PGD groups and also allow higher replication throughput since the WAL sender process now spends more time on communication.
Enabling
enable_wal_decoder
is an option for each PGD group, which is currently
disabled by default. You can use bdr.alter_node_group_option()
to enable or
disable the decoding worker for a PGD group.
When the decoding worker is enabled, PGD stores logical change record (LCR)
files to allow buffering of changes between decoding and when all
subscribing nodes received data. LCR files are stored under the
pg_logical
directory in each local node's data directory. The number and
size of the LCR files varies as replication lag increases, so this process also
needs monitoring. The LCRs that aren't required by any of the PGD nodes are cleaned
periodically. The interval between two consecutive cleanups is controlled by
bdr.lcr_cleanup_interval
, which defaults to 3 minutes. The cleanup is
disabled when bdr.lcr_cleanup_interval
is 0.
Disabling
When disabled, logical decoding is performed by the WAL sender process for each node subscribing to each node. In this case, no LCR files are written.
Even though the decoding worker is enabled for a PGD group, following GUCs control the production and use of LCR per node.
By default these are false
.
For production and use of LCRs, enable the decoding worker for the PGD group and set these GUCs to true
on each of the nodes in the PGD group.
bdr.enable_wal_decoder
— Whenfalse
, all WAL senders using LCRs restart to use WAL directly. Whentrue
along with the PGD group config, a decoding worker process is started to produce LCR and WAL senders that use LCR.bdr.receive_lcr
— Whentrue
on the subscribing node, it requests WAL sender on the publisher node to use LCRs if available.
Notes
As of now, a decoding worker decodes changes corresponding to the node where it's running. A logical standby is sent changes from all the nodes in the PGD group through a single source. Hence a WAL sender serving a logical standby currently can't use LCRs.
A subscriber-only node receives changes from respective nodes directly. Hence a WAL sender serving a subscriber-only node can use LCRs.
Even though LCRs are produced, the corresponding WALs are still retained similar to the case when a decoding worker isn't enabled. In the future, it might be possible to remove WAL corresponding the LCRs, if they aren't otherwise required.
LCR file names
For reference, the first 24 characters of an LCR file name are similar to those in a WAL file name. The first 8 characters of the name are currently all '0'. In the future, they're expected to represent the TimeLineId similar to the first 8 characters of a WAL segment file name. The following sequence of 16 characters of the name is similar to the WAL segment number, which is used to track LCR changes against the WAL stream.
However, logical changes are reordered according to the commit order of the transactions they belong to. Hence their placement in the LCR segments doesn't match the placement of corresponding WAL in the WAL segments.
The set of the last 16 characters represents the subsegment number in an LCR segment.
Each LCR file corresponds to a subsegment.
LCR files are binary and variable sized.
You can control the maximum size of an LCR file by adjusting bdr.max_lcr_segment_file_size
, which defaults to 1 GB.
Using with transaction streaming
It's possible to enable transaction streaming and the decoding worker at the same time. Transaction streaming means that the WAL sender can send a partial transaction before it commits, reducing replication lag. The WAL decoder now supports the decoding of partial transactions, so the decoding worker can decode the partial transaction and store it in an LCR file. The LCR file is then used to apply the transaction on the subscriber node. This in turn reduces CPU usage, by reducing the lag, and reduces disk space usages, since ".spill" files aren't generated.
The WAL decoder always streams the transactions to LCRs but based on downstream request the WAL sender either stream transaction or just mimics a normal BEGIN..COMMIT
scenario.
To support this feature, the system creates additional streaming files. These files have names in that begin with STR_TXN_<file-name-format>
and CAS_TXN_<file-name-format>
and each streamed transaction creates their own pair.
To enable transaction streaming with the WAL decoder, set the PGD group's bdr.streaming_mode
set to ‘default’ using bdr.alter_node_group_option
and set the node's bdr.default_streaming_mode
to auto
.
- On this page
- Enabling
- Disabling
- LCR file names