> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Allows accessing all shards (configured in the `remote_servers` section) of a cluster without creating a Distributed table.

# clusterAllReplicas

Allows accessing all shards (configured in the `remote_servers` section) of a cluster without creating a [Distributed](/reference/engines/table-engines/special/distributed) table. Only one replica of each shard is queried.

`clusterAllReplicas` function — same as `cluster`, but all replicas are queried. Each replica in a cluster is used as a separate shard/connection.

<Note>
  All available clusters are listed in the [system.clusters](/reference/system-tables/clusters) table.
</Note>

<h2 id="syntax">
  Syntax
</h2>

```sql theme={null}
cluster(['cluster_name', db.table, sharding_key])
cluster(['cluster_name', db, table, sharding_key])
clusterAllReplicas(['cluster_name', db.table, sharding_key])
clusterAllReplicas(['cluster_name', db, table, sharding_key])
```

<h2 id="arguments">
  Arguments
</h2>

| Arguments                   | Type                                                                                                                                              |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `cluster_name`              | Name of a cluster that is used to build a set of addresses and connection parameters to remote and local servers, set `default` if not specified. |
| `db.table` or `db`, `table` | Name of a database and a table.                                                                                                                   |
| `sharding_key`              | A sharding key. Optional. Needs to be specified if the cluster has more than one shard.                                                           |

<h2 id="returned_value">
  Returned value
</h2>

The dataset from clusters.

<h2 id="using_macros">
  Using macros
</h2>

`cluster_name` can contain macros — substitution in `{}`. The substituted value is taken from the [macros](/reference/settings/server-settings/settings#macros) section of the server configuration file.

Example:

```sql theme={null}
SELECT * FROM cluster('{cluster}', default.example_table);
```

<h2 id="usage_recommendations">
  Usage and recommendations
</h2>

Using the `cluster` and `clusterAllReplicas` table functions are less efficient than creating a `Distributed` table because in this case, the server connection is re-established for every request. When processing a large number of queries, please always create the `Distributed` table ahead of time, and do not use the `cluster` and `clusterAllReplicas` table functions.

The `cluster` and `clusterAllReplicas` table functions can be useful in the following cases:

* Accessing a specific cluster for data comparison, debugging, and testing.
* Queries to various ClickHouse clusters and replicas for research purposes.
* Infrequent distributed requests that are made manually.

Connection settings like `host`, `port`, `user`, `password`, `compression`, `secure` are taken from `<remote_servers>` config section. See details in [Distributed engine](/reference/engines/table-engines/special/distributed).

<h2 id="related">
  Related
</h2>

* [skip\_unavailable\_shards](/reference/settings/session-settings#skip_unavailable_shards)
* [load\_balancing](/reference/settings/session-settings#load_balancing)
