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

# Databases

> Connect your own PostgreSQL database to Studio, then read and change it from workflows with Execute SQL and fill form dropdowns from it.

Data > Databases connects Triggr to a PostgreSQL database you run, so workflows can query and change it with Execute SQL and forms can list options from it. You need the [Admin role](https://kb.mspprocess.com/studio/clients/team-and-permissions.md#roles).

<video controls preload="none" playsInline poster="/images/videos/studio-databases.jpg" src="https://mintcdn.com/triggr/GxrCQFDFNLmEMyJ1/images/videos/studio-databases.mp4?fit=max&auto=format&n=GxrCQFDFNLmEMyJ1&q=85&s=bf227b010af284518d73ccdf30e4fefa" />

Connect a database: connecting PostgreSQL, querying it from a workflow and filling a dropdown from it (1:28).

![The Databases page, Manage your external database connections, with Refresh and New Connection buttons and one connection, Docs sample – MSP data, type postgresql, database msp\_data, with Test Connection, Edit and delete actions.](https://mintcdn.com/triggr/_d7ojda9vf8IHE31/images/studio/data/databases.png?fit=max\&auto=format\&n=_d7ojda9vf8IHE31\&q=85\&s=99fa99f7dc4051e3c3b7366ebea6b233)

## Connect a database

**1. Let Triggr in**

The database needs a public address. Allow [Triggr's IP addresses](https://kb.mspprocess.com/security/ip-allowlist.md) to its port (usually 5432), and create a database user with only the rights your workflows need.

**2. Start a connection**

Click **New Connection**, then **Connection String** (or Manual Setup to type each detail).

![The Create New Database Connection dialog offering Manual Setup, to enter database connection details manually, or Connection String, to paste your database connection string.](https://mintcdn.com/triggr/_d7ojda9vf8IHE31/images/studio/data/new-connection.png?fit=max\&auto=format\&n=_d7ojda9vf8IHE31\&q=85\&s=1009a82660fc194785b2b80c70ebfc30)

**3. Paste the connection string**

Paste it as `postgresql://user:password@host:5432/database?sslmode=require` and click **Continue**.

![The Enter Connection String dialog with a connection string for user triggr\_app, a password placeholder and host db.yourmsp.com entered, and Back and Continue buttons.](https://mintcdn.com/triggr/_d7ojda9vf8IHE31/images/studio/data/connection-string.png?fit=max\&auto=format\&n=_d7ojda9vf8IHE31\&q=85\&s=1f1a9f5fb6095b06fd136242d0a2fae0)

**4. Check the details**

Rename the connection (it starts as the database name), type the password if the string had none or it has symbols in it, and click **Create Connection**.

![The Create New Database Connection form with Name Docs sample – MSP data, Type PostgreSQL, Host db.yourmsp.com, Port 5432, Database Name msp\_data, Username triggr\_app, a masked Password, SSL Mode Require, and Back and Create Connection buttons.](https://mintcdn.com/triggr/_d7ojda9vf8IHE31/images/studio/data/connection-details.png?fit=max\&auto=format\&n=_d7ojda9vf8IHE31\&q=85\&s=77c539799552fa62f3307f18dfa72b0c)

Leave SSL Mode on Require, or choose Verify Full to also check the server's certificate against its host name.

**5. Test it**

Click **Test Connection** on the connection's row: it should say "successfully connected to the database" (otherwise see [Troubleshooting](#troubleshooting)).

## Query it from a workflow

Add **Execute SQL** from Database, choose the database and replace the example query in SQL Query with yours; this one finds yesterday's failed backups in a `backup_results` table.

![The Find Failed Backups step: Database Docs sample – MSP data and a SQL Query selecting client, device and finished\_at from backup\_results where status is failed and finished\_at is within the last day, ordered by client.](https://mintcdn.com/triggr/_d7ojda9vf8IHE31/images/studio/data/execute-sql-step.png?fit=max\&auto=format\&n=_d7ojda9vf8IHE31\&q=85\&s=6c0a147e101907304a09de44f28bd493)

The output lists the rows in `data`, every value as text (empty for `NULL`).

```json theme={null}
{
  "success": true,
  "data": [
    { "client": "Acme Corp", "device": "ACME-NAS01", "finished_at": "2026-10-15T23:40:00Z" },
    { "client": "Globex", "device": "GLOBEX-HV02", "finished_at": "2026-10-15T23:55:00Z" }
  ]
}
```

Loop over the rows with a For Loop on `ctx.steps['Find Failed Backups'].data`, or read one value with `{{ ctx.steps['Find Failed Backups'].data[0].client }}`. A single row with a column named `count`, `sum`, `avg`, `min`, `max` or `total` also arrives as a number in `value`.

### Change data

`INSERT`, `UPDATE` and `DELETE` work too; add `RETURNING id` to get the new rows back in `data`. Create tables with your own database tool. Each query has 30 seconds.

### Put values in a query

Templates become part of the SQL text, so quote text values and only use values you trust:

```sql theme={null}
INSERT INTO backup_results (client, device, status, finished_at)
VALUES ('{{ ctx.client.name }}', '{{ ctx.params.device }}', '{{ ctx.params.status }}', now())
```

An apostrophe in a value, such as `O'Brien`, breaks the query and could change what it does. For anything a person or another system typed, double the apostrophes in a Code step first, as the Evaluate step does in the [uptime monitor](https://kb.mspprocess.com/studio/internal-apps/example-uptime-monitor.md).

## Use it in forms

A Select field can list options from your database: set **Options Source** to Use database, choose the connection and write a query that returns a value column and a label column. `{{ ctx.client.variableName }}` inserts a [client variable](https://kb.mspprocess.com/studio/clients/clients-and-variables.md) of the person's client. Test Query runs the query as typed, so test it without templates first.

![A Select field's Options Source set to Use database, Database Connection Docs sample – MSP data (postgresql), a SQL Query selecting site\_id and site\_name from client\_sites where halo\_client\_id equals the client's haloId variable, Value Column site\_id and Label Column site\_name.](https://mintcdn.com/triggr/_d7ojda9vf8IHE31/images/studio/data/form-database-options.png?fit=max\&auto=format\&n=_d7ojda9vf8IHE31\&q=85\&s=47fe18b02c6b6bca20d96afe02caf82d)

Forms with Microsoft or Google sign-in can also check a database before letting someone in (Optional Authorization in [Form authentication](https://kb.mspprocess.com/studio/forms/authentication.md)).

## Security

Triggr stores the password encrypted, and every Execute SQL step runs as the database user you entered, whoever runs the workflow. Anyone with the Admin role can edit connections and write queries against them.

## Troubleshooting

> [accordion] “failed to connect to database: dial tcp: lookup … no such host”
>
> The host isn't a public DNS name; use the database's internet-facing address.
>
> ![The Test Database Connection dialog with a red cross and the message failed to connect to database: dial tcp: lookup db.yourmsp.com: no such host.](https://mintcdn.com/triggr/_d7ojda9vf8IHE31/images/studio/data/test-connection-failed.png?fit=max\&auto=format\&n=_d7ojda9vf8IHE31\&q=85\&s=a27c0bb7d0c95bafa29a847a60cbd2af)

> [accordion] Test Connection waits, then fails with a timeout or “connection refused”
>
> Port 5432 is blocked from Triggr. Allow [Triggr's IP addresses](https://kb.mspprocess.com/security/ip-allowlist.md) in your firewall, and check PostgreSQL listens on the public address.

> [accordion] “pq: password authentication failed for user …”
>
> Click **Edit** on the connection and retype the password; one pasted in a connection string keeps symbols such as `@` encoded.

> [accordion] “pq: SSL is not enabled on the server”
>
> Turn on SSL in PostgreSQL so the password and data are encrypted on their way to Triggr.

> [accordion] “SQL query failed: invalid SQL query: …”
>
> Triggr checks each query before running it; the rest of the message is the problem: a syntax error, a missing table, a statement such as `CREATE TABLE`, or a connection error like those above.
>
> ![A failed Find Failed Backups step in a run, with Status error, Type execute\_sql and Output error SQL query failed: invalid SQL query: dial tcp: lookup db.yourmsp.com: no such host.](https://mintcdn.com/triggr/_d7ojda9vf8IHE31/images/studio/data/execute-sql-error.png?fit=max\&auto=format\&n=_d7ojda9vf8IHE31\&q=85\&s=79bd1a594679a4cc68bc9482fa6bdd7d)

> [accordion] “Invalid connection string format. Please check and try again.”
>
> Match `postgresql://user:password@host:5432/database`, or choose Manual Setup and type the details.

> [accordion] Which databases can I connect?
>
> PostgreSQL. For small registers you don't need SQL for, use [Data tables](https://kb.mspprocess.com/studio/data/data-tables.md).


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