> For the complete documentation index, see [llms.txt](https://docs.rootcause.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rootcause.ai/data-sources-and-connectors/connectors/postgresql.md).

# PostgreSQL

Connect RootCause to a PostgreSQL database to import tables, run custom queries, or query the database directly without importing.

***

### Prerequisites

* Hostname or IP, port (default 5432), database name and schema (default public)
* A user with read access to the tables you want, ideally read-only
* Network access from RootCause to the database (firewall rules, VPN)

***

### Setting up the connection

1. In the Import Manager, click the **PostgreSQL** card
2. Enter your connection details:

| Field               | Description                           | Example          |
| ------------------- | ------------------------------------- | ---------------- |
| Host                | Database server hostname or IP        | `db.example.com` |
| Port                | PostgreSQL port                       | `5432`           |
| Database            | Database name                         | `analytics`      |
| Schema              | Default schema for queries (optional) | `public`         |
| Username / Password | Database user                         | `readonly_user`  |
| Enable SSL          | Encrypted connection, recommended     | On               |

3. Click **Test connection** to verify, then **Save & continue**

***

### Importing data

**Tables**: browse schemas and tick one or more tables; each becomes its own source. **Custom Query**: write SQL to join, filter or aggregate before import.

<figure><img src="https://1662811113-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBXg3gZLR0e2Q8SzeQmql%2Fuploads%2Fgit-blob-57f597ce171fc7db8d5443f689a84a4b9ae096f6%2Frc-postgres-import-settings.png?alt=media" alt="PostgreSQL import settings with schema browser and selected tables"><figcaption><p>Tables mode: browse the live schema and tick tables; each becomes its own source.</p></figcaption></figure>

***

### Import modes

All six modes: Full Import, Full Import + Live, Recent Rows, Time Period, Date Range (PostgreSQL is the only connector that offers it) and Query Directly. Rolling windows are resolved by the database itself, so only the selected rows are read. See [Connectors](/data-sources-and-connectors/connectors.md) for what each mode means.

***

### Troubleshooting

**Connection timeout**

* Check host, port and firewall rules, and that the database accepts remote connections

**Authentication failed**

* Verify the credentials and that the user has CONNECT on the database and access to the schema

**Permission denied on table**

* Grant SELECT on the required tables
