How to let your team query Postgres from ChatGPT safely
Connect ChatGPT to Postgres with a read-only role, per-person access and an audit log, so colleagues can ask questions without database credentials.
Jump to a section
"We use ChatGPT and our data is in Postgres. What should I use so colleagues can query it safely?" It tends to come from a data lead whose sales and finance colleagues already ask ChatGPT everything except the questions that need the database. Those still land in the data lead's queue.
Getting ChatGPT to talk to Postgres takes an afternoon. Making it safe for a team takes four things: a read-only connection, access that differs per colleague, a record of who asked what, and database credentials that never sit on anyone's laptop or in a chat. This page covers the do-it-yourself route, where it falls short on those four, and the Contextflo route.
What ChatGPT needs from a Postgres connection
ChatGPT talks to databases through MCP (Model Context Protocol), the same open standard Claude, Cursor and Codex use. ChatGPT is different in one way that shapes everything below: the connection to an MCP server starts on OpenAI's side, so the server has to be reachable from the internet. As of December 1, 2026, per OpenAI's help center and developer docs [1, 2]:
| What | ChatGPT today |
|---|---|
| Server location | Remote, at a public HTTPS URL, or reached through OpenAI's Secure MCP Tunnel for private networks. Local stdio servers are not supported directly |
| Transport | SSE or streaming HTTP |
| Auth options for a custom server | OAuth, or no authentication |
| Plans that can add a custom server | Business and Enterprise/Edu on ChatGPT web (write actions included). Pro can connect read/fetch-only servers. Not on mobile |
| Who can add one in a workspace | On Business, admins and owners. On Enterprise/Edu, admins can grant it to selected members |
| Write actions | Need confirmation by default. Tools without the MCP readOnlyHint annotation count as writes |
Developer mode is no longer a separate step: you add a custom server from Plugins, then "Add custom MCP server" (Source: OpenAI Help Center: Developer mode and MCP apps in ChatGPT, https://help.openai.com/en/articles/12584461-developer-mode-and-mcp-apps-in-chatgpt, checked on 2026-12-01). It used to be a separate toggle, and plan rules move as often, so check OpenAI's article for your plan before you build.
Start with a read-only Postgres role
Both routes start here. Point the role at a read replica if you have one, so a heavy question cannot slow your app.
Loading code sample...
default_transaction_read_only makes a stray UPDATE fail at the database even if something above it misbehaves. If you grant SELECT ON ALL TABLES instead of a list, add ALTER DEFAULT PRIVILEGES FOR ROLE <the role that creates tables> IN SCHEMA public GRANT SELECT ON TABLES TO ai_readonly; so tables created next month stay visible. The Postgres setup guide covers that case.
The DIY way: host a Postgres MCP server for ChatGPT
Because ChatGPT only takes remote servers, the DIY route means running a small service. DBHub (@bytebase/dbhub, MIT licensed) is a reasonable choice because it serves MCP over HTTP (Source: Bytebase: DBHub on GitHub, https://github.com/bytebase/dbhub, checked on 2026-12-01).
-
Write a config that makes its SQL tool read-only and caps rows (Source: DBHub docs: TOML configuration, https://dbhub.ai/config/toml, checked on 2026-12-01):
Loading code sample...
-
Run it over HTTP on a server that can reach the database (Source: DBHub docs: Command-line options, https://dbhub.ai/config/command-line, checked on 2026-12-01):
Loading code sample...
The MCP endpoint is
/mcp. -
Put HTTPS in front of it with a reverse proxy or load balancer and a public hostname, for example
https://pg-mcp.yourcompany.com/mcp. If the database is on a private network, use OpenAI's Secure MCP Tunnel instead of opening it up (Source: OpenAI Help Center: Developer mode and MCP apps in ChatGPT, https://help.openai.com/en/articles/12584461-developer-mode-and-mcp-apps-in-chatgpt, checked on 2026-12-01). -
Add it in ChatGPT: Plugins, the plus button, "Add custom MCP server", paste the URL, pick authentication, accept the risk warning, then create it (Source: OpenAI Help Center: Developer mode and MCP apps in ChatGPT, https://help.openai.com/en/articles/12584461-developer-mode-and-mcp-apps-in-chatgpt, checked on 2026-12-01). On Business, an admin does this for the workspace.
-
Test it: ask for a row count, open the tool call to read the SQL, then ask for a table you did not grant and confirm it fails.
Where it breaks for a team
Authentication. DBHub protects its HTTP endpoint with a shared bearer token (--auth-token), off by default (Source: DBHub docs: Command-line options, https://dbhub.ai/config/command-line, checked on 2026-12-01). ChatGPT's custom server form offers OAuth or no authentication (Source: OpenAI developer docs: Developer mode, connecting custom MCP servers, https://developers.openai.com/api/docs/guides/developer-mode, checked on 2026-12-01), so the token does not plug in. Your options are building an OAuth layer in front of the server, or running a URL that answers anyone who finds it.
Everyone is the same person. Whoever connects gets the ai_readonly role. Finance and the support team see the same tables, because Postgres has no idea which colleague is behind the request. Giving them different access means separate roles, servers and URLs per group.
No record of who asked. pg_stat_statements and the Postgres logs show the SQL and the role, never the colleague or the question they typed. ChatGPT shows the SQL inside each chat, but nobody else can see it.
No shared meaning. The server hands ChatGPT table and column names. Each colleague's chat guesses what status = 3 or "active customer" means on its own, so two people asking the same question can get two numbers.
You also own the server: patching, uptime, TLS certificates and the password in its config. For one technical user who knows the schema, that is a fine trade. For colleagues across the company, the gaps above are the reason the data lead gets asked "is this number right?"
DIY vs Contextflo
| Self-hosted MCP server (DBHub) | Contextflo | |
|---|---|---|
| Read-only | The Postgres role, plus readonly = true on the tool | The Postgres role; Contextflo only sees what it can see |
| Per-colleague access | One role for everyone with the URL | Each person signs in; groups get their own tables |
| Audit | SQL and role in Postgres logs, no person or prompt | Every question and query logged per person, on every plan |
| Credentials | On your MCP server, in a config file | Entered once in Contextflo's form, stored encrypted |
| Sign-in from ChatGPT | OAuth you build, or no auth | Contextflo plugin, each person signs in |
| Shared definitions | None | Table and column descriptions, metrics and saved queries the team reuses |
| Hosting | Your server, proxy and certificates | Hosted; queries run in your database |
| Cost | Free software, plus your hosting and time | Free for one user and one data source; from $500/month for up to 10 people, unlimited queries |
| Setup | An afternoon, plus upkeep | About 10 minutes |
The Contextflo way
Contextflo connects to Postgres once, and colleagues ask from the ChatGPT or Claude they already use. Questions run on your existing ChatGPT subscription, so there is one AI bill and no per-query fee from us: queries are unlimited.
- Connect Postgres. In Contextflo, go to Data Sources, then Add data source, and choose PostgreSQL. Paste a
postgresql://connection string for the read-only role above, or fill in host, port and database. Click Test Connection and save. - Pick tables and set access. Choose the tables to sync, then create groups and pick which tables each group can query. It supports access control across all data sources, at the granularity each underlying data source supports, on every plan. The schema re-syncs daily, so next month's tables show up without anyone editing a config.
- Review the generated context. Contextflo writes table and column descriptions and starter metric definitions from your schema, plus any code and docs you connect. Fix what is off; it sharpens as the team saves corrections.
- Invite colleagues. Each one opens the Contextflo plugin in ChatGPT, clicks Connect and signs in with their own Contextflo account. No database password ever reaches them.
Every answer shows the SQL behind it, and every question and query lands in the per-person audit log. Tilt, a live-auction marketplace for limited-edition goods, runs about 6,000 queries a month this way with a one-person data team, and 30+ people ask every week.
The one setup Contextflo does not fit is a fully on-prem or air-gapped database that cannot accept any cloud connection.
Further reading
- Contextflo for Postgres and the full Postgres setup guide
- Connect your agent: ChatGPT, Claude, Claude Code, Codex and Cursor
- Claude with Postgres and the best Postgres MCP servers
Here is a more in-depth look at Contextflo and how it works.
What is Contextflo?
Contextflo is a governed context layer between your data and the AI your team already uses. Connect your warehouse once, and your team asks questions in their own Claude or ChatGPT. The model writes and runs the SQL; Contextflo supplies the definitions, the per-user access control, and the audit that make the answers trustworthy. Your data never moves, and you do not need a data team.
How it works
Your team queries in their own Claude or ChatGPT over MCP, so you bring any agent rather than a locked-in bot, and every answer comes back with the SQL shown and access enforced per user.
FAQ
We use ChatGPT and our data is in Postgres. What should I use so colleagues can query it safely?
Use a layer between ChatGPT and Postgres that connects with a read-only role, gives each colleague their own sign-in and table access, and logs every question and query. Contextflo does this: connect Postgres once, set access per group, and colleagues ask from the ChatGPT they already use, with unlimited queries.
Can ChatGPT connect to a local Postgres MCP server?
Not directly. As of December 2026, OpenAI's help center says ChatGPT connects to remote MCP servers over a public HTTPS URL, and offers Secure MCP Tunnel for servers on a private network. A local stdio server that works in Cursor or Claude Desktop has to be hosted first.
Can ChatGPT change data in my Postgres database?
Not if it connects with a read-only role. Set default_transaction_read_only on the role and grant SELECT only, so a write fails at the database whatever the AI sends. ChatGPT also asks for confirmation before tools that are not marked read-only.
Can each colleague get different access to Postgres from ChatGPT?
Yes. With Contextflo, each colleague signs in with their own account and only queries the tables their group can see, with one read-only Postgres role behind it and no database user per person. A self-hosted MCP server usually gives everyone who has the URL the same role.
Which Postgres hosts does this work with?
RDS, Supabase, Neon, Cloud SQL, Azure, Railway, Render and self-hosted Postgres. Contextflo takes a postgresql:// connection string or the host, port and database fields.