PostgreSQL Connector
Connect to PostgreSQL databases to enable natural language queries over your structured data.
Overview
The PostgreSQL connector allows you to:
- Discover database schema
- Execute natural language queries
- Run read-only SQL
- Index table metadata
Prerequisites
- PostgreSQL database access
- Read-only user credentials
- Network connectivity to database
Authentication
Username/Password
- Enter host and port
- Provide username and password
- Specify database name
SSL Configuration
| Mode | Description |
|---|---|
disable | No SSL |
require | SSL required |
verify-ca | Verify CA certificate |
verify-full | Verify CA and hostname |
Configuration
| Setting | Description |
|---|---|
| Host | Database hostname |
| Port | Database port (5432) |
| Database | Database name |
| Username | DB user |
| Password | User password |
| SSL Mode | SSL configuration |
| Schema | Schema to index |
Setup Steps
- Add Connector: Knowledge → Add Data Source → PostgreSQL
- Enter Connection: Host, port, database
- Provide Credentials: Username and password
- Configure SSL: If required
- Test & Create: Verify and save
Usage with Agents
Once connected, AI agents can:
User: "What were our total sales last quarter?"
Agent:
├── Tool: search_database_schema
│ Finding relevant tables...
├── Tool: query_database
│ SELECT SUM(amount) FROM orders
│ WHERE created_at >= '2024-10-01'
└── Answer: Total sales were $1.2M
Schema Discovery
ZenSearch indexes:
- Table names and descriptions
- Column names and types
- Primary and foreign keys
- Indexes and constraints
Query Validation
For security, queries are validated:
- Only SELECT statements allowed
- No data modification (INSERT, UPDATE, DELETE)
- No schema changes (DROP, ALTER)
- Timeout limits enforced
Best Practices
- Create a read-only database user
- Limit schema access if needed
- Add table/column comments for better NL understanding
- Index frequently queried columns
Troubleshooting
Connection refused: Check host/port and firewall
Authentication failed: Verify username and password
SSL required: Enable appropriate SSL mode