Skip to main content

PostgresAI monitoring

Postgres monitoring that you and your agent both read.

Catch problems early, and find the cause with your agent.

From $16 per cluster per month. Pricing →

When something happens: investigating a spike

Active sessions go from a steady 20-30 to 262. Why?

You, in dashboards active session history, 3 hours

  • Lock: transactionid171
  • LWLock: LockManager (lock manager contention)38
  • CPU*31
  • IO: DataFileRead14
  • Client: ClientRead8

Sessions at 14:36, by wait event. CPU* means that Postgres reports no wait event.

The finding: 171 of 262 sessions wait for a row lock, and one query ID has 148 of them. Their blocker has had a transaction open for 94 seconds, and runs update orders set status = $1 where id = $2.

Example data; real metrics and commands. The first answer can take up to about 12 minutes; follow-ups come within seconds. CLI reference →

Your agent, in a shell the stored history of 14:36, queried later

pgai promql
# What do the sessions wait for?
# pgwatch_wait_events_total is a gauge: sessions per event
$ npx pgai@latest promql --project shop \
    --at 2026-11-12T14:36:00Z \
    'sort_desc(sum by (wait_event) (
      pgwatch_wait_events_total))'
SERIES                        VALUE
{wait_event="transactionid"}  171
{wait_event="LockManager"}    38
{wait_event="CPU*"}           31
{wait_event="DataFileRead"}   14
{wait_event="ClientRead"}     8

5 series, 5 points

Then, in the same shell:

pgai promql
# Which queries wait for the row lock?
$ npx pgai@latest promql … \
    'topk(3, sum by (query_id) (pgwatch_wait_events_total{
      wait_event="transactionid"}))'
SERIES                             VALUE
{query_id="-7514152763537218973"}  148
{query_id="-2835399305386018931"}  19
{query_id="-370359998942231564"}   4

# Who blocks them? (value: the blocker's transaction age, ms)
$ npx pgai@latest promql … \
    'max by (blocker_query_id) (pgwatch_lock_waits_blocker_tx_ms{
      blocked_query_id="-7514152763537218973"})'
SERIES                                    VALUE
{blocker_query_id="3018945720344115117"}  94120

# What does the blocker run?
$ npx pgai@latest promql … \
    'count by (displayname_raw_long) (last_over_time(
      pgwatch_query_info{queryid="3018945720344115117"}[1h]))'
SERIES                                                                                      VALUE
{displayname_raw_long="3018945720344115117 | update orders set status = $1 where id = $2"}  1

Checkups warn you early

  • First checkup: indexes, bloat, Postgres version and risky settings, with recommended fixes.
  • After about 24 hours: query analysis and wait-event trends, then daily checkups.
  • Every Monday: a weekly review; over time, health history and forecasts.
  • Every plan: issue updates by email or Slack. Your agent reads issues through the CLI or MCP, and metrics through the CLI.
  • Not a pager: keep your on-call alerting.

What it keeps

The state and the history of your Postgres: sessions, wait events, queries, autovacuum, bloat, replication. The system views, sampled every 30 seconds for most metrics, with history.

What do sessions wait for?

Active session history (ASH): wait events per query ID, every 15 seconds.

Which queries cost the most?

pg_stat_statements: calls, time, rows, buffers, WAL.

Who blocks whom?

Lock waits, long transactions, idle in transaction.

Does autovacuum keep up?

Workers, queue, dead tuples, xmin horizon holders (sessions that stop cleanup), wraparound risk.

Which tables and indexes bloat?

Sizes, bloat estimates, unused, redundant, invalid indexes.

Are replicas and the WAL archive behind?

Replication lag, slots, WAL generation, archiving lag.

How close to max_connections?

Sessions by state, and the limits.

Host CPU, memory and disk for RDS, Aurora, Supabase and ClickHouse. 14 dashboards →

Compared with CloudWatch, Datadog and a DIY Grafana

CloudWatch and Datadog are good general tools, with database load by wait event and automatic recommendations. The differences, from their public docs:

