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

# PostgreSQL

> Connect PostgreSQL to query your database and analyze your data with natural language

Connect Adapt to PostgreSQL to query your database and analyze your data using
natural language. Adapt connects to your database through a standard connection
string, so you can explore tables and pull insights without writing SQL by hand.

## Set up credentials

Adapt connects to PostgreSQL using a single connection string in the standard
format:

```
postgresql://user:password@host:port/dbname
```

<Steps>
  <Step title="Gather your connection details">
    Collect the values for your database:

    * **Host**: the server address (for example `db.example.com` or an IP)
    * **Port**: the PostgreSQL port, `5432` by default
    * **Database name**: the database you want to query
    * **User** and **password**: the credentials Adapt will authenticate with
  </Step>

  <Step title="Create a read-only role (recommended)">
    For safety, create a dedicated read-only role and grant it `SELECT` on the
    schemas you want Adapt to access, rather than using a superuser account.
  </Step>

  <Step title="Assemble the connection string">
    Combine the values into one string:

    ```
    postgresql://user:password@host:5432/dbname
    ```

    If your server requires SSL, append `?sslmode=require` to the end. Any
    special characters in the password must be percent-encoded.
  </Step>
</Steps>

<Note>
  If your database is behind a firewall or private network, make sure the host is
  reachable and that any required IP addresses are allowlisted.
</Note>

## Connect to Adapt

<Steps>
  <Step title="Open Integrations">
    In Adapt, go to **Settings > Integrations**.
  </Step>

  <Step title="Find PostgreSQL">
    Search for **PostgreSQL** and select it from the catalog.
  </Step>

  <Step title="Start the connection">
    Click **Connect** to open the connection form.
  </Step>

  <Step title="Add your credentials">
    Enter the values you gathered above, then click **Add connection**:

    | Secret Name             | Value                             |
    | ----------------------- | --------------------------------- |
    | `POSTGRES_DATABASE_URL` | Your PostgreSQL connection string |

    You can rename the connection and choose whether it is shared with your
    organization or kept personal to you.
  </Step>

  <Step title="Test the connection">
    Ask Adapt to list your tables or query your data.
  </Step>
</Steps>

### Security

* Credentials are encrypted at rest with AES-256
* Use a dedicated read-only role with `SELECT`-only privileges
* Connect over SSL (`sslmode=require`) whenever your server supports it
* Restrict network access to your database and allowlist only trusted addresses
* Never share your connection string publicly or commit it to source control

## Capabilities

Adapt can query your PostgreSQL database. Explore your tables and analyze your
data using natural language.

### Examples

Explore data:

```
What tables are in my PostgreSQL database?
```

Inspect a table:

```
Show me the columns and types in the orders table.
```

Summarize records:

```
How many customers signed up in the last 30 days?
```

Analyze trends:

```
What are my top 10 products by total revenue this year?
```
