Are you an LLM? You can read better optimized documentation at /v6.0/en-us/metadb-slave-config.md for this page in Markdown format
Metadb Master-Slave Configuration
Configuration Instructions
- Metadb master-slave configuration, applicable to Metadb database versions higher than 13.5. For Metadb services below this version, refer to Database Service Upgrade.
Standalone/Cluster Deployment
Preparation Work
- Configure the
export PG_METASLAVE_HOST=(10.10.10.xx 10.10.10.xx)parameter in the/opt/hengshi/conf/hengshi-sense-env.shfile, where10.10.10.xxrepresents the IP address of the slave node.
Multiple slave configurations are supported, allowing you to choose one or multiple slave nodes, and horizontal scaling of the number of slave nodes is supported. - Ensure that the slave server can log in to the master server without a password.
- Before executing the initialization operation for the slave node, ensure that the master node's
metadbservice is in a running state.
Note: The slave node port cannot be configured; it uses theHS_PG_PORTvalue configured on the master node. Please ensure that this port is available on the slave node.
Initialization Operations
Note
- Before initializing metaslave, ensure that the metadb service is running.
- The initialized slave database has read-only permissions without write permissions and cannot be directly connected for use as a database.
shell
cd /opt/hengshi
bin/hengshi-sense-bin init metaslave1
2
2

Startup Operations
shell
cd /opt/hengshi
bin/hengshi-sense-bin start metaslave1
2
2

Stop Operation
shell
cd /opt/hengshi
bin/hengshi-sense-bin stop metaslave1
2
2
Switching Slave Database Operations
- Promote write permissions for the slave database. This operation needs to be executed on the server with the original slave database address configured in
HS_PG_HOST.
shell
cd /opt/hengshi
bin/hengshi-sense-bin promote metadb1
2
2
- When the following prompt appears, enter
Yto confirm the operation. The successful operation interface is shown below:
- Modify the
HS_PG_HOSTparameter in the/opt/hengshi/conf/hengshi-sense-env.shfile to the slave database address you want to switch to as the master database. Note- If the
HS_ENGINE_HOSTparameter is not configured, please configure it. Using the default parameter will reference theHS_PG_HOSTparameter information, which may lead to an incorrect engine address. - After switching to the slave database, please reconfigure the
PG_METASLAVE_HOSTparameter. The previously configured master-slave relationship will become invalid, and you will need to perform initialization operations again.
- If the
- Restart the HENGSHI service to complete the master-slave switching operation.
shell
cd /opt/hengshi
bin/hengshi-sense-bin restart hengshi1
2
2
Cluster Deployment Notes
- Uncomment the following content in
/opt/hengshi/ansible/hostson the cluster operation node (default Node-A):
shell
[metaslave] #metadb database slave (optional) can be used as a backup when the master database is down
Node-B1
2
2
- Specify the
export PG_METASLAVE_HOST=(Node-B)parameter in/opt/hengshi/conf/hengshi-sense-env.shon the machine node where the metadb slave resides (default Node-B) as Node-B. Use spaces to separate multiple hosts.
Alternatively, you can directly modify /opt/hengshi/conf/hengshi-sense-env.sh on Node-A, and then use the following command to synchronize the configuration file to other nodes:
shell
./hs_install -m config -c ../cluster-conf/1
- Execute initialization and startup operations on the cluster operation node (default Node-A):
shell
/opt/hengshi/bin/hengshi-sense-bin init metaslave
/opt/hengshi/bin/hengshi-sense-bin start metaslave1
2
2
You will see the word "streaming," indicating that the master-slave configuration is successful. 
Container Deployment
Preparation Work
- Deploy Metadb master-slave using a specific docker-compose.yaml file. Please contact support personnel.
- Configure the hsenv file:
- HS_MASTER_PG_HOST: Deployment service node, server IP information (not the internal IP of the docker container).
- HS_SLAVE_PG_HOST: Deployment slave node, server IP information (not the internal IP of the docker container).
- Ensure that the HS_MASTER_PG_HOST and HS_SLAVE_PG_HOST servers can communicate normally and that the HS_PG_EXPOSE_PORT is mutually open.
Initialization Operations
Note
- Before initializing metaslave, ensure that the metadb service is running.
- The initialized slave database has read-only permissions and no write permissions. It cannot be directly connected for use as a database.
shell
cd single
docker-compose run --rm metadb init metaslave1
2
2

Start Operation
shell
cd single
docker-compose up -d1
2
2

Stop Operation
shell
cd single
docker-compose down1
2
2
Switching Slave Operations
- Promote the read-write permissions of the slave. This operation needs to be executed on the server with the original slave address configured in
HS_SLAVE_PG_HOST.
shell
cd single
docker-compose run --rm metadb promote metadb1
2
2
- When the following prompt appears, enter
Yto confirm the operation. The successful operation interface is shown below:
- Modify the
hengshi docker-compose/.envconfiguration file, changingHS_PG_HOST:xxxto the IP of the slave server. - Restart the HENGSHI service to complete the master-slave switching operation.
shell
cd single
docker-compose down
docker-compose up1
2
3
2
3
k8s Deployment
Preparation Work
- Please contact the after-sales personnel to obtain the
metaslave.yamlconfiguration file.
Startup Operations
Note
- Before executing the
metaslaveoperation, ensure that themetadbservice is in a running state. - The initialized slave database has read-only permissions and no write permissions; it cannot be directly connected for use as a database.
- Please confirm that the
LOCAL_HOST_NAMEparameter is configured in theconfigmap.yamlfile.
shell
kubectl -n hengshi apply -f configmap.yaml
kubectl -n hengshi apply -f metaslave.yaml1
2
2
Switching Slave Database Operations
- Promote slave database read-write permissions
shell
kubectl -n hengshi exec -it metaslave-0 -- /docker-entrypoint.sh promote metadb single1
- When the following prompt appears, enter Y to confirm the operation. The successful operation interface is shown below:

- Modify the
configmap.yamlfile, change the parameterHS_PG_HOST: **metadb-0.hengshi-hs**tometaslave-0.hengshi-hs. - Restart the HENGSHI service to complete the master-slave switching operation:
shell
kubectl -n hengshi apply -f hengshi.yaml1