---
title: Metastore Read Replicas
description: >-
  Learn how to configure a read-only metastore backed by a database read replica
  to scale search in BYOC Logs
breadcrumbs: Docs > BYOC Logs > Configure BYOC Logs > Metastore Read Replicas
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Metastore Read Replicas

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Overview{% #overview %}

By default, indexers and searchers in a BYOC (Bring Your Own Cloud) Logs cluster all read index metadata from the same metastore database. You can deploy a read-only metastore backed by a database read replica so that searchers query the replica instead. This scales search requests independently of indexing and isolates the search path from the indexing path.

## Prerequisite: A read replica database{% #prerequisite-a-read-replica-database %}

Prepare one or more read replica instances of your metastore PostgreSQL database.

{% alert level="info" %}
If you use Amazon Aurora, use a reader endpoint instead of an individual read-replica endpoint. A reader endpoint load-balances across available replicas and provides better availability.
{% /alert %}

## Create a Kubernetes secret for the read replica{% #create-a-kubernetes-secret-for-the-read-replica %}

The read-only metastore requires an environment variable named `QW_METASTORE_READ_REPLICA_URI`. Set it to the connection URI for your read replica instance(s), similar to `QW_METASTORE_URI` for the primary metastore. Store this URI in a Kubernetes secret in your BYOC Logs namespace:

```shell
kubectl create secret generic byoclogs-metastore-read-replica-uri \
-n <NAMESPACE_NAME> \
--from-literal QW_METASTORE_READ_REPLICA_URI="postgres://<USERNAME>:<PASSWORD>@<READ_REPLICA_ENDPOINT>:<PORT>/<DATABASE>"
```

## Deploy the read-only metastore{% #deploy-the-read-only-metastore %}

Add a `metastore_ro` section to your `datadog-values.yaml` file to deploy the read-only metastore. At minimum, set `metastore_ro.enabled` to `true` and configure `extraEnvFrom` to reference the secret you created:

In the `datadog-values.yaml` file:

```yaml
metastore_ro:
  enabled: true
  extraEnvFrom:
    - secretRef:
        name: byoclogs-metastore-read-replica-uri
```

{% alert level="info" %}
Set the remaining `metastore_ro` parameters (such as `podSize`, resource requests and limits, and node placement) to match your primary `metastore` configuration.
{% /alert %}

Upgrade your Helm chart release to apply the change:

```shell
helm upgrade <RELEASE_NAME> datadog/cloudprem \
  -n <NAMESPACE_NAME> \
  -f datadog-values.yaml
```

After the upgrade completes, searchers use the read-only metastore to serve search requests, while indexers continue to use the primary metastore.

## Further reading{% #further-reading %}

Additional helpful documentation, links, and articles:

- [Configure BYOC Logs](https://docs.datadoghq.com/byoc-logs/configure.md)
- [Size your cluster](https://docs.datadoghq.com/byoc-logs/operate/sizing.md)
- [Best practices](https://docs.datadoghq.com/byoc-logs/operate/best_practices.md)
