PostgreSQL configuration for BDR v4
Several PostgreSQL configuration parameters affect BDR nodes. You can set these parameters differently on each node, although that isn't generally recommended.
PostgreSQL settings for BDR
BDR requires these PostgreSQL settings to run correctly:
wal_level
— Must be set tological
, since BDR relies on logical decoding.shared_preload_libraries
— Must containbdr
, although it can contain other entries before or after, as needed. However, don't includepglogical
.track_commit_timestamp
— Must be set toon
for conflict resolution to retrieve the timestamp for each conflicting row.
BDR requires these PostgreSQL settings to be set to appropriate values, which vary according to the size and scale of the cluster.
logical_decoding_work_mem
— Memory buffer size used by logical decoding. Transactions larger than this overflow the buffer and are stored temporarily on local disk. Default is 64 MB, but you can set it much higher.max_worker_processes
— BDR uses background workers for replication and maintenance tasks, so you need enough worker slots for it to work correctly. The formula for the correct minimal number of workers, for each database, is:- One per PostgreSQL instance plus
- One per database on that instance plus
- Four per BDR-enabled database plus
- One per peer node in the BDR group plus
- One for each writer-enabled per peer node in the BDR group You might need more worker processes temporarily when a node is being removed from a BDR group.
max_wal_senders
— Two needed per every peer node.max_replication_slots
— Same asmax_wal_senders
.wal_sender_timeout
andwal_receiver_timeout
— Determines how quickly a node considers its CAMO partner as disconnected or reconnected. See CAMO failure scenarios for details.
In normal running for a group with N peer nodes, BDR requires N slots and WAL senders. During synchronization, BDR temporarily uses another N - 1 slots and WAL senders, so be careful to set the parameters high enough for this occasional peak demand.
max_replication_slots
sets the maximum number of replication origins.
Some of the functionality of parallel apply uses an extra origin per writer.
Hence, when parallel apply is enabled, you must set the max_replication_slots
to
N * (number of writers)
plus the number of slots needed for peak demand as described in the previous paragraph.
When the decoding worker is enabled, this process requires one extra replication slot per BDR group.
Changing these parameters requires restarting the local node:
max_worker_processes
, max_wal_senders
, max_replication_slots
.
You might also want your applications to set these parameters. See Durability and performance options for details.
synchronous_commit
— Affects the durability and performance of BDR replication. in a similar way to physical replication.synchronous_standby_names
— Same as above.
BDR-specific settings
You can also set BDR-specific configuration settings. Unless noted otherwise, you can set the values at any time.
Conflict handling
bdr.default_conflict_detection
— Sets the default conflict detection method for newly created tables. Accepts same values as bdr.alter_table_conflict_detection().
Global sequence parameters
bdr.default_sequence_kind
— Sets the default sequence kind. The default value isdistributed
, which meanssnowflakeid
is used forint8
sequences (i.e.,bigserial
) andgalloc
sequence forint4
(i.e.,serial
) andint2
sequences.
DDL handling
bdr.default_replica_identity
— Sets the default value forREPLICA IDENTITY
on newly created tables. TheREPLICA IDENTITY
defines the information written to the write-ahead log to identify rows that are updated or deleted.The accepted values are:
DEFAULT
— Records the old values of the columns of the primary key, if any (this is the default PostgreSQL behavior).FULL
— Records the old values of all columns in the row.NOTHING
— Records no information about the old row.
See PostgreSQL documentation for more details.
BDR can't replicate
UPDATE
andDELETE
operations on tables without aPRIMARY KEY
orUNIQUE
constraint. The exception is when the replica identity for the table isFULL
, either by table-specific configuration or bybdr.default_replica_identity
.If
bdr.default_replica_identity
isDEFAULT
and there is aUNIQUE
constraint on the table, it isn't automatically picked up asREPLICA IDENTITY
. You need to set it explicitly when creating the table or after, as described above.Setting the replica identity of tables to
FULL
increases the volume of WAL written and the amount of data replicated on the wire for the table.bdr.ddl_replication
— Automatically replicate DDL across nodes (default ison
).This parameter can be set only by bdr_superuser or superuser roles.
Running DDL or calling BDR administration functions with
bdr.ddl_replication = off
can create situations where replication stops until an administrator can intervene. See DDL replication for details.A
LOG
-level log message is emitted to the PostgreSQL server logs wheneverbdr.ddl_replication
is set tooff
. Additionally, aWARNING-level
message is written whenever replication of captured DDL commands or BDR replication functions is skipped due to this setting.bdr.role_replication
— Automatically replicate ROLE commands across nodes (default ison
). Only a superuser can set this parameter. This setting works only ifbdr.ddl_replication
is turned on as well.Turning this off without using external methods to ensure roles are in sync across all nodes might cause replicated DDL to interrupt replication until the administrator intervenes.
See Role manipulation statements for details.
bdr.ddl_locking
— Configures the operation mode of global locking for DDL.This parameter can be set only by bdr_superuser or superuser roles.
Possible options are:
- off — Don't use global locking for DDL operations.
- on — Use global locking for all DDL operations.
- dml — Use global locking only for DDL operations that need to prevent writes by taking the global DML lock for a relation.
A
LOG
-level log message is emitted to the PostgreSQL server logs wheneverbdr.ddl_replication
is set tooff
. Additionally, aWARNING
message is written whenever any global locking steps are skipped due to this setting. It's normal for some statements to result in twoWARNING
messages: one for skipping the DML lock and one for skipping the DDL lock.bdr.truncate_locking
— False by default, this configuration option sets the TRUNCATE command's locking behavior. Determines whether (when true) TRUNCATE obeys thebdr.ddl_locking
setting.
Global locking
bdr.ddl_locking
— Described above.bdr.global_lock_max_locks
— Maximum number of global locks that can be held on a node (default 1000). Can be set only at Postgres server start.bdr.global_lock_timeout
— Sets the maximum allowed duration of any wait for a global lock (default 10 minutes). A value of zero disables this timeout.bdr.global_lock_statement_timeout
— Sets the maximum allowed duration of any statement holding a global lock (default 60 minutes). A value of zero disables this timeout.bdr.global_lock_idle_timeout
— Sets the maximum allowed duration of idle time in transaction holding a global lock (default 10 minutes). A value of zero disables this timeout.bdr.predictive_checks
— Log level for predictive checks (currently used only by global locks). Can beDEBUG
,LOG
,WARNING
(default), orERROR
. Predictive checks are early validations for expected cluster state when doing certain operations. You can use them for those operations for fail early rather than wait for timeouts. In global lock terms, BDR checks that there are enough nodes connected and withing reasonable lag limit for getting quorum needed by the global lock.
Node management
bdr.replay_progress_frequency
— Interval for sending replication position info to the rest of the cluster (default 1 minute).bdr.standby_slot_names
— Require these slots to receive and confirm replication changes before any other ones. This setting is useful primarily when using physical standbys for failover or when using subscribe-only nodes.
Generic replication
bdr.writers_per_subscription
— Default number of writers per subscription (in BDR, you can also change this withbdr.alter_node_group_config
for a group).bdr.max_writers_per_subscription
— Maximum number of writers per subscription (sets upper limit for the setting above).bdr.xact_replication
— Replicate current transaction (default ison
).Turning this off makes the whole transaction local only, which means the transaction isn't visible to logical decoding by BDR and all other downstream targets of logical decoding. Data isn't transferred to any other node, including logical standby nodes.
This parameter can be set only by the bdr_superuser or superuser roles.
This parameter can be set only inside the current transaction using the
SET LOCAL
command unlessbdr.permit_unsafe_commands = on
.
Note
Even with transaction replication disabled, WAL is generated, but those changes are filtered away on the origin.
Warning
Turning off bdr.xact_replication
leads to data
inconsistency between nodes. Use it only to recover from
data divergence between nodes or in
replication situations where changes on single nodes are required for
replication to continue. Use at your own risk.
bdr.permit_unsafe_commands
— Option to override safety check on commands that are deemed unsafe for general use.Requires
bdr_superuser
or PostgreSQL superuser.
Warning
The commands that are normally not considered safe can either produce inconsistent results or break replication altogether. Use at your own risk.
bdr.batch_inserts