def toggle_pause(cluster_name: str, group: Optional[int], paused: bool, wait: bool) -> None:
    """Toggle the ``pause`` state in the cluster members.

    :param cluster_name: name of the Patroni cluster.
    :param group: filter which Citus group we should toggle the pause state of. Refer to the module note for more
        details.
    :param paused: the desired state for ``pause`` in all nodes.
    :param wait: ``True`` if it should block until the operation is finished or ``false`` for returning immediately.

    :raises:
        PatroniCtlException: if
            * ``pause`` state is already *paused*; or
            * cluster contains no accessible members.
    """
    dcs = get_dcs(cluster_name, group)
    cluster = dcs.get_cluster()
    if global_config.from_cluster(cluster).is_paused == paused:
        raise PatroniCtlException('Cluster is {0} paused'.format(paused and 'already' or 'not'))

    for member in get_all_members_leader_first(cluster):
        try:
            r = request_patroni(member, 'patch', 'config', {'pause': paused or None})
        except Exception as err:
            logging.warning(str(err))
            logging.warning('Member %s is not accessible', member.name)
            continue

        if r.status == 200:
            if wait:
                wait_until_pause_is_applied(dcs, paused, cluster)
            else:
                click.echo('Success: cluster management is {0}'.format(paused and 'paused' or 'resumed'))
        else:
            click.echo('Failed: {0} cluster management status code={1}, ({2})'.format(
                       paused and 'pause' or 'resume', r.status, r.data.decode('utf-8')))
        break
    else:
        raise PatroniCtlException('Can not find accessible cluster member')
Toggle the ``pause`` state in the cluster members.

    :param cluster_name: name of the Patroni cluster.
    :param group: filter which Citus group we should toggle the pause state of. Refer to the module note for more
        details.
    :param paused: the desired state for ``pause`` in all nodes.
    :param wait: ``True`` if it should block until the operation is finished or ``false`` for returning immediately.

    :raises:
        PatroniCtlException: if
            * ``pause`` state is already *paused*; or
            * cluster contains no accessible members.
    
patroni/ctl.py