The OpenAI Codex CLI brings AI-assisted development directly into your terminal. Combined with Sequel's MCP server, it becomes a tool for querying your PostgreSQL database in natural language, right alongside the rest of your development workflow, without leaving the command line.
What You'll Accomplish
After this setup, you can run Codex in your terminal and ask:
- "How many active sessions are in the database right now?"
- "Which tables have more than a million rows?"
- "Give me the schema for the orders table."
Codex will call Sequel's MCP server, run the SQL against your PostgreSQL database, and return the results in the terminal session.
Prerequisites
- A Sequel account: Sign up free at sequel.sh
- A running PostgreSQL database: local or cloud-hosted
- OpenAI Codex CLI installed: follow the install instructions at openai.com/codex
Step 1: Connect Your PostgreSQL Database to Sequel
Sign in to sequel.sh and click Data Sources in the left sidebar.

Click New Connection. On the "Choose a connector" page, select PostgreSQL.

Fill in two fields:
- Connection Name: a memorable label, e.g.
My App DB - Connection String: your full PostgreSQL connection string:
postgresql://username:password@host:5432/database_name

Click Connect to verify and save.
Recommended: Create a read-only user before connecting:
CREATE USER sequel_reader WITH PASSWORD 'strong_password'; GRANT CONNECT ON DATABASE myapp TO sequel_reader; GRANT USAGE ON SCHEMA public TO sequel_reader; GRANT SELECT ON ALL TABLES IN SCHEMA public TO sequel_reader;
Step 2: Get Your Sequel API Key
Click Settings in the left sidebar, then select API Keys from the settings navigation.

Click New key, name it codex, and copy the key (starts with sql_).
Step 3: Configure Codex CLI to Use Sequel MCP
Set your API key as an environment variable (add to ~/.zshrc or ~/.bashrc):
export SEQUEL_API_KEY="sql_your_api_key"
Reload your shell:
source ~/.zshrc
Add Sequel to ~/.codex/config.toml (create the file if it doesn't exist):
[mcp_servers.sequel]
url = "https://api.sequel.sh/mcp"
bearer_token_env_var = "SEQUEL_API_KEY"
Save the file. Codex will load this MCP server on the next session start.
Step 4: Query Your PostgreSQL Database
Start a Codex session:
codex
Then ask questions:
What tables are in my PostgreSQL database?
How many users signed up in the last 7 days?
Show me all orders with a total value over $500 from this month.
Codex calls Sequel's MCP tools, translates your question to SQL, runs it, and returns results in the terminal.
What You Can Do Now
- Explore database schemas while coding: ask "What columns does the events table have?" without switching to a database client
- Debug data issues during development: ask "Are there any rows in the jobs table with a null status?"
- Understand existing data: ask "What's the distribution of user_role values in the users table?"
- Catch issues before production: ask "Are there any orders with negative total values?" as a pre-deploy check

