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

# PostgreSQL

> Connect PostgreSQL for read-only querying during investigations.

Connect PostgreSQL so Struct Agent can query application data during investigations. Use the documented read-only role and verify the intended database.

## Inspect access and existing connections

Use a claimed workspace with permission to configure connections.

```bash theme={null}
struct whoami --json
struct connections catalog postgres --json
struct connections list --json
```

Use the catalog's current fields, choices and permission requirements. Reuse an existing healthy connection instead of creating a duplicate.

## Connect with the CLI

Supply credentials from approved secret storage through `PGPASSWORD`, `POSTGRES_CONNECTION_STRING`. The catalog describes which are needed for the selected authentication method. Do not put literal secrets in shell arguments or chat.

Replace example values with the intended resource:

```bash theme={null}
struct connect postgres --host <host> --database <database> --user <username>
```

Use `PGPASSWORD` from a secret manager. The default port is 5432 and SSL mode is `require`; choose `verify-full` when the certificate chain is supported. Private CA files are not supported. For a connection string, use `--connection-string-env PG_URL`. Add `--test-only` to check without saving, and inspect `ok` even when the exit code is zero. See [SSH tunnels](https://docs.struct.ai/integrations/ssh-tunnels.md) for private networks.

## Verify and recover

Use the returned connection ID:

```bash theme={null}
struct connections show CONNECTION_ID --json
struct connections test CONNECTION_ID --json
```

Inspect `ok`, `health` and missing permissions, not only the exit code. `struct connections grant-command CONNECTION_ID` prints repair instructions where supported; have an authorized operator apply them. For expired OAuth links, start the connection command again and use the new link. Do not reconnect to a different account silently.

Verify a bounded operation for the requested job. Connection health proves checked access; it does not prove telemetry arrival, an investigation or alert delivery.

## What Struct does with it

Answers data questions during investigations, such as how many orders failed in a window, and measures the impact of [Issues](https://docs.struct.ai/agent/jobs/issues.md) with live queries you can inspect.

## Permissions

Use a dedicated read-only role with USAGE and SELECT on the schemas Struct should query. Struct runs every query in a read-only transaction and never writes to your database.

### Read-only queries

Answer data questions during investigations and measure the impact of open issues.

| Grant | Used for |
| - | - |
| `CONNECT` | On the database |
| `USAGE` | On each schema Struct should query |
| `SELECT` | On the tables in those schemas, including tables created later through default privileges |

* Grant schemas one by one rather than `pg_read_all_data`: that role reads every table in every database on the server, and limiting `CONNECT` does not narrow it.

### How to grant

> [accordion] Create a read-only role
>
> ```sql theme={null}
> CREATE ROLE "struct_reader" LOGIN PASSWORD '<password>';
> GRANT CONNECT ON DATABASE "<database>" TO "struct_reader";
> -- Before running the schema grants below, reconnect to "<database>". Repeat them for each chosen schema.
> GRANT USAGE ON SCHEMA "public" TO "struct_reader";
> GRANT SELECT ON ALL TABLES IN SCHEMA "public" TO "struct_reader";
> -- Tables created later: run this as the role that creates them (for example your migration user).
> ALTER DEFAULT PRIVILEGES IN SCHEMA "public" GRANT SELECT ON TABLES TO "struct_reader";
> ```

Replace the values in angle brackets.

Permission catalog version `2026-11-04.1`. See [permission changes](https://docs.struct.ai/reference/permission-changes.md).


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