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

# SQL database

> Let Attlas query your SQL databases directly to analyze data and answer complex questions in real time.

The SQL database integration (PostgreSQL-compatible) connects a database to your chat. Attlas reads the structure of the tables you choose to share and writes read-only queries to answer your visitors' questions with live data.

It works with any PostgreSQL database, and Supabase is the easiest place to start.

***

## **🛠️ How to connect**

1. Go to your **Chat Settings** > **Integrations** > **SQL Database**.
2. Click **Connect** and fill in your database details:
   * **Name & Description:** A friendly name and description to help the AI understand what data is inside.
   * **Currency (Optional):** The primary currency used for monetary values in your tables, helping the AI format and interpret financial data.
   * **Host & Port:** Your database server address and port (default is `5432` for PostgreSQL).
   * **Database:** The name of your database.
   * **User & Password:** Your database credentials (ideally read-only).
   * **SSL Mode:** Select `require` or `disable`.
3. Click **Test** to verify the credentials and see how many tables are found.
4. Click **Save** to finish.

***

## Connect a Supabase database

Supabase shows two kinds of connection details. Use the pooler one.

> [!WARNING]
>
> The **Direct connection** host (`db.<project-ref>.supabase.co`) only works over IPv6, and Attlas connects over IPv4. It fails with an `ENETUNREACH` error.

1. In your Supabase project, click **Connect** at the top of the dashboard.
2. Open the **Session pooler** tab.
3. Copy the values into the form:

| Field | Value |
| - | - |
| Host | `aws-0-<region>.pooler.supabase.com` |
| Port | `5432` |
| Database | `postgres` |
| User | `postgres.<project-ref>` (keep the `.<project-ref>` suffix) |
| Password | Your database password |
| SSL Mode | `require` |

> [!TIP]
>
> If you see "Tenant or user not found", check that your user includes the project reference. If you forgot the password, reset it from the same Supabase page.

***

## Fill in the connection details

Click the Connect button to open the form and fill in the following fields:

| Field | Description example |
| - | - |
| Name | A friendly name to identify this connection |
| Description | A description of what the database does (helps Attlas understand the context of the data) |
| Currency | The primary currency used for monetary data in this database (e.g., USD, EUR), optional |
| Host | The address of your database server, for example `aws-0-us-west-1.pooler.supabase.com` or `123.45.67.89` |
| Port | The connection port (5432 by default for PostgreSQL) |
| Database | The name of your database |
| User | The connection username, for example `postgres.<project-ref>` on Supabase |
| Password | The password associated with the user |
| SSL Mode | The security level of the SSL connection |
| Instructions | Optional rules for how Attlas uses this database. Available in the settings once connected |

***

## **⚙️ Managing your integration**

Click **Settings** on your active SQL Database card to manage the following:

* **Select Tables to Share:** Choose which tables or views Attlas can read. Attlas checks this list on every query and blocks any table you did not share, whatever your database user is allowed to read.
* **Instructions:** Write the rules Attlas must follow with your data (see below).
* **Refresh Schema:** After you add or change tables or columns, click **Refresh** to sync them.
* **Temporarily Disable:** Turn the integration on or off with the toggle.
* **Disconnect:** Remove the database connection.

### Instructions

The description says what your database contains. Instructions say how to use it. Write one rule per line, up to 1,000 characters:

```text theme={null}
- Only show projects with status 'published'.
- Prices are stored in cents.
- 'code' is the identifier customers use.
- Never mention units marked 'soldout'.
```

> [!TIP]
>
> Use instructions to hide drafts, explain units, or name the column your customers use to find an item.

### Schemas

Attlas reads every schema in your database, not only `public`. Tables outside `public` appear as `schema.table`, for example `cms.projects`. Internal Supabase schemas (`auth`, `storage`, `realtime`, `vault` and similar) are never read.

> [!NOTE]
>
> Existing connections only see new schemas after you click **Refresh Schema**. Your current table selection stays unchanged.

## **💡 Best practices for database schema**

To help Attlas write accurate queries and perform precise calculations, consider these schema design tips:

* **Use precise column types:** If you want the chat to perform calculations, such as sums, averages, or ratios, on numeric data, ensure those columns use a numeric type, such as `numeric`, `decimal`, `integer`, or `float`. Avoid storing numbers as text, such as `varchar` or `text`, as this makes calculations harder and less accurate.
* **Add column comments:** Use database comments on your tables and columns. Adding a brief description directly to a column, for example `COMMENT ON COLUMN users.status IS 'Active statuses: active, suspended, pending'`, provides crucial context that guides Attlas in writing the correct SQL queries.

***

## **🔒 Security best practices**

To keep your data safe, we highly recommend:

* **Share only what you need:** Attlas rejects any query that touches a table you did not share. Keep tables with personal data or credentials unchecked.
* **Views need their source tables:** A view you share reads from other tables. Those tables must be shared too.
* **Use a read-only user:** Create a database user with only `SELECT` permissions. Attlas only sends read queries, and a read-only user adds a second layer of protection.
* **Keep SSL enabled:** Set `sslmode` to `require` to encrypt data in transit.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.