Node management interfaces v5
You can add and remove nodes dynamically using the SQL interfaces.
bdr.alter_node_group_option
Modify a PGD node group configuration.
Synopsis
Parameters
node_group_name
— Name of the group to be changed.config_key
— Key of the option in the node group to be changed.config_value
— New value to be set for the given key.
config_value
will be parsed into the data type appropriate for the option.
Some parameters can be applied only to the top-level node group. For these parameters, the Groups column contains Top. Some parameters can be applied to the top-level node group and subgroups. For these parameters, the Groups column contains All. When a parameter can be applied only to subgroups, the Groups column contains Sub.
The table shows the group options that can be changed using this function.
Name | Type | Groups | Description |
---|---|---|---|
apply_delay | interval | All | How long nodes wait to apply incoming changes. This option is useful mainly to set up a special subgroup with delayed subscriber-only nodes. Don't set this on groups that contain data nodes or on the top-level group. Default is 0s . |
check_constraints | boolean | Top | Whether the apply process checks the constraints when writing replicated data. We recommend keeping the default value or you risk data loss. Valid values are on or off . Default is on . |
default_commit_scope | text | All | The commit scope to use by default, initially the local commit scope. This option applies only to the top-level node group. You can use individual rules for different origin groups of the same commit scope. See Origin groups for more details. |
enable_proxy_routing | boolean | All | Where pgd-proxy through the group leader is enabled for given group. Valid values are on or off . Default is off . |
enable_raft | boolean | Sub | Whether group has its own Raft consensus. This option is necessary for setting enable_proxy_routing to on . This option is always on for the top-level group. Valid values are on or off . Default is off for subgroups. |
enable_wal_decoder | boolean | Top | Enables/disables the decoding worker process. You can't enable the decoding worker process if streaming_mode is already enabled. Valid values are on or off . Default is off . |
location | text | All | Information about group location. This option is purely metadata for monitoring. Default is '' (empty string). |
num_writers | integer | Top | Number of parallel writers for the subscription backing this node group. Valid values are -1 or a positive integer. -1 means the value specified by the GUC bdr.writers_per_subscription is used. -1 is the default. |
route_reader_max_lag | integer | All | Maximum lag in bytes for a node to be considered a viable read-only node. Currently reserved for future use. |
route_writer_max_lag | integer | All | Maximum lag in bytes of the new write candidate to be selected as write leader. If no candidate passes this, no writer is selected automatically. Default is -1 . |
route_writer_wait_flush | boolean | All | Whether to switch if PGD needs to wait for the flush. Currently reserved for future use. |
streaming_mode | text | Top | Enables/disables streaming of large transactions. When set to off , streaming is disabled. When set to any other value, large transactions are decoded while they're still in progress, and the changes are sent to the downstream. If the value is set to file , then the incoming changes of streaming transactions are stored in a file and applied only after the transaction is committed on upstream. If the value is set to writer , then the incoming changes are directly sent to one of the writers, if available.If parallel apply is disabled or no writer is free to handle streaming transactions, then the changes are written to a file and applied after the transaction is committed. If the value is set to auto , PGD tries to intelligently pick between file and writer , depending on the transaction property and available resources. You can't enable streaming_mode if the WAL decoder is already enabled. Default is auto .For more details, see Transaction streaming. |
Return value
bdr.alter_node_group_option()
returns VOID
on success.
An ERROR
is raised if any of the provided parameters is invalid.
Notes
You can examine the current state of node group options by way of the view
bdr.node_group_summary
.
This function passes a request to the group consensus mechanism to change the defaults. The changes made are replicated globally using the consensus mechanism.
The function isn't transactional. The request is processed in the background, so you can't roll back the function call. Also, the changes might not be immediately visible to the current transaction.
This function doesn't hold any locks.
bdr.alter_node_interface
This function changes the connection string (DSN
) of a specified node.
Synopsis
Parameters
node_name
— Name of an existing node to alter.interface_dsn
— New connection string for a node.
Notes
Run this function and make the changes only on the local node. This means that you normally execute it on every node in the PGD group, including the node that is being changed.
This function is transactional. You can roll it back, and the changes are visible to the current transaction.
The function holds lock on the local node.
bdr.alter_node_option
Modify the PGD node routing configuration
Synopsis
Parameters
node_name
— Name of the node to be changed.config_key
— Key of the option in the node to be changed.config_value
— New value to be set for the given key.
The node options that can be changed using this function are:
route_priority
— Relative routing priority of the node against other nodes in the same node group. Default is'-1'
.route_fence
— Whether the node is fenced from routing. When true, the node can't receive connections from PGD Proxy. Default is'f'
(false).route_writes
— Whether writes can be routed to this node, that is, whether the node can become write leader. Default is't'
(true) for data nodes and'f'
(false) for other node types.route_reads
— Whether read-only connections can be routed to this node. Currently reserved for future use. Default is't'
(true) for data and subscriber-only nodes,'f'
(false) for witness and standby nodes.route_dsn
— The dsn for the proxy to use to connect to this node. This option is optional. If not set, it defaults to the node'snode_dsn
value.
bdr.alter_subscription_enable
This function enables either the specified subscription or all the subscriptions of the local PGD node. This is also known as resume subscription. No error is thrown if the subscription is already enabled. Returns the number of subscriptions affected by this operation.
Synopsis
Parameters
subscription_name
— Name of the subscription to enable. If NULL (the default), all subscriptions on the local node are enabled.immediate
— This currently has no effect.
Notes
This function isn't replicated and affects only local node subscriptions (either a specific node or all nodes).
This function is transactional. You can roll it back, and the current transaction can see any catalog changes. The subscription workers are started by a background process after the transaction has committed.
bdr.alter_subscription_disable
This function disables either the specified subscription or all the subscriptions of the local PGD node. Optionally, it can also immediately stop all the workers associated with the disabled subscriptions. This is also known as pause subscription. No error is thrown if the subscription is already disabled. Returns the number of subscriptions affected by this operation.
Synopsis
Parameters
subscription_name
— Name of the subscription to disable. If NULL (the default), all subscriptions on the local node are disabled.immediate
— Used to force the action immediately, stopping all the workers associated with the disabled subscription. When this option istrue
, you can't run this function inside of the transaction block.fast
— This argument influences the behavior ofimmediate
. If set totrue
(the default) it stops all the workers associated with the disabled subscription without waiting for them to finish current work.
Notes
This function isn't replicated and affects only local node subscriptions (either a specific subscription or all subscriptions).
This function is transactional. You can roll it back, and the current transaction can see any catalog changes.
However, the timing of the subscription
worker stopping depends on the value of immediate
. If set to true
, the
workers receive the stop without waiting for the COMMIT
. If the fast
argument is set to true
, the interruption of the workers doesn't wait for
current work to finish.
bdr.create_node
This function creates a node.
Synopsis
Parameters
node_name
— Name of the new node. Only one node is allowed per database. Valid node names consist of lowercase letters, numbers, hyphens, and underscores.local_dsn
— Connection string to the node.node_kind
— One ofdata
(the default),standby
,subscriber-only
, orwitness
. If you don't set this parameter, or if you provideNULL
, the defaultdata
node kind is used.
Notes
This function creates a record for the local node with the associated public connection string. There can be only one local record, so once it's created, the function reports an error if run again.
This function is a transactional function. You can roll it back and the changes made by it are visible to the current transaction.
The function holds lock on the newly created node until the end of the transaction.
bdr.create_node_group
This function creates a PGD node group. By default, the local node should join the
group as the only member. You can add more nodes to the group with
bdr.join_node_group()
.
Synopsis
Parameters
node_group_name
— Name of the new PGD group. As with the node name, valid group names must consist of only lowercase letters, numbers, and underscores.parent_group_name
— If a node subgroup is being created, this must be the name of the parent group. ProvideNULL
(the default) when creating the main node group for the cluster.join_node_group
— This parameter determines whether the node joins the group being created. The default value istrue
. Providing false when creating a subgroup means the local node won't join the new group, for example, when creating a independent remote group. In this case, you must specifyparent_group_name
.node_group_type