Connect ChatGPT to PostgreSQL, read-only

Add your PostgreSQL database to AI2SQL, install the AI2SQL app in ChatGPT and sign in. ChatGPT can then answer questions from your Postgres data with real SQL, while writes are blocked and your password never leaves AI2SQL.

Short answer: ChatGPT can't open a connection to PostgreSQL by itself. Give it one through an app that only runs read-only SQL. With AI2SQL you add the database once with a read-only role, install the AI2SQL app in ChatGPT, and sign in. The same steps work for Supabase, Neon, Amazon RDS and Azure Database for PostgreSQL.

Step 1: a read-only PostgreSQL role

Enforce read-only in PostgreSQL itself, so a write fails even if every other layer missed it:

CREATE ROLE chatgpt_ro LOGIN PASSWORD 'a-long-random-password';
GRANT CONNECT ON DATABASE appdb TO chatgpt_ro;
GRANT USAGE ON SCHEMA public TO chatgpt_ro;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO chatgpt_ro;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO chatgpt_ro;
ALTER ROLE chatgpt_ro SET default_transaction_read_only = on;

To keep some tables out of reach, grant SELECT on chosen tables or a separate schema instead of ALL TABLES.

Step 2: add the database to AI2SQL

Sign in at builder.ai2sql.io, open Connections, pick PostgreSQL and enter the host, port (usually 5432), database and the chatgpt_ro role. On Supabase or Neon, copy the host and port from the project's connection settings. If PostgreSQL runs on your laptop or inside a private network, use the desktop connector instead.

Step 3: install AI2SQL in ChatGPT

  1. Open the AI2SQL app in the ChatGPT plugin directory and add it.
  2. ChatGPT opens AI2SQL. Sign in with the account that holds the PostgreSQL connection and press Allow.
  3. In a new chat, type @AI2SQL so ChatGPT uses the app for your question.

Prefer to add it by hand? Turn on developer mode in ChatGPT's connector settings and create a connector with the URL https://builder.ai2sql.io/api/chatgpt-mcp and OAuth authentication.

Step 4: ask a question

Try "@AI2SQL describe my Postgres database, then show monthly revenue for the last 6 months." ChatGPT reads the real schema with describe_schema, writes PostgreSQL SQL (date_trunc, ILIKE, ::date casts) and runs it with run_query. Ask ChatGPT to show the SQL it ran if you want to check it.

What keeps it safe

Common PostgreSQL snags

The same connection also works from Claude and Cursor. For MySQL and SQL Server, see ChatGPT + MySQL and ChatGPT + SQL Server.

Frequently asked

Can ChatGPT connect to a PostgreSQL database? +

Yes. Install the AI2SQL app in ChatGPT and sign in. Once a PostgreSQL connection is added in AI2SQL, ChatGPT can read its schema and run read-only queries on it. ChatGPT never sees the database password.

Can ChatGPT change data in PostgreSQL? +

Not through AI2SQL. Each call accepts one SELECT or WITH statement. INSERT, UPDATE, DELETE, COPY, DDL and functions such as pg_read_file, dblink and pg_sleep are rejected before they reach PostgreSQL. A read-only role makes the database refuse writes as well.

Does it work with Supabase, Neon, Amazon RDS or Azure Database for PostgreSQL? +

Yes, as long as AI2SQL can reach the database over the network. Use the direct connection string details (host, port, database, user) and a read-only role. A PostgreSQL on your laptop or a private network needs the AI2SQL desktop connector.

Do I need ChatGPT developer mode? +

No. AI2SQL is in the ChatGPT plugin directory. Developer mode is only needed if you want to add the server URL by hand.

Can I try it before connecting my database? +

Yes. Ask: Use AI2SQL to show the top 5 customers by revenue in demo_shop. demo_shop is a shared sample store with fake data and works on every plan. Running queries on your own database needs Pro or Team, which start with a 7-day trial.

Ask ChatGPT about your PostgreSQL data

Connect PostgreSQL, add the AI2SQL app in ChatGPT, sign in. Read-only and logged from the first query.

Connect PostgreSQL free →

Related guides