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

# PostgreSQL

> Connect PostgreSQL to ClarityQ

## Setup

### Step 1: Create a dedicated database user

Connect to your PostgreSQL database and create a service account for ClarityQ:

```sql theme={null}
-- Create the ClarityQ user
CREATE USER clarityq_user WITH PASSWORD 'your_secure_password';

-- Grant database connection privilege
GRANT CONNECT ON DATABASE your_database TO clarityq_user;
```

### Step 2: Configure schema and table permissions

Grant the necessary permissions for ClarityQ to discover schemas, query data, and perform analytics:

```sql theme={null}
-- Grant schema usage for data schemas
GRANT USAGE ON SCHEMA public TO clarityq_user;
GRANT USAGE ON SCHEMA your_schema TO clarityq_user;

-- Grant schema access for metadata discovery
GRANT USAGE ON SCHEMA information_schema TO clarityq_user;
GRANT USAGE ON SCHEMA pg_catalog TO clarityq_user;

-- Grant SELECT on existing tables for data querying
GRANT SELECT ON ALL TABLES IN SCHEMA public TO clarityq_user;
GRANT SELECT ON ALL TABLES IN SCHEMA your_schema TO clarityq_user;

-- Grant SELECT on system tables for schema introspection
GRANT SELECT ON ALL TABLES IN SCHEMA information_schema TO clarityq_user;
GRANT SELECT ON ALL TABLES IN SCHEMA pg_catalog TO clarityq_user;


-- Grant access to views for complete schema discovery
GRANT SELECT ON ALL TABLES IN SCHEMA information_schema TO clarityq_user;

```

### Step 3: Configure network access

Ensure your PostgreSQL database allows connections from the following ClarityQ IP addresses:

* 44.218.213.75
* 54.161.37.107
* 54.208.212.67

Configure your firewall, security groups, or database access rules to allow inbound connections from these IPs on port 5432.

### Step 5: Add connection in ClarityQ

In the ClarityQ interface, fill out the connection form with the following fields:

* **Connection Name**: Choose a name for this connection (e.g., "Production PostgreSQL")
* **Host**: Your PostgreSQL server hostname or IP address (e.g., `db.example.com`)
* **Port**: `5432` (default, pre-filled)
* **Database**: Your database name (e.g., `analytics_db`)
* **User**: `clarityq_user` (the user you created in Step 1)
* **Password**: The password you set for `clarityq_user`

## Connection parameters reference

### Required parameters

| Parameter         | Type   | Description                            | Example           |
| ----------------- | ------ | -------------------------------------- | ----------------- |
| `connection_name` | string | Unique identifier for this connection  | `Production DB`   |
| `host`            | string | Database server hostname or IP address | `db.example.com`  |
| `database`        | string | Target database name                   | `analytics_db`    |
| `user`            | string | PostgreSQL username                    | `clarityq_user`   |
| `password`        | string | User password                          | `secure_password` |

### Optional parameters

| Parameter | Type   | Default  | Description            |
| --------- | ------ | -------- | ---------------------- |
| `port`    | number | `5432`   | PostgreSQL server port |
| `schema`  | string | `public` | Default schema         |
