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: SELECT for reporting, plus INSERT, UPDATE, or DELETE only 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. Set sslmode to match your server (for example require for managed databases that enforce TLS).
  • Permission in your workspace to create connections and MCP instances (MCP write permission).

Connect in AgentRuntime

  1. 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_dsn and Value set to your DSN, for example postgres://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.

  2. 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.

  3. Smoke test with an MCP step

    In Workflow Studio, create a workflow with a single mcp step using tool_name postgres_health and run it. A result of {"ok": true} means AgentRuntime can log in to your database.

  4. Look around (optional)

    Run postgres_list_schemas and postgres_list_tables to 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_query against 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_exec using $1, $2 placeholders, or use postgres_transaction when several tables must change together.
  • Approval before changes. Put a human approval step before a postgres_exec that updates or deletes production rows.
  • Schema-aware agents. Let an agent call postgres_list_tables, postgres_describe_table, and postgres_explain_query so the SQL it writes matches your real schema.

Tools

ToolWhat it does
postgres_healthCheck that the database is reachable (runs SELECT 1).
postgres_queryRun a read-only SELECT or WITH query; returns up to 200 rows.
postgres_execRun one INSERT, UPDATE, DELETE, or DDL statement. Writes data.
postgres_transactionRun up to 20 mutating statements as one transaction: all commit or all roll back. Writes data.
postgres_list_schemasList schemas, excluding system schemas.
postgres_list_tablesList tables in a schema (default public).
postgres_describe_tableShow columns, data types, nullability, and defaults for a table.
postgres_list_indexesList the indexes on a table.
postgres_get_table_ddlReturn a CREATE TABLE statement built from the table's columns.
postgres_explain_queryShow 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 as rows and count.
  • postgres_exec: sql (required), args. Returns rows_affected and ok. SELECT and WITH statements are rejected; use postgres_query.
  • postgres_transaction: statements (required), an ordered array of objects with sql and optional args. Returns statement_count, per-statement results, and committed.
  • postgres_list_tables: schema (optional). postgres_describe_table, postgres_list_indexes, postgres_get_table_ddl: table (required) and schema (optional, default public).
  • 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:

KeyRequiredDefaultDescription
postgres_dsnYesnonePostgreSQL connection string.
postgres_request_timeout_secondsNo30Per-request timeout in seconds for queries and the connection check.
postgres_max_open_connsNo10Maximum open connections in the pool.
postgres_max_idle_connsNo5Maximum idle connections kept in the pool.

Troubleshooting

IssueFix
missing config: postgres_dsnThe 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 refusedCheck the host and port in the DSN and that your firewall or security group allows the connection.
permission deniedGrant the database user the privileges the statement needs on that table.
SSL errorsChange sslmode in the DSN to match your server (for example require).
postgres_query only allows SELECT/CTE queriesUse postgres_exec for writes.
multiple SQL statements are not allowedSend one statement per call, or use postgres_transaction for several writes.
Slow queriesRun postgres_explain_query to inspect the plan.
Edit this pageagentruntime-io/agentruntime-docs