Postgres depth
CloudWatch (RDS for PostgreSQL): instance-wide metrics, no bloat estimates.Datadog: bloat estimates off by default, no autovacuum queue metric.PostgresAI: bloat estimates, the autovacuum queue and the xmin horizon holder, by default.
Price
CloudWatch Database Insights: Standard free, 7 days; per-query statistics need Advanced, per vCPU-hour.Datadog Database Monitoring: $70 per database host per month, billed annually.PostgresAI: Starter covers the primary; Scale includes replicas (up to 5) and Grafana. Pricing →
postgres_exporter + Grafana, run yourself
Free and open source; you run it. pg_stat_statements off by default, no bloat estimates.PostgresAI: both by default, plus wait-event history per query ID, daily checkups and issues. The core is open source too.
Sources

Database Insights, CloudWatch pricing, RDS metrics, Datadog pricing, Datadog Postgres integration, postgres_exporter; read in November 2026.

Set it up with your AI agent

Which setup fits you

Any Postgres with a public endpoint: RDS, Aurora, Neon, self-managed, Cloud SQL, Azure
PostgresAI runs the monitoring box. For IP allowlists, Deploy shows the box's IP first.Neon: 30-second monitoring queries keep the compute awake.
RDS in a private subnet
AWS PrivateLink, on Scale: $512 per cluster, replicas included. Single RDS instances; Aurora not yet. Setup guide →
Supabase
Approve access in Supabase (OAuth): no URL, no password. Any plan, with host stats.
Other private networks
Contact us →

Paste this prompt into your agent

Prompt
Install the PostgresAI skill and use it to check my Postgres database.

1. Download https://gitlab.com/postgres-ai/postgresai/-/raw/main/.claude/skills/postgresai/SKILL.md and save it as ~/.claude/skills/postgresai/SKILL.md (or wherever your agent keeps skills). Then read it and follow it.
2. Set up PostgresAI monitoring for my database.
3. Wait for issues to be detected, then report them in order of severity (worst first), along with recommended fixes.
  • Claude Code, Cursor, Codex, or any agent that runs commands.
  • Your agent does the setup. You approve the sign-in, say yes to the price, and add a card.
  • Setup creates a read-only role (postgres_ai_mon), a postgres_ai schema and pg_stat_statements. Nothing else changes in your database without your OK: SKILL.md.

Agents start here

https://gitlab.com/postgres-ai/postgresai/-/raw/main/.claude/skills/postgresai/SKILL.md

On a remote machine, use an API key instead of the browser sign-in.

Prefer to click through it yourself?

  1. Sign in to PostgresAI Console and create an organization.
  2. DB health → Monitoring instances: pick your database, then Starter or Scale.
  3. Add a card and the database URL. For Supabase, you approve access in Supabase (OAuth) instead: no URL, no password.
  4. Test connection → Deploy.

The people behind it

  • Your agent follows the order we use in consulting: golden signals, then wait events, then the query.
  • When a problem needs a human, escalate it: Scale includes two expert requests per month, answered within 24 business hours; you can buy more. Larger work: PostgresAI consulting.

Data privacy →

No table data, no application data, no query parameter values (one exception below).

  • Collected: system view statistics, wait events, object names, and query texts with $1, $2 in place of parameters.
  • The exception, on by default: the health check includes the first 500 characters of the query that holds the xmin horizon, as written, so it can contain literal values. The setting postgresai.capture_query_preview=off disables it.
  • Credentials: an admin login is used once to create the read-only role and is never stored, or you create the role yourself (npx pgai@latest prepare-db --print-sql). The monitoring box connects as that role.
  • Supabase only: for host stats, PostgresAI reads the project's secret key on demand, never stores it, and logs each use.
  • Every metric's source is public: the SQL in metrics.yml, and the query texts for chart legends (pgwatch_query_info) from the monitoring backend.

For a security review

  • Where it runs: a VM in PostgresAI cloud that PostgresAI operates, on the provider and region you choose in Advanced setup (for example, AWS or Hetzner).
  • SOC 2 Type 2: the PostgresAI Platform, Security and Availability criteria, examined by Sensiba LLP for March 4 to June 4, 2026. The report is issued to DBLab Inc., an affiliate of Nombox LLC d.b.a. PostgresAI, and shared under NDA on request.
  • Sub-processors, with where they process data: the published list.
  • Pin the CLI: npx pgai@0.18.0.

Supported Postgres versions

Versions
PostgreSQL 14 through 19. Version 19 is a pre-release (RC1). Details.
Source
Open-source core, Apache 2.0 (postgres-ai/postgresai). PostgresAI Console runs it for you.

Install it while your database is healthy. One prompt, and your agent sets it up.

From $16 per cluster per month. Pricing →