How to Connect PostgreSQL to Codex

Query your PostgreSQL data directly from Codex using Sequel’s MCP server. Ask questions in plain English, with no SQL, no dashboards, and no context switching.

Short answer

Connect PostgreSQL to Sequel, then add Sequel's MCP server to Codex using the config on this page. Codex can then query your live PostgreSQL data in plain English, with no connector code and no CSV exports. Both steps take a few minutes.

Example prompts

Everything you can ask Codex about your PostgreSQL data.

Ask in plain English — Sequel translates it into a PostgreSQL query, runs it, and Codex hands back the answer. No SQL, no dashboards, no CSV exports.

What you can ask Codex
  • How many rows are in each table?
  • Show me the 10 most recently created users
  • What's the average order value by customer segment?
  • Which products have never been ordered?
  • Show me monthly revenue broken down by plan type

How it works

Three steps to get started

1

Connect PostgreSQL to Sequel

In your Sequel dashboard, go to Connections and add PostgreSQL. Sequel handles authentication and schema discovery automatically.

2

Add Sequel to the agent

Copy the Sequel MCP configuration into Codex's settings file (shown below). Swap in your API key from Settings → API Keys.

3

Ask Codex about your data

Restart Codex and start asking questions. "How many rows are in each table?" — and get a real answer backed by live PostgreSQL data.

Why Codex

What Codex does with your PostgreSQL data

Grounded answers from real data

Codex with Sequel queries your actual databases before generating code or explanations. Every schema reference, column name, and data shape is verified against what's really there.

Terminal-native data access

No context switching — Codex can pull database data mid-session to inform code generation, write migrations based on actual schemas, and validate assumptions without leaving the terminal.

Agentic data workflows

Codex's multi-step agent can chain Sequel tool calls together: discover schema, sample data, run analysis, then generate code — all in one automated flow.

Configuration

Add Sequel to Codex

Place this in ~/.codex/config.yaml and replace sql_your_api_key with a key from Settings → API Keys.

~/.codex/config.yaml

mcp_servers:
  sequel:
    type: http
    url: https://api.sequel.sh/mcp
    headers:
      Authorization: "Bearer sql_your_api_key"

Install

Install PostgreSQL MCP in Codex

Pick your app and Sequel installs itself: a one-click link where the client supports it, that client’s own few steps where it doesn’t. Every route signs in with your Sequel account over OAuth, so there is no API key to copy and nothing to keep in sync.

Already have an MCP client?

https://api.sequel.sh/mcp

Add it as a remote (streamable HTTP) server and sign in when prompted. Skills come with it; nothing else to install. Manual setup per client

Add Sequel to Codex

Terminal

codex mcp add sequel --url https://api.sequel.sh/mcp
  1. 1Run the command in your terminal. It writes the server to ~/.codex/config.toml.
  2. 2Run codex mcp login sequel and sign in in the browser.
  3. 3Start Codex and ask a question.

Frequently asked questions

How do I connect PostgreSQL to Codex?

You need two things: (1) connect PostgreSQL to Sequel in your Sequel dashboard under Connections, and (2) add the Sequel MCP config to Codex using the setup shown above. Once both are done, Codex can query your PostgreSQL data directly.

What PostgreSQL data can Codex access?

Codex can access any data available through your PostgreSQL connection in Sequel. Use Sequel's search tool to discover available metrics and dimensions, then execute queries to pull the data you need.

Is my PostgreSQL data sent to Codex's servers?

Query results are returned to Codex as context within your conversation. Only the data you explicitly ask about is retrieved. Sequel never stores your query results permanently — they exist only for the duration of the tool call.

Do I need a Sequel account?

Yes. You need a Sequel account to connect PostgreSQL and generate an API key. Sign up free at sequel.sh — no credit card required. Then create a connection to PostgreSQL and generate an API key from Settings → API Keys.

Can I connect multiple PostgreSQL accounts?

Yes. Sequel supports multiple connections of the same type. If you have multiple PostgreSQL accounts or properties, add each as a separate connection in Sequel. Codex will be able to query all of them.

How do I configure Sequel for Codex CLI?

Add the Sequel MCP server to ~/.codex/config.yaml as shown above. Create the file if it doesn't exist. Replace `sql_your_api_key` with a real key from Settings → API Keys, then restart Codex.

Does Codex CLI support HTTP MCP servers?

Yes. Codex CLI supports MCP over HTTP (Streamable HTTP transport). The `type: http` field in the config tells Codex to use this transport when connecting to Sequel.

Can I limit which databases Codex can access?

Sequel MCP is scoped to your organization's connected data sources. You can create separate API keys for different environments and revoke them at any time from Settings → API Keys.

Is this the same as the original OpenAI Codex model?

No — Codex CLI is OpenAI's agentic terminal coding tool, separate from the original Codex language model. It uses the latest OpenAI models (GPT-4o and o-series) with MCP tool support.

How do I connect my PostgreSQL database?

Click 'New Connection', select PostgreSQL, and enter your host, port, database name, username, and password. Sequel will test the connection before saving. Make sure your database allows connections from Sequel's IP range.

Is my database connection secure?

All connections use SSL/TLS by default. Credentials are encrypted at rest and never exposed in query results or logs. Sequel uses a read-only connection by default and will not execute write statements.

Can Sequel modify my data?

No. Sequel is read-only by default and will warn you if a query could modify data. The agent is explicitly instructed never to run INSERT, UPDATE, DELETE, or DDL statements unless you explicitly request and confirm it.

What PostgreSQL versions are supported?

Sequel supports PostgreSQL 12 and above. Older versions may work but are not officially tested.

Connect PostgreSQL to Codex today

Sign up free, connect your data sources, and start querying in minutes.