How to Connect PostgreSQL to an AI Agent, Step by Step
· DoubleX
Quick answer
To connect PostgreSQL to an AI agent, create a read-only database user, add the PostgreSQL connector with its credentials, choose whether the connection is personal, team, or company-wide, and enable it only for the agents that need it. In DoubleX Agentes, the connector reads tables in read-only mode.
Connecting a database to an AI agent is mostly an access-control exercise. The agent is only as safe as the credentials and permissions you hand it, so the setup below starts with the database side and ends with a test you can audit.
This guide is for technical teams who own the database and want to give agents controlled, read-only access.
What does the PostgreSQL connector allow, and why is it read-only?#
The PostgreSQL connector lets an agent query the tables of a PostgreSQL database directly, in read-only mode. A connector is a system linked to the platform whose tools agents can use. Read-only is the default for database connectors (PostgreSQL and MySQL), so an agent can look at data but not change it.
That design protects production data. Even if a request is poorly worded, the agent cannot run an update or a delete through this connector. You can still add a second layer on the database itself, as described next.
What should you prepare before connecting?#
Prepare a dedicated database user with read permissions only, plus the connection details for your PostgreSQL server. Do not reuse an admin or application account.
Have this checklist ready:
| Item | What to prepare | Why it matters |
|---|---|---|
| Host and port | The address your PostgreSQL server accepts connections on | The platform must be able to reach it |
| Database name | The specific database the agent should see | Limits the scope of access |
| Dedicated user | A new user created only for agents | Easy to audit and revoke |
| Permissions | SELECT only, on the schemas and tables the agent needs | Keeps sensitive tables out of reach |
| Password | A strong, unique password | Stored encrypted by the platform (AES-256-GCM) |
| Network rules | Allow access from the platform if your firewall restricts it | Avoids failed connections |
How do you add PostgreSQL on the Connectors screen?#
Open the Connectors screen, pick PostgreSQL, and enter the connection details for your read-only user. Follow these steps in DoubleX Agentes:
- Sign in and open the Connectors screen.
- Find PostgreSQL in the list (it appears in the data category) and start the connection.
- Enter the host, port, database name, user, and password you prepared.
- Choose the connection scope: personal, team, or company (see the next section).
- Save the connection and confirm it appears as connected.
- Go to the Agents screen and enable the connector for the agents that should use it.
Secrets such as passwords, tokens, and keys are stored encrypted with AES-256-GCM. For the full connector reference, see the Connectors API documentation.
Personal, team, or company connection: which should you choose?#
Choose the narrowest scope that still works. A connection can be personal (valid only for you), for a team, or for the whole company.
| Scope | Best for | Consideration |
|---|---|---|
| Personal | One analyst exploring data on their own | Only that person's agents and routines use it |
| Team | A data or product team sharing the same agents | Everyone on the team uses the same database user |
| Company | A database that many areas need to read | Use a user limited to non-sensitive tables |
A scheduled routine runs with the permissions of the person who created it. If someone leaves or changes roles, review the routines and connections they own.
How do you choose which agents and actions can access the database?#
For each agent, you choose which systems it can use and, within each system, which actions it can run. Only enable PostgreSQL on the agents that truly need to read from it.
A practical setup:
- Create a dedicated agent for data questions instead of adding the connector to every agent.
- Keep the connector disabled on agents that handle e-mail, calendar, or customer messages.
- Use team roles (owner, admin, member) and sharing by person, team, or company to control who can talk to the agent.
- Remember that the database user is your last line of defense: even if the platform setting changes, the database permissions still apply.
How do you test the connection and check the history on the Tasks screen?#
Send the agent a simple, harmless request, then open the Tasks screen to review exactly what it did. Every request becomes a task with full history: the request, each tool the agent used, and the result. You can see who asked, what was done, and when.
To test:
- Open a conversation with the agent that has PostgreSQL enabled.
- Ask it to list the tables it can see, or to count the rows in one small table.
- Open the Tasks screen and open that task.
- Check which tool calls ran and whether the result matches what you expect.
- Try asking for a table outside the permitted schemas. The database should refuse it.
If the connection fails, recheck the host, port, firewall rules, and user permissions first. Once the test works, you can move to real use cases in PostgreSQL with an AI Agent: Example Requests and Routines. If you run Postgres on Neon, see How to Connect Neon to an AI Agent and Query Postgres. To understand the platform first, read the Introduction.
Frequently asked questions#
Can the AI agent change or delete data in my PostgreSQL database?#
Not through this connector. PostgreSQL connections are read-only by default, so the agent can query tables but not modify them. Also give the database user SELECT-only permissions for a second layer of protection.
Do I need to write code to connect PostgreSQL?#
No. You add the connector from the Connectors screen by entering the connection details. Developers who want more control can use the REST API, the CLI, or the MCP server.
Is my company data used to train AI models?#
No. Company content is not used to train models, and requests only go to AI providers that do not use what they receive for training. There is also a zero-retention option that uses only providers that store nothing after the response.
Can I see what the agent queried?#
Yes. Each request is a task on the Tasks screen with the request, each tool used, and the result, so you can audit who asked for what and when.
Should I use a personal or company connection?#
Start with a personal or team connection and widen it only if needed. For company-wide access, use a database user limited to non-sensitive tables.
Related guides
- How to Connect Box to an AI Agent: Step-by-Step GuideLearn how to connect Box to an AI agent: set up the connector, limit it to read-only, choose who can use it, and check the history of your first request.
- How to Connect Neon to an AI Agent and Query PostgresLearn how to connect Neon Postgres to an AI agent in DoubleX Agentes: pick the connection scope, limit actions, start read-only, and test your first query.