BDR system functions v4
Perform BDR management primarily by using functions you call from SQL.
All functions in BDR are exposed in the bdr
schema. Schema qualify any calls to these
functions instead of putting bdr
in the
search_path
.
Version information functions
bdr.bdr_version
This function retrieves the textual representation of the BDR version currently in use.
bdr.bdr_version_num
This function retrieves the BDR version number that is currently in use. Version numbers are monotonically increasing, allowing this value to be used for less-than and greater-than comparisons.
The following formula returns the version number consisting of major version, minor version, and patch release into a single numerical value:
System information functions
bdr.get_relation_stats
Returns the relation information.
bdr.get_subscription_stats
Returns the current subscription statistics.
System and progress information parameters
BDR exposes some parameters that you can query using SHOW
in psql
or using PQparameterStatus
(or equivalent) from a client
application.
bdr.local_node_id
When you initialize a session, this is set to the node id the client is connected to. This allows an application to figure out the node it's connected to, even behind a transparent proxy.
It's also used with Connection pools and proxies.
bdr.last_committed_lsn
After every COMMIT
of an asynchronous transaction, this parameter is updated to
point to the end of the commit record on the origin node. Combining it with bdr.wait_for_apply_queue
,
allows applications
to perform causal reads across multiple nodes, that is, to wait until a transaction
becomes remotely visible.
transaction_id
As soon as Postgres assigns a transaction id, if CAMO is enabled, this parameter is updated to show the transaction id just assigned.
bdr.is_node_connected
Synopsis
Returns boolean by checking if the walsender for a given peer is active on this node.
bdr.is_node_ready
Synopsis
Returns boolean by checking if the lag is lower than the given span or
lower than the bdr.global_commit_timeout
otherwise.
Consensus function
bdr.consensus_disable
Disables the consensus worker on the local node until server restart or until
it's reenabled using bdr.consensus_enable
(whichever happens first).
Warning
Disabling consensus disables some features of BDR and affects availability of the EDB Postgres Distributed cluster if left disabled for a long time. Use this function only when working with Technical Support.
bdr.consensus_enable
Reenabled disabled consensus worker on local node.
bdr.consensus_proto_version
Returns currently used consensus protocol version by the local node.
Needed by the BDR group reconfiguration internal mechanisms.
bdr.consensus_snapshot_export
Synopsis
Generate a new BDR consensus snapshot from the currently committed-and-applied state of the local node and return it as bytea.
By default, a snapshot for the highest supported Raft version is
exported. But you can override that by passing an explicit version
number.
The exporting node doesn't have to be the current Raft leader, and it doesn't
need to be completely up to date with the latest state on the leader. However, bdr.consensus_snapshot_import()
might not accept such a snapshot.
The new snapshot isn't automatically stored to the local node's
bdr.local_consensus_snapshot
table. It's only returned to the caller.
The generated snapshot might be passed to bdr.consensus_snapshot_import()
on
any other nodes in the same BDR node group that's behind the exporting node's
Raft log position.
The local BDR consensus worker must be disabled for this function to work. Typical usage is:
While the BDR consensus worker is disabled:
- DDL locking attempts on the node fail or time out.
- galloc sequences don't get new values.
- Eager and CAMO transactions pause or error.
- Other functionality that needs the distributed consensus system is disrupted. The required downtime is generally very brief.
Depending on the use case, it might be practical to extract a snapshot that
already exists from the snapshot
field of the bdr.local_consensus_snapshot
table and use that instead. Doing so doesn't require you to stop the consensus worker.
bdr.consensus_snapshot_import
Synopsis
Import a consensus snapshot that was exported by
bdr.consensus_snapshot_export()
, usually from another node in the same BDR
node group.
It's also possible to use a snapshot extracted directly from the snapshot
field of the bdr.local_consensus_snapshot
table on another node.
This function is useful for resetting a BDR node's catalog state to a known good state in case of corruption or user error.
You can import the snapshot if the importing node's apply_index
is less than
or equal to the snapshot-exporting node's commit_index
when the
snapshot was generated. (See bdr.get_raft_status()
.) A node that can't accept
the snapshot because its log is already too far ahead raises an error
and makes no changes. The imported snapshot doesn't have to be completely
up to date, as once the snapshot is imported the node fetches the remaining
changes from the current leader.
The BDR consensus worker must be disabled on the importing node for this
function to work. See notes on bdr.consensus_snapshot_export()
for details.
It's possible to use this function to force the local node to generate a new Raft snapshot by running: