graphql-engine/docs/graphql/cloud/read-replicas.rst
Rikin Kachhia 4815c2bbc8 docs: update with misc 2.0 changes
- update copyright
- fix typo: comparision -> comparison
- add new null in comparision exp behaviour
- update cloud read replica page

GitOrigin-RevId: bfd322344e7ecf89a2c1361db4bc2d7e25718b98
2021-03-24 16:38:27 +00:00

111 lines
2.9 KiB
ReStructuredText

.. meta::
:description: Hasura Cloud read replicas
:keywords: hasura, docs, cloud, read replicas, connections, pool
.. _read_replicas:
Read replicas
=============
.. contents:: Table of contents
:backlinks: none
:depth: 1
:local:
Introduction
------------
Hasura Cloud can load balance queries and subscriptions across read replicas while sending all mutations and metadata API calls to the master.
Adding read replica urls
------------------------
.. rst-class:: api_tabs
.. tabs::
.. tab:: Console
Support coming very soon
.. tab:: CLI
You can add read replicas for a database by adding their config to the ``/metadata/databases/database.yaml`` file:
.. code-block:: yaml
:emphasize-lines: 11-17
- name: <db-name>
kind: postgres
configuration:
connection_info:
database_url:
from_env: <DATABASE_URL_ENV>
pool_settings:
idle_timeout: 180
max_connections: 50
retries: 1
read_replicas:
- database_url:
from_env: <DATABASE_REPLICA_URL_ENV>
pool_settings:
idle_timeout: 180
max_connections: 50
retries: 1
Apply the metadata by running:
.. code-block:: yaml
hasura metadata apply
.. tab:: API
Currently it is only possible to add read replicas for a database at the time of creation using the :ref:`pg_add_source metadata API <pg_add_source>`
.. code-block:: http
:emphasize-lines: 15-26
POST /v1/metadata HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin
{
"type": "pg_add_source",
"args": {
"name": "<db_name>",
"configuration": {
"connection_info": {
"database_url": {
"from_env": "<DATABASE_URL_ENV>"
}
},
"read_replicas": [
{
"database_url": {
"from_env": "<DATABASE_REPLICA_URL_ENV>"
},
"pool_settings": {
"retries": 1,
"idle_timeout": 180,
"max_connections": 50
}
}
]
}
.. admonition:: For existing v1.3 projects
If you have configured your Postgres instances with replicas, the replica URLs can be added to Hasura using the following environment variable in your project ENV Vars tab:
.. code-block:: bash
HASURA_GRAPHQL_READ_REPLICA_URLS=postgres://user:password@replica-host:5432/db
If you have multiple replicas, their urls can be added as comma separated values.
Additional environment variables for read replicas specifically:
``HASURA_GRAPHQL_CONNECTIONS_PER_READ_REPLICA``
``HASURA_GRAPHQL_STRIPES_PER_READ_REPLICA``