bihactl
bihactl — create a BiHA cluster in Postgres Pro
Synopsis
bihactl add --biha-node-id= node_id--host= [hostoptions]
bihactl init --biha-node-id= node_id--nquorum= quorum_value--host= [hostoptions]
bihactl status [options]
bihactl -V | --version
bihactl -? | --help
Description
bihactl is a command line utility that allows creating a BiHA cluster, changing its composition, as well as monitoring the cluster status and version. For more information about the BiHA solution, see Built-in High Availability (BiHA).
This section contains information about the bihactl utility commands:
The follower node can be added using a magic string saved after the bihactl init command by adding the -s option to the bihactl add command.
Important
It is not recommended to execute the bihactl commands in the PGDATA directory. The bihactl utility may create the biha_init.log and biha_add.log files in the directory where it is executed. However, the target PGDATA directory must be empty for proper execution of the bihactl commands.
Command-Line Reference #
add #
Syntax:
bihactl add --biha-node-id=node_id--host=host{--use-leader=conn_info| --magic-string=magic_string| --magic-file=magic_file} [--convert-standby [--enable-proxima]] [--pgdata=datadir] [--port=port] [--biha-port=biha_port] [--backup-method=backup_method] [--backup-options=backup_options] [--mode=node_mode] [--referee-with-postgres-db]]
Adds a follower node to the initialized cluster. When this command is executed, a backup of the leader node is created by means of pg_basebackup or pg_probackup. When you add a node, bihactl keeps the replication slot by calling pg_basebackup with the --slot= parameters and pg_probackup with the SLOT_NAME, --wal-method=stream, --checkpoint=fast--stream --slot= parameters that prevents deletion of WAL on the leader during backup. SLOT_NAME
Note
You must add nodes one by one. Do not add a new node if creation of a previously added node has not been completed yet and the node is in the CSTATE_FORMING state. Otherwise, you may encounter the following error:
WARNING: aborting backup due to backend exiting before pg_backup_stop was
called
The backup utility can be set with the -m option, while the parameters of the selected backup are specified with the -O option.
This command can take the following options:
-c--convert-standby#Converts an existing node to make it a follower node in the high-availability cluster. The node should be a leader node replica prior to the conversion.
-Ddatadir--pgdata=#datadirSpecifies the directory where the database cluster should be stored. If not specified, bihactl uses the
PGDATAvalue.-fmagic_file--magic-file=#magic_fileUses a magic file that contains encoded data to connect to the leader node.
-hhost--host=#hostSpecifies the node host for incoming connections.
-Inode_id--biha-node-id=#node_idSpecifies the unique ID of the node.
-lconn_info--use-leader=#conn_infoSpecifies parameters to connect to the leader node in the following format:
host=
leader_hostport=leader_portbiha-port=leader_biha_port-mbackup_method--backup-method=#backup_methodSpecifies the backup utility. The allowed values are
pg_basebackupandpg_probackup. The default value ispg_basebackup. If you do not specify the--backup-methodoption, the default backup method is used. Thepg_basebackuputility is the only value that can be used when adding the referee node.-Obackup_options--backup-options=#backup_optionsSpecifies additional options of pg_basebackup or pg_probackup depending on the backup utility specified in the
--backup-methodoption.-pport--port=#portSpecifies the node port for incoming connections.
If not specified:
When converting the existing cluster using --convert-standby, bihactl uses the
PGPORTvalue.When creating a BiHA cluster from scratch, bihactl uses the default 5432 value.
-Pbiha_port--biha-port=#biha_portSpecifies the port used to exchange service information between nodes. If not specified, the value is set to
.port+ 1-rnode_mode--mode=#node_modeSpecifies the operation mode of the node. The allowed values are as follows:
regular— the node can operate as the leader or as the follower. This is the default value.referee— the node only participates in the leader elections and does not contain any user databases.referee_with_wal— the node participates both in the leader elections in the same way as in therefereemode and receives the entire WAL from the leader node.
By default, the
postgresdatabase is not copied to a node inrefereeorreferee_with_walmodes. To copy thepostgresdatabase to the referee, use the --referee-with-postgres-db option.-R--referee-with-postgres-db#Copies the
postgresdatabase with all the objects to the referee node. You can only use this option when adding a node inrefereeorreferee_with_walmodes.-smagic_string--magic-string=#magic_stringUses a magic string that contains encoded data to connect to the leader node.
-x--enable-proxima#Enables the proxima extension on a follower node converted from a standby node. For more information about converting the cluster, see Setting Up a BiHA Cluster from the Existing Cluster with Streaming Replication.
init #
Syntax:
bihactl init --biha-node-id=node_id--nquorum=quorum_value--host=host[--convert [--root-cert=/path/to/ca.crt--server-cert=/path/to/server.crt\ --server-key=/path/to/server.key--user-postgres-cert=/path/to/client.crt\ --user-postgres-key=/path/to/client.key[--postgres-ssl-mode=ssl_mode]]] [--enable-proxima] [--pgdata=datadir] [--port=port] [--biha-port=biha_port] [--use-ssl] [--minnodes=min_node_num] [--magic-file=magic_file] [--options=initdb_options] [--sync-standbys=sync_standbys_num[--sync-standbys-min=sync_standbys_min_num] [--root-cert=/path/to/ca.crt--user-biha-cert=/path/to/client.crt\ --user-biha-key=/path/to/client.key[--biha-ssl-mode=ssl_mode]]
Initializes a cluster and sets the leader node. When this command is executed, bihactl accesses the initdb utility, at this stage you can also specify its parameters with the -o option.
This command can take the following options:
-C--convert#Converts an existing node to make it the leader node in the high-availability cluster.
-Ddatadir--pgdata=#datadirSpecifies the directory where the database cluster should be stored. If not specified, bihactl uses the
PGDATAvalue.-fmagic_file--magic-file=#magic_fileUses a magic file that contains encoded data to connect to the leader node.
-hhost--host=#hostSpecifies the node host for incoming connections.
-Inode_id--biha-node-id=#node_idSpecifies the unique ID of the node.
-Mmin_node_num--minnodes=#min_node_numSpecifies the minimum number of operational nodes for the leader node to be open for write transactions. If not specified, the value equals the
nquorumvalue.-Nquorum_value--nquorum=#quorum_valueSpecifies the minimum number of nodes, which must vote for the new leader node if the current leader is down. This parameter can be set with the biha.set_nquorum function.
When setting up this value, consider the split-brain risk. It is recommended to use the following formula: (
total number of nodes+ 1)/2. For example, if your cluster has 3 nodes, thenquorumvalue must be 2.-oinitdb_options--options=#initdb_optionsSpecifies additional options of initdb.
-pport--port=#portSpecifies the node port for incoming connections.
If not specified:
When converting the existing cluster using --convert, bihactl uses the
PGPORTvalue.When creating a BiHA cluster from scratch, bihactl uses the default 5432 value.
-Pbiha_port--biha-port=#biha_portSpecifies the port used to exchange service information between nodes. If not specified, the value is set to
.port+ 1-S--use-ssl#Enables the protected mode of the service information exchange between cluster nodes with SSL/TLS over the biha control channel.
-Ysync_standbys_num--sync-standbys=#sync_standbys_numEnables quorum-based synchronous replication by setting the synchronous_standby_names parameter and specifying the number of synchronous standbys (quorum) with the
ANYmethod. It is recommended that thesync_standbys_numvalue be less than the value of the--minnodesoption.-ysync_standbys_min_num--sync-standbys-min=#sync_standbys_min_numEnables relaxed quorum-based synchronous replication by specifying the
MINfield value of the synchronous_standby_names parameter, which is the minimum number of synchronous standbys that must be available for the leader node to continue operation. Thesync_standbys_min_numvalue must be lower than --sync-standbys and cannot be negative. If the option is not specified, the BiHA cluster operates according to the default synchronous replication restrictions, i.e. the leader node is not available for write transactions until all followers catch up with its current state.-x--enable-proxima#Enables the proxima extension with the default parameters in a BiHA cluster when you create a BiHA cluster from scratch or on the leader node when you convert the existing primary-standby cluster into a BiHA cluster.
--biha-ssl-mode=#ssl_modeDetermines the SSL authentication policy for the
biha_replication_userrole. The following modes are supported:verify-full(default)requireverify-ca
For more information about modes, see sslmode.
--postgres-ssl-mode=#ssl_modeDetermines the SSL authentication policy for the superuser. The following modes are supported:
verify-full(default)requireverify-ca
For more information about modes, see sslmode.
--root-cert=#/path/to/ca.crtSpecifies the path to the trusted CA certificate in the PEM format.
--server-cert=#/path/to/server.crtSpecifies the path to the SSL certificate for the BiHA node in the PEM format.
--server-key=#/path/to/server.keySpecifies the path to the private key for the --server-cert certificate in the PEM format.
--user-biha-cert=#/path/to/client.crtSpecifies the path to the SSL certificate for the
biha_replication_userrole authentication in the PEM format.--user-biha-key=#/path/to/client.keySpecifies the path to the private key for the --user-biha-cert certificate in the PEM format.
--user-postgres-cert=#/path/to/client.crtSpecifies the path to the SSL certificate for the superuser authentication in the PEM format.
--user-postgres-key=#/path/to/client.keySpecifies the path to the private key for the --user-postgres-cert certificate in the PEM format.
status #
Syntax:
bihactl status {--host=host [--port=port] | --magic-string=magic_string | --magic-file=magic_file}
Checks the node status and displays it in the biha.status_v view. This command can take the following options:
-fmagic_file--magic-file=magic_fileUses a magic file that contains encoded data to connect to the leader node.
-hhost--host=hostSpecifies the node host for incoming connections.
-pport--port=portSpecifies the node port for incoming connections. If not specified, bihactl uses the
PGPORTvalue. The default value is 5432.-smagic_string--magic-string=magic_stringUses a magic string that contains encoded data to connect to the leader node.
-V | --version #
Syntax:
bihactl -V bihactl --version
Displays the current version of the high-availability cluster.