Postgres connector
Query, inspect, and update PostgreSQL databases from AgentRuntime workflow steps.
On this page
The postgres connector lets workflow steps run SQL against a PostgreSQL database you own. It can read data, describe tables and indexes, explain query plans, and (when you allow it) write data. Use it to pull numbers into reports, record results from other tools in your own tables, or give an agent a way to look at your schema. If you also run MySQL, see the MySQL connector.
Prerequisites
- A PostgreSQL database that AgentRuntime can reach over the network (self-hosted or managed, for example Amazon RDS, Cloud SQL, or Supabase). Allow inbound connections from the internet or from AgentRuntime in your firewall or security group as your setup requires.
- A database user and password. Create a dedicated user and give it only what your workflows need:
SELECTfor reporting, plusINSERT,UPDATE, orDELETEonly if a step must write. - The connection string (DSN) for that user, in the form
postgres://user:password@host:5432/dbname?sslmode=require. Your database host or cloud console shows the host, port, and database name. Setsslmodeto match your server (for examplerequirefor managed databases that enforce TLS). - Permission in your workspace to create connections and MCP instances (MCP write permission).
Connect in AgentRuntime
- Create a connection
Open Connections in the Console and click New custom connection. Optionally set a Display name, then under Credentials add one row with Key
postgres_dsnand Value set to your DSN, for examplepostgres://reporting_user:your-password@db.example.com:5432/appdb?sslmode=require. Click Save.The dialog also asks who can use the connection; choose the sharing option that fits your team.
- Add the postgres MCP instance
Open MCP, click Add connectors, click the postgres connector, then Add to workspace. Open Instance config, select your connection in the Connection picker, make sure the profile is active, and save.
- Smoke test with an MCP step
In Workflow Studio, create a workflow with a single
mcpstep usingtool_namepostgres_healthand run it. A result of{"ok": true}means AgentRuntime can log in to your database. - Look around (optional)
Run
postgres_list_schemasandpostgres_list_tablesto confirm you are connected to the database you expect.
See Authentication for how connections are bound to MCP instances.
What you can build
- Daily KPI digest. Run
postgres_queryagainst your metrics tables on a schedule, have an LLM step write a summary, and send it by email. - Record results from other tools. Take data from an API call or form and store it with
postgres_execusing$1,$2placeholders, or usepostgres_transactionwhen several tables must change together. - Approval before changes. Put a
humanapproval step before apostgres_execthat updates or deletes production rows. - Schema-aware agents. Let an agent call
postgres_list_tables,postgres_describe_table, andpostgres_explain_queryso the SQL it writes matches your real schema.
Tools
| Tool | What it does |
|---|---|
postgres_health | Check that the database is reachable (runs SELECT 1). |
postgres_query | Run a read-only SELECT or WITH query; returns up to 200 rows. |
postgres_exec | Run one INSERT, UPDATE, DELETE, or DDL statement. Writes data. |
postgres_transaction | Run up to 20 mutating statements as one transaction: all commit or all roll back. Writes data. |
postgres_list_schemas | List schemas, excluding system schemas. |
postgres_list_tables | List tables in a schema (default public). |
postgres_describe_table | Show columns, data types, nullability, and defaults for a table. |
postgres_list_indexes | List the indexes on a table. |
postgres_get_table_ddl | Return a CREATE TABLE statement built from the table's columns. |
postgres_explain_query | Show the query plan for a SELECT or WITH query; with analyze true it actually runs the query. |
Parameters:
postgres_query:sql(required),args(array for$1,$2, ...),limit(default 100, maximum 200). Results are returned asrowsandcount.postgres_exec:sql(required),args. Returnsrows_affectedandok.SELECTandWITHstatements are rejected; usepostgres_query.postgres_transaction:statements(required), an ordered array of objects withsqland optionalargs. Returnsstatement_count, per-statement results, andcommitted.postgres_list_tables:schema(optional).postgres_describe_table,postgres_list_indexes,postgres_get_table_ddl:table(required) andschema(optional, defaultpublic).postgres_explain_query:sql(required),args,analyze(optional boolean).
Each call accepts a single SQL statement. Queries run in a read-only transaction.
Example
Fetch pending orders for a daily report:
{
"id": "fetch-orders",
"type": "mcp",
"name": "Fetch pending orders",
"instance_id": "REPLACE_POSTGRES_INSTANCE",
"tool_name": "postgres_query",
"tool_args": {
"sql": "SELECT id, email, total FROM orders WHERE status = $1",
"args": ["pending"],
"limit": 100
},
"timeout_s": 30
}Use the rows in a later step with {{steps.fetch-orders.result.rows}}.
Configuration
Connection keys (the connection's Key names) and what they do:
| Key | Required | Default | Description |
|---|---|---|---|
postgres_dsn | Yes | none | PostgreSQL connection string. |
postgres_request_timeout_seconds | No | 30 | Per-request timeout in seconds for queries and the connection check. |
postgres_max_open_conns | No | 10 | Maximum open connections in the pool. |
postgres_max_idle_conns | No | 5 | Maximum idle connections kept in the pool. |
Troubleshooting
| Issue | Fix |
|---|---|
missing config: postgres_dsn | The connection has no postgres_dsn key, or the instance profile is not wired to it. Check the connection's keys and Instance config. |
| Timeout or connection refused | Check the host and port in the DSN and that your firewall or security group allows the connection. |
permission denied | Grant the database user the privileges the statement needs on that table. |
| SSL errors | Change sslmode in the DSN to match your server (for example require). |
postgres_query only allows SELECT/CTE queries | Use postgres_exec for writes. |
multiple SQL statements are not allowed | Send one statement per call, or use postgres_transaction for several writes. |
| Slow queries | Run postgres_explain_query to inspect the plan. |