postgresai
OfficialAn MCP server for the PostgresAI platform that lets an agent manage issues and comments, action items, file attachments, checkup reports, and deploy Postgres monitoring — all against the PostgresAI API/Console.
Issues: list (filter by status/hidden, paginate), view with comments and seen-by, create, update (title, description, status open/closed, labels, hidden), comment and edit/reply to comments.
Action items: list for an issue, view one or many by ID, create (title, description, SQL action, config parameter changes), update (mark done, approve/reject with reason, edit title/description).
Files: upload a local file and get a storage URL plus ready-to-paste markdown link, or download a file by URL/relative path; attachments can be auto-uploaded and appended to issues/comments.
Monitoring deployment: put a database under PostgresAI Cloud monitoring (
pgai mon deploy) — handles role preparation, box provisioning with pricing confirmation, IP allowlisting, RDS PrivateLink (CloudFormation/Terraform), Supabase OAuth consent, ClickHouse/RDS/provider detection, and returns status plus health/dashboard URLs.Checkup reports: list reports (status/project/date filters, fetch all), list a report's files (JSON or markdown, by report or check ID like H002/F004), and fetch the data content of each check.
Multi-org support: most tools accept
org_id(required with a global token, optional with a per-org token), plus adebugflag for verbose logging.
Connects to PostgreSQL 14-18 databases to run 45+ read-only health checks (bloat, indexes, queries, settings, security), collect metrics via pgwatch/Active Session History, and produce AI-ready JSON reports; can also prepare a database by creating a read-only monitoring role, enabling pg_stat_statements and a helper schema.
PostgresAI
Open-source PostgreSQL Monitoring v4 — built for humans and AI agents
One Rust binary (pgai-mon). Parquet on disk or S3. Plain SQL queries via DuckDB. Active Session History (ASH) and continuous Database Health.
Works with Supabase · AWS RDS (incl. PrivateLink) / Aurora (direct) · ClickHouse Managed Postgres · Self-hosted PostgreSQL
PostgresAI Console · Docs · Quick start · Query in SQL · Pricing
The commands below target Monitoring v4; see installation versions for release-channel requirements.
Give your AI coding agent (Claude Code, Codex, Cursor) one command and let it connect, monitor, and diagnose your Postgres:
npx skills add postgres-ai/postgresai --skill postgresaiOr start a local demo with sample Postgres traffic (requires Docker):
npx pgai mon local-install --demoBattle-tested in the PostgresAI team's work with companies including GitLab, Miro, Chewy, Suno, Supabase, Gadget, and more.
Why Monitoring v4?
Monitoring v4 combines collection, Parquet storage, and SQL querying in one Rust binary designed for Postgres engineers and AI agents. The legacy v3 stack used 10 containers; the full v4 Compose deployment adds supporting services for dashboards, Database Health, jobs, and host metrics.
Legacy stacks (v3 / pgwatch + TSDB) | PostgresAI Monitoring v4 ( | |
Footprint | 10 containers (pgwatch, VictoriaMetrics, sink DB, Flask, vmalert, exporters) | 1 Rust binary ( |
Storage | Stateful time-series database + separate Postgres sink | Parquet files on local disk or S3 |
Query language | PromQL | Plain SQL via embedded DuckDB ( |
AI agents | MCP server for Issues and reports; metrics via PromQL | 1-liner agent skill ( |
Related MCP server: PostgreSQL MCP Server
Architecture
flowchart LR
PG["PostgreSQL 14+<br/>Supabase · AWS RDS · ClickHouse · Self-Hosted"] -->|read-only least-privilege| MON["pgai-mon<br/>(single Rust binary)"]
MON -->|Parquet| STORE["Local volume or S3"]
STORE --> DUCK["Embedded DuckDB<br/>Read-only SQL engine"]
DUCK --> AGENT["AI Agents<br/>Skill · MCP · pgai mon sql"]
DUCK --> CONSOLE["PostgresAI Console<br/>Database Health & Issues"]
DUCK --> GRAF["Grafana (optional)<br/>ASH & Four Golden Signals"]Quick start
Installation versions
The unversioned npx pgai commands, global MCP installation, agent-guided deployment, and postgresai@latest upgrade below require a Monitoring v4 release on npm's latest tag. Check npm view pgai dist-tags and npm view postgresai dist-tags before installing. For v4 release-candidate testing, substitute npx pgai@rc for npx pgai and install MCP with npm install -g postgresai@rc. For the upgrade path, also replace postgresai@latest with postgresai@rc. Installing the agent skill does not select a CLI channel: its deployment commands use postgresai@latest, so explicitly instruct the agent to use the v4 RC when testing a release candidate.
1. With your AI coding agent (fastest)
npx skills add postgres-ai/postgresai --skill postgresaiRequires Node.js 22.20+ for npx skills. Your agent loads .claude/skills/postgresai/SKILL.md and guides authentication, read-only database setup (postgres_ai_mon), Cloud or self-hosted deployment, and root-cause analysis.
Prefer starting in the browser? Open PostgresAI Console and choose Set up with your AI agent.
2. Directly from your terminal
# Preview the setup SQL (creates a role, grants, and supported extensions)
npx pgai prepare-db --print-sql postgresql://admin@host:5432/dbname
# Create the least-privilege postgres_ai_mon role (idempotent)
npx pgai prepare-db postgresql://admin@host:5432/dbname
# Deploy to PostgresAI Cloud (or self-host with: npx pgai mon local-install)
npx pgai auth login
npx pgai mon deploy postgresql://admin@host:5432/dbname3. MCP server (Claude Code, Cursor, Codex)
Install globally so your MCP client points to a stable binary rather than a temporary npx cache:
npm install -g postgresai
postgresai auth login
postgresai mcp install claude-code # or: postgresai mcp install cursor
# Codex: codex mcp add postgresai -- postgresai mcp startManual stdio clients use postgresai mcp start. Both postgresai and the shorter pgai command alias are included.
Query monitoring in plain SQL
No PromQL required. Query live or historical metrics, wait events, and normalized pg_stat_statements text straight from your terminal or agent with npx pgai mon sql (pass --project <name> for Cloud or --local for self-hosted):
Top 10 collected queries by execution time over the last hour:
npx pgai mon sql --local "
select
s.labels['datname'] as datname,
s.labels['queryid'] as queryid,
coalesce(q.query, s.labels['queryid']) as query,
round(sum(s.value) / 1000.0, 2) as exec_sec
from prom_increase_pure(
'pgwatch_pg_stat_statements_exec_time_total', [],
epoch_ms(now()), epoch_ms(now()), 60000, 3600000
) s
left join query_text_names q
on q.dbname = s.labels['datname']
and cast(q.queryid as varchar) = s.labels['queryid']
where isfinite(s.value)
group by 1, 2, 3
order by exec_sec desc
limit 10
"A series with no sample before the one-hour window is counted from zero by prom_increase_pure; during the first hour of collection, that can include execution time accumulated before monitoring started.
Active Session History (top wait events over the last hour):
npx pgai mon sql --local "
select
labels['wait_event_type'] as wait_type,
labels['wait_event'] as wait_event,
round(sum(value), 2) as sum_observed_series_avg
from prom_avg_over_time(
'pgwatch_wait_events_total', [],
epoch_ms(now()), epoch_ms(now()), 60000, 3600000
)
where isfinite(value)
group by 1, 2
order by sum_observed_series_avg desc
limit 15
"The ASH example sums per-series averages over recorded samples. Missing wait-event series are not zero-filled, so this is not a wall-clock average active-session count; use the ASH dashboards for that view. Both examples aggregate across the selected monitoring instance and need collected data.
Supported platforms
Platform | Connection | Host CPU / RAM / Disk metrics |
Supabase | OAuth consent via Supabase Management API (no DB password needed) | Supabase metrics endpoint; self-hosted installs need the host-metrics relay enabled |
AWS RDS & Aurora | Direct URL; private AWS PrivateLink for RDS instances (not Aurora or RDS Proxy endpoints) | CloudWatch / Enhanced Monitoring with AWS permissions configured |
ClickHouse Managed Postgres | Standard URL + | Built-in via ClickHouse Cloud API ( |
Self-hosted / Bare metal / Docker | Direct URL or self-hosted | Bundled exporters cover the monitoring host only. Custom scrapes expose raw |
Cloud vs. Self-Hosted
Self-Hosted (Apache 2.0): Run the full
pgai-mon+ Grafana + reporter stack on your own Linux/Docker host with zero account required (npx pgai mon local-install). Store Parquet history on local disk or in your own S3 bucket (PGAI_MON_STORE=s3://bucket/prefix).PostgresAI Cloud: Fully managed monitoring boxes, continuous Database Health analysis, prioritized Issues workflow, and team Console — Starter at $16/cluster/month and Scale at $512/cluster/month (pricing). Confirm your exact quote before any billed deployment.
Repository map
Path | What lives here |
| |
| |
Continuous Database Health insight generator reading from | |
Official AI agent skill for setup and Postgres diagnostics | |
Wait-event visualization color standard |
Upgrading from v3 starts metric history fresh.
postgresai mon updateswitches an existing v3 compose stack topgai-mon, keeps a backup of your old compose file, and leaves old volumes untouched so you can roll back if needed. Legacy v3 maintenance lives onGEN3_STABLE.npm install -g postgresai@latest postgresai mon updateKey
.envknobs for self-hosted installs:PGAI_MON_STORE=s3://bucket/prefix(S3 Parquet storage),GRAFANA_PORT/PGAI_MON_PORT(default bound to127.0.0.1:3000and127.0.0.1:8765),GRAFANA_BIND_HOST=0.0.0.0:(expose behind TLS),PGAI_MON_TOKEN(bearer token for the local API),GRAFANA_SCALE=0(headless mode, also set bymon local-install --no-grafana). See.env.example.Kubernetes: The archived Helm chart targets v3, not
pgai-mon; it is retained inold/postgres_ai_helmfor reference.mon updateprints the backup-specific rollback commands. Full CLI commands and storage options:cli/README.mdandmon/README.md.
Links & community
PostgresAI Console · Documentation · llms.txt · Pricing · GitLab (source & issues) · Postgres.FM · Postgres.TV · Contact
Apache License 2.0 — see LICENSE. Built by PostgresAI as part of Self-Driving Postgres.
Available Tools
16 toolscreate_action_itemC
Create a new action item for an issue
Inputs: title (required), issue_id (required), debug, org_id, +3 more.
create_issueB
Create a new issue in PostgresAI. Local files passed via 'attachments' are uploaded to PostgresAI storage and the resulting markdown links are appended to the issue description.
Inputs: title (required), debug, labels, org_id, +4 more.
deploy_monitoringA
Put a Postgres database under PostgresAI Cloud monitoring (same as pgai mon deploy): prepares the monitoring role (an admin URL creates it; otherwise returns the SQL), provisions the monitoring box, and returns JSON with status (ready | in_progress | deleting | deleted | inactive | action_required | failed: the same words as pgai dblab deploy), health_url (the project's Health Matrix in the console), dashboard_url (Grafana, signing in with PostgresAI) and next (the exact next action). A billed box is provisioned only with yes: true: without it the result is action_required with the price (and requires_payment_method), so show the price to the user first. It does not wait for the box: call it again to see the status. Safe to call again. When PostgresAI can't reach the database the way an IP allowlist refuses (or with ip_first), the box's IP is reserved first and the result is action_required with step allow_ip (ip, cidr, host, port, reserved_until): give the user the cidr and port to allow on the database, then call again with ip_allowed: true. ClickHouse Managed Postgres, RDS and Supabase are detected from the host. An RDS instance that is not publicly accessible is monitored over AWS PrivateLink (no public IP, nothing opened): the user creates a CloudFormation stack in their AWS account from a link. Until the stack exists the result is action_required with step privatelink_stack and cfn_url: give the user the link to open in the RDS's AWS account (the stack keeps its name); once they say it is created, call again. When this machine's aws CLI can read the RDS (read-only; aws_profile picks the profile, no_aws: true skips it), the link is filled in and the stack is found by itself; otherwise pass vpce_service, the stack's VpceServiceName output. When the URL's user can't create the monitoring role, or this machine can't reach the database (a private RDS seen from outside its VPC), the result is action_required with step prepare_db, sql, nonce and monitoring_password: the user runs the SQL as the master user in that database, then call again with monitoring_password and nonce. host_stats: true adds host CPU, memory, disk and IOPS through a read-only role the stack creates (host_stats_role: its HostStatsRoleArn output, when not read from AWS). Aurora and RDS Proxy endpoints are not supported over PrivateLink. Supabase needs no password (PostgresAI prepares the database through the Supabase Management API): the first time, the result is action_required with a consent link in next; give it to the user to open and approve, then call again. Elsewhere the URL must carry its password, and only these query parameters: sslmode, channel_binding, application_name. PGAI_MON_PASSWORD, PGPASSWORD and CLICKHOUSE_KEY_ID + CLICKHOUSE_KEY_SECRET of the server process are not used (pass clickhouse_key), and a TLS failure is not retried in plaintext (say sslmode=disable for a server without TLS). For another database on a server PostgresAI already monitors for the org, an admin URL with sslmode=require (or verify-*), each query parameter once, is enough: PostgresAI fills in the password of postgres_ai_mon it keeps, over TLS only (on a server without TLS, pass the postgres_ai_mon URL; if nobody has its password, the user runs in a terminal: pgai mon instances delete the server's other databases, then pgai mon deploy --reset-password with PGAI_MON_PASSWORD set to a new one, then deploys them again with it).
Inputs: database_url (required), yes, cloud, debug, +18 more.
download_fileA
Download a file from PostgresAI storage by URL (full URL under the storage base, or a relative path like /files/123/foo.png).
Inputs: url (required), debug, org_id, output_path.
get_report_dataA
Get checkup report file content: the JSON data of each check, in a 'data' field. Either report_id or check_id must be provided. For findings and recommendations, use the issues tools (list_issues, view_issue).
Inputs: type, debug, org_id, check_id, +1 more.
list_action_itemsC
List action items for an issue
Inputs: issue_id (required), debug, org_id.
list_issuesC
List issues from PostgresAI API (same as CLI 'issues list')
Inputs: debug, limit, offset, org_id, +2 more.
list_report_filesA
List files in a checkup report (metadata only, no content). Checkup reports are JSON, one file per check. Either report_id or check_id must be provided. For findings and recommendations, use the issues tools (list_issues, view_issue).
Inputs: type, debug, org_id, check_id, +1 more.
list_reportsA
List checkup reports. Returns report metadata: id, project, status, timestamps. Use get_report_data to fetch actual report content. Supports date-based filtering with before_date.
Inputs: all, debug, limit, org_id, +3 more.
post_issue_commentA
Post a new comment to an issue (optionally as a reply). Local files passed via 'attachments' are uploaded to PostgresAI storage and the resulting markdown links are appended to the comment body (image extensions render inline).
Inputs: issue_id (required), debug, org_id, content, +2 more.
update_action_itemB
Update an action item: mark as done/not done, approve/reject, or edit title/description
Inputs: action_item_id (required), debug, title, org_id, +4 more.
update_issueA
Update an existing issue (title, description, status, labels, is_hidden). Use status=1 to close, status=0 to reopen. Local files passed via 'attachments' are uploaded and appended to 'description'; if 'description' is omitted, the existing description is fetched first and appended to.
Inputs: issue_id (required), debug, title, labels, +5 more.
update_issue_commentA
Update an existing issue comment. Local files passed via 'attachments' are uploaded and appended to 'content' as markdown links.
Inputs: comment_id (required), debug, org_id, content, +1 more.
upload_fileA
Upload a local file to PostgresAI storage. Returns the storage URL and a ready-to-paste markdown link (image extensions get the inline  form, others get [](url)). For posting attachments alongside an issue or comment, prefer the 'attachments' parameter on the issue/comment tools — this tool is for ad-hoc uploads or when you need the URL out of band.
Inputs: path (required), debug, org_id.
view_action_itemC
View action item(s) with all details. Supports single ID or multiple IDs.
Inputs: debug, org_id, action_item_id, action_item_ids.
view_issueA
View a specific issue with its comments and who has seen it (seen_by). Viewing records the token owner in the issue's seen-by list as an AI agent.
Inputs: issue_id (required), debug, org_id.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 16 tools
Most tools target a distinct resource+action (issues, action items, reports, files, monitoring), and descriptions explicitly cross-reference each other (e.g. list_reports points to get_report_data, report tools point to issues tools). Minor overlap remains between view_action_item (accepts multiple IDs) and list_action_items, and between post_issue_comment/create_issue attachment handling versus upload_file, but the descriptions make the intended boundaries clear.
Nearly all tools follow a consistent verb_noun snake_case pattern (list_issues, create_issue, update_issue_comment, list_report_files, deploy_monitoring). Deviations are small: 'post_issue_comment' rather than create_*, and 'get_report_data' vs 'view_issue'/'view_action_item' mixing get/view verbs, but nothing confusing.
16 tools cover four coherent sub-areas (issues, action items, checkup reports, storage/attachments) plus monitoring deployment, so each tool has a plausible place. It sits just above the ideal 3-15 range and the very large deploy_monitoring description does a lot of work in one tool, but nothing feels redundant.
Issues and action items have list/view/create/update and comment create/update, but no delete operations for issues, comments, or action items, and there is no way to list or remove monitored deployments (deploy_monitoring is idempotent but there is no status-list or undeploy tool). Reports are read-only by nature, which is acceptable, but the missing lifecycle ends will force agents to work around gaps.
Maintenance
Related MCP Connectors
Open-source DBA tool for AI agents: graded database health checks, SQL, backups proven by restore
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Related MCP Servers
- AlicenseAqualityDmaintenanceprovides AI-powered PostgreSQL performance tuning capabilities.1431Apache 2.0
- AlicenseNot gradedqualityCmaintenanceEnables secure, AI-driven PostgreSQL database administration, observability, and querying with support for extensions like PostGIS and pgvector, connection pooling, and advanced tool filtering.82 npm12MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to interact with PostgreSQL databases through schema intelligence, query execution, and DBA tooling including index analysis and health monitoring. Features configurable access levels and audit logging for secure database operations.MIT
- AlicenseAqualityDmaintenanceEnables AI agents to analyze, optimize, and safely interact with PostgreSQL databases, including health checks, index recommendations, query planning, and SQL execution with read-only and production protection modes.15MIT