# 双集群容灾控制函数
- gs_streaming_dr_in_switchover() 描述：基于流式复制的异地容灾解决方案中主集群在执行计划内switchover过程中截断业务的接口。
  返回值类型：Boolean，表明此次业务截断是否成功，是否可以正常进行switchover流程。
  
- gs_set_dr_dest_name() 描述：用于配置日志发送端集群的所有日志接收端集群实例ID，入参为与日志发送端集群直接连接的所有日志接收端集群实例ID拼接成的字符串，并以','作为间隔符；设置成功返回t，否则返回f。
  入参类型：text，当入参为0时表示未配置日志接收端集群实例ID信息。容灾流程中会自动设置，不建议用户进行修改。
  ![](https://support.huaweicloud.com/distributed-ref-v10-gaussdb/public_sys-resources/notice_3.0-zh-cn.png)
  日志接收端集群实例ID不可为"invalid_cluster_uuid"，且字符长度不可超过36位。
  返回值类型：boolean
  示例
  ```
  gaussdb=# SELECT * FROM gs_set_dr_dest_name('cluster1,cluster2');
   gs_set_dr_dest_name
  ---------------------
   t
  (1 row)
  ```
  
  
- gs_get_dr_dest_name() 描述：用于查看通过gs_set_dr_dest_name配置的所有日志接收端集群实例ID信息。
  返回值类型：text，返回值为0时表示配置的日志接收端集群实例ID信息为空。
  示例
  ```
  gaussdb=# SELECT * FROM gs_get_dr_dest_name();
   gs_get_dr_dest_name
  ---------------------
   cluster1,cluster2
  (1 row)
  ```
  
  
- gs_set_hadr_link_info() 描述：用于容灾链路信息的设置，入参是JSON格式的text；设置成功返回"success"，失败则返回"failed"。容灾流程中会自动设置，不建议用户进行修改。
  返回值类型：text
  表1gs_set_hadr_link_info参数说明 
  | 参数名                       | 类型          | 描述                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
  |:---|:---|:---|
  | meta_version               | string       | 容灾链路JSON格式的版本号。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
  | version                    | string        | 容灾链路信息的版本号。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
  | replication_info        | string    | 存放容灾链路信息，包含多条链路信息的JSON数组。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
  | dest_name                   | string       | 灾备集群实例ID。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
  | dest_type                 | string    | 控制容灾链路的类型。 取值类型：枚举值 取值范围：physical_standby_cluster/logical_standby_cluster/gaussstor 默认值：physical_standby_cluster                                                                                                                                                                                                                                                                                                                                             |
  | mode                      | string      | 控制容灾链路日志同步的模式。 取值类型：枚举值 取值范围： - sync：该链路同步等待日志接收端备机持久化redo日志到磁盘，确保无数据丢失，会影响主机性能。  - semisync：该链路优先同步传输，若发生断链超时或RPO异常时则降级为异步。  - async：异步传输，优先主机性能。   默认值：async |
  | net_timeout              | string      | 半同步模式下超时阈值。 取值范围：\[0,max\] 取值单位：秒 默认值：0                                                                                                                                                                                                                                                                                                                                                                                                                     |
  | rpo_threshold           | int       | 半同步模式下RPO阈值。 取值范围：\[0,max\] 取值单位：秒 默认值：0                                                                                                                                                                                                                                                                                                                                                                                                                      |
  | compression                | string     | 控制是否打开压缩。 取值类型：枚举值 取值范围：enable/disable 默认值：enable                                                                                                                                                                                                                                                                                                                                                                                                         |
  | compression_algo_setting | string      | 控制压缩算法，当前不支持修改，此参数使用默认值"lz4,1"。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
  | replication_rate_limit   | int/string | 控制容灾链路的限制速度，带单位：K、M、G，例如：1024K、1M、10M、2048G。 取值单位：Byte 取值范围：\[-1、0、1MB \~ 2TB\] - 整型：-1、0、1048576 \~ 2199023255552  - 字符串：-1、0、1048576 \~ 2199023255552   默认值：-1                                                                                             |
  | rate_burst               | int      | 控制允许单次发送的最大数据包大小，为replication_rate_limit的倍数关系。 取值范围：\[1, 5\] 默认值：2                                                                                                                                                                                                                                                                                                                                                                                                                                          |
  | conn_info                | string      | 包含连接串和访问权限信息。详见下面示例的具体内容。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
     
  示例
  ```
  gaussdb=# SELECT gs_set_hadr_link_info('{"meta_version":"1","version":"3","replication_info":[{"dest_name":"clusterb","dest_type":"physical_standby_cluster","mode":"async","net_timeout":0,"rpo_threshold":0,"compression":"enable","compression_algo_setting":"lz4,1","replication_rate_limit":-1,"rate_burst":2,"conn_info":{"shards":{"replconninfo":{"shard_1":{"localinfo":{"dn_6001":{"h":"127.0.0.1","p":40001,"hbp":40005},"dn_6002":{"h":"127.0.0.1","p":40001,"hbp":40005},"dn_6003":{"h":"127.0.0.1","p":40001,"hbp":40005}},"remoteinfo":[{"h":"127.0.0.1","p":40001,"hbp":40005},{"h":"127.0.0.1","p":40001,"hbp":40005},{"h":"127.0.0.1","p":40001,"hbp":40005}]},"shard_2":{"localinfo":{"dn_6006":{"h":"127.0.0.1","p":40021,"hbp":40025},"dn_6004":{"h":"127.0.0.1","p":40021,"hbp":40025},"dn_6005":{"h":"127.0.0.1","p":40021,"hbp":40025}},"remoteinfo":[{"h":"127.0.0.1","p":40021,"hbp":40025},{"h":"127.0.0.1","p":40021,"hbp":40025},{"h":"127.0.0.1","p":40021,"hbp":40025}]},"shard_3":{"localinfo":{"dn_6008":{"h":"127.0.0.1","p":40041,"hbp":40045},"dn_6009":{"h":"127.0.0.1","p":40041,"hbp":40045},"dn_6007":{"h":"127.0.0.1","p":40041,"hbp":40045}},"remoteinfo":[{"h":"127.0.0.1","p":40041,"hbp":40045},{"h":"127.0.0.1","p":40041,"hbp":40045},{"h":"127.0.0.1","p":40041,"hbp":40045}]}},"hba":[{"type":"host","database":"all","user":"rdsAdmin","method":"trust"},{"type":"host","database":"replication","user":"stream_user","method":"sha256"}]},"cn":{"replconninfo":{"cn_5001":{"h":"127.0.0.1","p":9081,"hbp":9085,"remoteinfo":[{"h":"127.0.0.1","p":9081,"hbp":9085}]},"cn_5002":{"h":"127.0.0.1","p":9081,"hbp":9085,"remoteinfo":[{"h":"127.0.0.1","p":9081,"hbp":9085}]},"cn_5003":{"h":"127.0.0.1","p":9081,"hbp":9085,"remoteinfo":[{"h":"127.0.0.1","p":9081,"hbp":9085}]}},"hba":[{"type":"host","database":"all","user":"rdsAdmin","method":"trust"},{"type":"host","database":"replication","user":"stream_user","method":"sha256"}]}}}]} ');
   gs_set_hadr_link_info 
  -----------------------
   success
  (1 row)
  ```
  
- gs_get_hadr_link_info() 描述：用于查看当前所有容灾链路的信息。
  返回值类型：record
  示例
  ```
  gaussdb=# SELECT * FROM gs_get_hadr_link_info();
  -[ RECORD 1 ]------------+-----------------------------------------------------------------------------------------------------------------------------
  dest_name                | clusterb
  dest_type                | physical_standby_cluster
  mode                     | semisync
  net_timeout              | 60
  rpo_threshold            | 10
  compression              | enable
  compression_algo_setting | lz4,1
  replication_rate_limit   | 0
  rate_burst               | 2
  replconninfo             | localhost=127.0.0.1 localport=20001 localheartbeatport=20005 remotehost=127.0.0.1 remoteport=20025 remoteheartbeatport=20029
                           | localhost=127.0.0.1 localport=20001 localheartbeatport=20005 remotehost=127.0.0.1 remoteport=20033 remoteheartbeatport=20037
                           | localhost=127.0.0.1 localport=20001 localheartbeatport=20005 remotehost=127.0.0.1 remoteport=20041 remoteheartbeatport=20045
                           | 
  hba                      | local all all trust
                           | local all all trust
                           | local all all trust
                           |
  ```
  
- gs_get_hadr_link_version() 描述：用于获取容灾链路信息的版本号。
  返回值类型：int8
  示例
  ```
  gaussdb=# SELECT * FROM gs_get_hadr_link_version();
   link_info_version 
  -------------------
                  100
  (1 row)
  ```
  
- gs_get_hadr_sync_status() 描述：用于查看当前所有容灾链路日志同步的状态信息。
  返回值类型：record
  表2gs_get_hadr_sync_status参数说明 
  | 参数类型   | 参数名                           | 类型          | 描述                    |
  |:---|:---|:---|:---|
  | 输出参数 | dest_name                 | text         | 容灾链路日志接收端集群ID。         |
  | 输出参数   | sync_state                  | text         | 当前容灾链路实际的同步状态。        |
  | 输出参数   | current_rpo                | int         | 当前容灾链路的RPO时间（单位：秒）。   |
  | 输出参数    | sender_sent_location        | text          | 容灾链路日志发送端发送日志位置。     |
  | 输出参数     | sender_write_location        | text      | 容灾链路日志发送端写入到文件系统的日志位置。   |
  | 输出参数    | sender_flush_location        | text        | 容灾链路日志发送端flush磁盘的日志位置。  |
  | 输出参数   | sender_replay_location      | text          | 容灾链路日志发送端回放日志位置。      |
  | 输出参数   | receiver_received_location  | text          | 容灾链路日志接收端接收日志位置。      |
  | 输出参数   | receiver_flush_location     | text         | 容灾链路日志接收端日志flush磁盘位置。 |
  | 输出参数   | last_disconnect_time          | timestamptz | 最近一次容灾链路断链的时间。        |
  | 输出参数 | last_upgrade_to_sync_time | timestamptz  | 半同步模式下，最近一次升级为同步模式的时间。  |
  | 输出参数     | last_downgrade_to_async_time | timestamptz | 半同步模式下，最近一次降级为异步模式的时间。  |
  | 输出参数   | mode                        | text        | 容灾链路日志同步模式的配置值。         |
  | 输出参数  | net_timeout                  | text      | 容灾链路半同步模式的超时阈值。        |
  | 输出参数   | rpo_threshold                | text        | 容灾链路半同步模式的RPO阈值。         |
     
  示例
  ```
  gaussdb=# SELECT * FROM gs_get_hadr_sync_status();
  -[ RECORD 1 ]----------------+------------------------------
  dest_name                    | clusterb
  sync_state                   | Sync
  current_rpo                  | 0
  sender_sent_location         | 0/11380B20
  sender_write_location        | 0/11380B20
  sender_flush_location        | 0/11380B20
  sender_replay_location       | 0/11380B20
  receiver_received_location   | 0/11380B20
  receiver_flush_location      | 0/11380B20
  last_disconnect_time         | 2026-01-15 20:35:42.18516+08
  last_upgrade_to_sync_time    | 2026-01-15 21:29:55.147578+08
  last_downgrade_to_async_time | 2026-01-15 20:36:42.187545+08
  mode                         | semisync
  net_timeout                  | 60
  rpo_threshold                | 10
  ```
  
- gs_stat_get_replication_limit() 描述：用于查询当前集群所有链路的限流配置参数值，最近1s、最近5s和最近60s的平均带宽使用情况。
  返回值类型：record
  表3gs_stat_get_replication_limit参数说明 
  | 参数类型   | 参数名                     | 类型     | 描述                                 |
  |:---|:---|:---|:---|
  | 输出参数  | dest_name             | text  | 该发送链路的目标集群名称。                      |
  | 输出参数    | replication_rate_limit | text | 该链路限流配置的带宽上限。                       |
  | 输出参数     | rate_burst             | text    | 该链路限流配置的突发流量为带宽上限的倍数，允许瞬时产生的最大流量。 |
  | 输出参数 | current_usage             | text   | 最近1s链路使用的平均带宽统计，单位Byte/s。         |
  | 输出参数    | average_usage_5s      | text    | 最近5s链路使用的平均带宽统计，单位Byte/s。           |
  | 输出参数  | average_usage_60s      | text    | 最近60s链路使用的平均带宽统计，单位Byte/s。         |
     
  示例
  ```
  gaussdb=# SELECT * FROM gs_stat_get_replication_limit();
  -[ RECORD 1 ]----------+---------
  dest_name              | clusterb
  replication_rate_limit | -1
  rate_burst             | 2
  current_usage          | 0
  average_usage_5s       | 0
  average_usage_60s      | 0
  -[ RECORD 2 ]----------+---------
  dest_name              | clusterc
  replication_rate_limit | -1
  rate_burst             | 2
  current_usage          | 0
  average_usage_5s       | 0
  average_usage_60s      | 0
  ```
  
 
