Updated on 2024-10-14 GMT+08:00

Dual-Cluster DR Control Functions

Dual-cluster DR control functions can be used to create an archive slot, which specifies the OBS information for storing physical logs.

  • pg_create_physical_replication_slot_extern(slotname text, dummy_standby bool, extra_content text, need_recycle_xlog bool)

    Description: Creates an OBS or a NAS archive slot. slotname indicates the slot name of the DR standby. The primary and standby nodes must use the same slot name. dummy_standby specifies whether the database is deployed in primary/standby/secondary mode or one-primary and multi-standby mode. The value false indicates that the database is deployed in one-primary and multi-standby mode, and the value true indicates that the database is deployed in primary/standby/secondary mode. extra_content contains some information about the archive slot. For an OBS archive slot, the format is OBS;obs_server_ip;obs_bucket_name;obs_ak;obs_sk;archive_path;is_recovery;is_vote_replicate, where OBS indicates the archive media of the archive slot, obs_server_ip indicates the IP address of OBS, obs_bucket_name indicates the bucket name, obs_ak indicates the AK of OBS, obs_sk indicates the SK of OBS, archive_path indicates the archive path i, and is_recovery indicates whether the slot is an archive slot or a recovery slot. The value 0 indicates that the slot is an archive slot and is used by the primary database instance. The value 1 indicates that the slot is a recovery slot and is used by the DR database instance. is_vote_replicate indicates whether the voting copy is archived first. The value 0 indicates that the synchronous standby server is archived first, and the value 1 indicates that the voting copy is archived first. This field is reserved in the current version and is not adapted yet. For a NAS archive slot, the format is NAS;archive_path;is_recovery;is_vote_replicate. Compared with the OBS archive slot, the NAS archive slot does not have the OBS configuration information, while the meanings of other fields are the same.

    If the media is not specified, the OBS archive slot is used by default. The extra_content format is obs_server_ip;obs_bucket_name;obs_ak;obs_sk;archive_path;is_recovery;is_vote_replicate.

    need_recycle_xlog specifies whether to recycle old archived logs when creating an archive slot. The value true indicates that old archived logs are recycled, and the value false indicates that old archive logs are not recycled.

    Return type: records, including slotname and xlog_position of the current DR standby.

    Note: Users who invoke this function must have the SYSADMIN permission or the REPLICATION permission, or inherit the gs_role_replication permission of the built-in role.

    Example:

    Create an OBS archive slot.

    1
    2
    3
    4
    5
    openGauss=# select * from pg_create_physical_replication_slot_extern('uuid', false, 'OBS;obs.cn-north-7.ulanqab.huawei.com;dyk;19D772JBCACXX3KWS51D;********;openGauss_uuid/dn1;0;0', false);
     slotname | xlog_position
    ----------+---------------
     uuid     |
    (1 row)
    

    Create a NAS archive slot.

    1
    2
    3
    4
    openGauss=# select * from pg_create_physical_replication_slot_extern('uuid', false, 'NAS;/data/nas/media/openGauss_uuid/dn1;0;0', false);
     slotname | xlog_position
    ----------+---------------
     uuid     |
    
  • gs_set_obs_delete_location(delete_location text)

    Description: Sets the location where OBS archive logs can be deleted. The value of delete_location is a LSN. The logs before this location have been replayed and flushed to disks in the DR cluster and can be deleted on OBS.

    Return type: xlog_file_name text, indicating the file name of the logs that can be deleted. The value of this parameter is returned regardless of whether OBS is deleted successfully.

    openGauss=# select gs_set_obs_delete_location('0/54000000');
     gs_set_obs_delete_location  
    -----------------------------
     000000010000000000000054_00
    (1 row)
  • gs_hadr_do_switchover()

    Description: Triggers a planned switchover in the primary cluster in the geo-redundancy scenario.

    Return type: Boolean, indicating whether the switchover process is performed normally and whether services are taken over successfully.

  • gs_set_obs_delete_location_with_slotname(cstring, cstring )

    Description: Sets the location where OBS archive logs can be deleted in a DR relationship. The first parameter indicates the LSN. The logs before this location have been replayed and flushed to disks in the DR database instance and can be deleted on OBS. The second parameter indicates the name of the archive slot.

    Return type: xlog_file_name text, indicating the file name of the logs that can be deleted. The value of this parameter is returned regardless of whether OBS is deleted successfully.

  • gs_streaming_dr_in_switchover()

    Description: Triggers a planned switchover in the primary cluster in remote DR solutions based on streaming replication.

    Return type: Boolean, indicating whether the switchover process is performed normally and whether services are taken over successfully.