Prerequisites
- A PostgreSQL database (self-hosted, RDS, Cloud SQL, Supabase, or compatible) reachable from AgentRuntime
- A connection string (DSN) with credentials scoped to the operations your workflows need
SELECTfor reporting;INSERT/UPDATE/DELETEonly when workflows must write- TLS configured for production (
sslmode=requireor stricter in the DSN) - project_contributor access
Connect in AgentRuntime
Create a connection
Go to Connections and click New custom connection to create a connection string connection with your Postgres DSN:Use a read-only role for reporting workflows. Grant write privileges only when steps call
postgres_exec.Add postgres MCP instance
Go to MCP, click Add instance for postgres, wire your connection on Instance config, set the profile active, and save.
Test with a health check
Add a workflow with a single mcp_call to
postgres_health. Run it to confirm connectivity before adding production queries.What you can build
- Operational reports — Scheduled
postgres_queryon KPI tables → LLM narrative → Gmail or Resend digest. - Enrichment pipeline — External API fetch →
postgres_execINSERT with$1args → downstream sync to Google Sheets. - Approval-gated writes — human_task before
postgres_execUPDATE/DELETE on production tables. - Schema-aware agents —
postgres_list_tables+postgres_describe_table+postgres_explain_query→ Autopilot answers with grounded SQL.
Tools
| Tool | Description |
|---|---|
postgres_health | Check PostgreSQL connectivity with a simple query |
postgres_query | Run a read-only query with optional args and row limit |
postgres_exec | Run a mutating statement (INSERT, UPDATE, DELETE, DDL) |
postgres_list_tables | List user tables in the current database |
postgres_describe_table | Describe columns, types, nullability, and defaults |
postgres_list_schemas | List non-system PostgreSQL schemas |
postgres_list_indexes | List indexes for a table |
postgres_get_table_ddl | Return the CREATE TABLE DDL for a table |
postgres_explain_query | Run EXPLAIN or EXPLAIN ANALYZE for a query |
Example
Fetch pending orders for a daily report:lua_script step:
Configuration
| Key | Required | Default | Description |
|---|---|---|---|
postgres_dsn | Yes | — | PostgreSQL connection string (lib/pq DSN) |
postgres_request_timeout_sec | No | 30 | Per-request timeout in seconds for queries and ping |
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 |
|---|---|
| Connection timeout | Check network path, firewall rules, and DSN host/port |
permission denied | Grant the DB user SELECT (and write privileges only if needed) on target tables |
| SSL errors | Adjust sslmode in the DSN to match your server configuration |
| Slow queries | Use postgres_explain_query with analyze: true to inspect the execution plan |
Related
- Integrations quickstart
- MySQL connector — similar SQL patterns for MySQL
- Connector catalog
- Troubleshooting