> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lerian.studio/llms.txt
> Use this file to discover all available pages before exploring further.

# Add a Data Source

> Configure an external database connection when Reporter needs a Data Source that is not already available.

Use this page to create a Data Source when Reporter needs to read from an external database or from a connection that is not already configured. If the report uses internal Lerian product data, such as Midaz or CRM, the Data Source may already exist.

## Objective

***

Configure an external connection that Templates and Reports can use.

For example, create a Data Source named `production-postgres` that points to an external reporting database, or `compliance-readonly` for a read-only database user used by reporting operators.

## When to use

***

Use this task when:

* the required Data Source is not already available in Reporter;
* a new database must feed reports;
* an existing report process needs a separate read-only connection;
* operators need schemas and fields available in Template Builder or report filters.

Before adding one, check whether the required internal Data Source already exists. Creating a duplicate external connection is unnecessary when Reporter already has the source configured.

Do not use this task to fix an existing connection. Use [Edit a Data Source](/en/lerian-console/reporter-console/editing-a-data-source) and [Test a Data Source Connection](/en/lerian-console/reporter-console/testing-a-data-source).

## Before you start

***

Have these details ready:

* host, port, and database name;
* username and password;
* schema names, when the database uses schemas;
* SSL requirements and CA certificate, when required by infrastructure;
* a clear connection name, such as `production-postgres` or `compliance-readonly`.

<Warning>
  Use credentials intended for reporting access. A Data Source gives Reporter access to read data used in Templates and Reports.
</Warning>

## Step by step

***

<Steps>
  <Step title="Open Data Sources">
    Go to **Data Sources** and click **Add Data Source**.
  </Step>

  <Step title="Fill in connection details">
    In **Add Data Source**, enter **Connection Name**, **Database Type**, **Host**, **Port**, **Database Name**, **Username**, and **Password**.
  </Step>

  <Step title="Configure schemas when needed">
    For database types where the Console shows **Schemas** (currently PostgreSQL in the selector), add the schemas that Reporter should inspect. Type a schema name and click **Add**, or press **Enter**.
  </Step>

  <Step title="Configure SSL when required">
    Expand **SSL Configuration**, turn on **Enable SSL**, select **SSL Mode**, and paste the **CA Certificate** if your infrastructure requires it.
  </Step>

  <Step title="Add metadata when useful">
    Expand **Metadata** to add key-value fields that help operators classify the connection.
  </Step>

  <Step title="Create the Data Source">
    Click **Create**.
  </Step>

  <Step title="Test the connection">
    The new Data Source appears with **Disconnected** status. Run **Test Connection** before using it in Templates or Reports.
  </Step>
</Steps>

## Field guide

***

| Field                         | What to enter                                                                                                                       | Example                         |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- |
| **Connection Name**           | Required operator-facing name. Technical field: `configName`. Console validation: 3 to 100 characters.                              | `production-postgres`           |
| **Database Type**             | Required database engine. Console currently offers `POSTGRESQL` and `MONGODB`. Technical field: `type`.                             | `POSTGRESQL`                    |
| **Host**                      | Required database server address, not an application URL. Technical field: `host`.                                                  | `db.example.com`                |
| **Port**                      | Required database port. Technical field: `port`; valid range is 1 to 65535.                                                         | `5432`                          |
| **Database Name**             | Required database name Reporter will query. Technical field: `databaseName`.                                                        | `ledger`                        |
| **Username**                  | Required database user. Technical field: `username`.                                                                                | `reporter_readonly`             |
| **Password**                  | Required secret when creating a Data Source. Technical field: `password`.                                                           | Stored through the form         |
| **Schemas**                   | Optional schema list for supported database types. Stored as `metadata.schemas`; entries are trimmed, lowercased, and deduplicated. | `public`, `pix`, `transactions` |
| **Enable SSL**                | Optional SSL toggle. When enabled, the connection payload includes `ssl`.                                                           | Enabled                         |
| **SSL Mode**                  | Required when SSL is enabled. Use `disable`, `require`, `verify-ca`, or `verify-full`. Technical field: `ssl.mode`.                 | `verify-ca`                     |
| **CA Certificate**            | Required for `verify-ca` and `verify-full`. Technical field: `ssl.ca`.                                                              | PEM CA certificate              |
| **Metadata** key/value fields | Optional operator classification data. Only rows with a nonblank key are submitted. Technical field: `metadata`.                    | `environment = production`      |

## Expected result

***

The new external Data Source appears on the **Data Sources** page with **Disconnected** status until tested. After a successful test, operators can use its fields in Templates and Reports.

## Common errors and care points

***

<AccordionGroup>
  <Accordion title="Using an application URL as Host">
    **Host** should be the database server address, such as `db.example.com`, not the URL of an application or admin panel.
  </Accordion>

  <Accordion title="Skipping schemas">
    If the database uses schemas and the required schema is not listed, operators may not see the expected tables and fields.
  </Accordion>

  <Accordion title="Ignoring SSL requirements">
    If infrastructure requires SSL or a CA certificate, the connection can fail until **SSL Configuration** matches that requirement.
  </Accordion>

  <Accordion title="Using unclear names">
    Names like `db1` are hard to use safely. Prefer names that show environment and purpose, such as `production-compliance-readonly`.
  </Accordion>
</AccordionGroup>

## Next steps

***

* Use [Test a Data Source Connection](/en/lerian-console/reporter-console/testing-a-data-source) immediately after creation.
* Use [Template Builder](/en/lerian-console/reporter-console/template-builder) to use fields from the Data Source in a Template.
* Use [Generate a Report](/en/lerian-console/reporter-console/generating-a-report) after the Template and Data Source are ready.

<Card title="API equivalent" type="tip" horizontal>
  [Create connection endpoint](/en/reference/reporter/connections/create-connection)
</Card>
