You Already Speak AI: The PostgreSQL DBA's Translation Guide

If you look after Postgres every day, you already speak AI. You just use different words. A prompt is a query. A context window is work_mem. A tool call is a function call. And an agent? That's a junior DBA with a runbook.

This is the Postgres version of my Oracle video, written down. No product tour, just a map from what you already know to what's new, and where it can hurt you.

9:12 in the morning, too many connections

The running example: new logins start failing with too_many_connections. The old way, you open your script folder, your notes, the mailing list archive and a search engine. You write the query against pg_stat_activity yourself, run it in psql, and read the result. Every step is yours.

Now you can type the question in plain English. The model drafts the SQL, explains the plan or the lock, and an agent can even run read-only queries through a tool. What didn't change: the database is still the source of truth, and you're still the one accountable for what runs on it.

Your own servers or a managed service, the AI layer is the same. What matters is where the model runs and where your data goes. A local model keeps the data inside. A cloud model is usually stronger, but your prompt leaves the building.

The translation table

AI termWhat you already knowWhy it matters
PromptA query with no parserPostgres stops you with SQLSTATE 42601. A model just guesses. "Which app uses the most connections?" Right now, or held the longest? Write prompts like a good ticket.
Tokens8 kB pagesThe unit of work, cost and every limit. Longer prompts cost more, like more buffers in EXPLAIN (ANALYZE, BUFFERS).
Context windowwork_memFixed size. When a long chat fills it, the app trims, like a sort spilling to temp files. The middle of a long context gets lost.
Stateless APIA fresh backend, or a pooled connection after DISCARD ALLA chat only seems to remember because the app resends the whole history every time.
System promptALTER ROLE ... SETKicks in at every request, like role settings at every login. Put the dialect in it: Postgres, not T-SQL.
HallucinationStale statisticsConfident and wrong. In the video the model invents a column called idle_since. Postgres has state_change.
Non-determinismNo plan baselineSame question, different SQL. Test against a case you already know.
Grounding / RAGCatalog lookupFeed only the slice it needs: information_schema.columns, your COMMENT ON COLUMN notes, a runbook page.
Tool callFunction callThe model only asks. The app executes. The model never touches the database.
MCPPort 5432 + libpq or JDBCOne protocol, many clients and servers. There are open-source MCP servers for Postgres.
Workflow vs agentNightly cron script vs junior DBAvacuumdb, reindexdb, pg_dump in fixed order, or an agent that picks its next step from each result.
Human-in-the-loopChange approvalThe agent finds the idle transactions. pg_terminate_backend is still your call.

Two queries, one question

"Which app holds connections it isn't using?" Both generated queries ran fine. One counted state = 'idle', which is mostly connection pools doing their normal thing. The other counted state = 'idle in transaction': an open transaction that's doing nothing. Only that one answers the question. Check the result against a small case you already know.

Where the agent stops

SELECT pid, application_name,
  now() - xact_start AS tx_age
FROM pg_stat_activity
WHERE state = 'idle in transaction'
ORDER BY xact_start;
-- pg_terminate_backend(4127) → you approve

An old open transaction also holds back vacuum, so these sessions hurt twice. Ending them rolls back their work, though, and that's a decision a human makes.

What got better, what it costs

The good part: a first SQL draft in seconds, plain-English explanations of plans, locks and error messages, help on an engine you know less well, and a lot less searching. The bad part: answers can be confidently wrong, the same question can give different results, calls cost tokens and time, and data may leave your network. NIST also names a quieter one, over-reliance. You trust it because it sounds sure, and slowly stop checking.

Security, in DBA words

  1. Prompt injection is SQL injection without parameters. A value in a table row or a line in the server log can say "ignore your rules". In SQL you'd use $1 parameters. There's no such thing for prompts, so limit what the model can do. OWASP lists it as LLM risk number one.
  2. Sensitive data disclosure is an uncontrolled export. Classify before you paste, mask real values, use a local model for anything you wouldn't send outside.
  3. Excessive agency is giving an app role superuser. Give the AI its own role, for example GRANT pg_read_all_data TO ai_ro;, and require human approval for anything high impact.
  4. Avoid the lethal trifecta: private data, untrusted content and a way to send data out. Never all three in one agent.
  5. Passwords and connection strings never go into the chat.
  6. Audit it like any other role. With its own role, log_statement = 'all' for that role shows exactly what it ran. Set its application name in the connection string and pg_stat_activity tells you which session is the AI.
  7. Production last. Sanitized copy or a read-only hot standby, lab first, human approval, and pg_create_restore_point('before_fix') before any change.

New words, old habits. Least privilege, review before commit, test before production. If you've done this job for a while, you already have most of the instincts you need.

Full video: You Already Speak AI (PostgreSQL edition) on YouTube. PIDs and outputs in the video are illustrative.

Sources

Comments