PostgreSQL
Step-by-step guide to connecting PostgreSQL to Formula Bot, including read-only user setup, SSL configuration, and cloud provider instructions.
Connect your PostgreSQL database to analyze data using natural language queries and create visualizations.
Prerequisites
- PostgreSQL 10 or higher
- Database credentials
- Network access from Formula Bot servers
- A user with SELECT permissions
Connection Details
| Field | Description | Example |
|---|---|---|
| Host | Server hostname or IP | db.example.com |
| Port | PostgreSQL port (default 5432) | 5432 |
| Database | Database name | analytics |
| Username | Database user | readonly_user |
| Password | User password | ******** |
| SSL Mode | SSL connection mode | require |
Setup Steps
1. Create a Read-Only User
CREATE USER formulabot WITH PASSWORD 'your-secure-password';
GRANT CONNECT ON DATABASE your_database TO formulabot;
GRANT USAGE ON SCHEMA public TO formulabot;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO formulabot;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO formulabot;
2. Configure Network Access
Allow connections from Formula Bot:
In pg_hba.conf:
host your_database formulabot 0.0.0.0/0 md5
Or use IP whitelisting in your cloud provider's security settings.
3. Connect in Formula Bot
- Go to Connectors > Add Connector
- Select PostgreSQL
- Enter your connection details
- Set SSL Mode (recommended:
require) - Click Test Connection
- Save when successful
SSL Configuration
PostgreSQL supports several SSL modes:
| Mode | Description |
|---|---|
disable | No SSL (not recommended) |
allow | Prefer SSL, fall back to unencrypted |
prefer | Prefer SSL, fall back to unencrypted |
require | Require SSL, skip verification |
verify-ca | Require SSL, verify CA certificate |
verify-full | Require SSL, verify CA and hostname |
Use require or higher for production databases. Cloud databases like AWS RDS and Heroku require SSL by default.
Cloud Providers
AWS RDS
- Enable public accessibility or use VPC peering
- Add Formula Bot IPs to your security group
- SSL is enabled by default
Heroku Postgres
- Get credentials from Heroku dashboard
- SSL is required (
requiremode) - Credentials may rotate - update if connection fails
Supabase
- Find connection details in project settings
- Use the connection pooler for better performance
- SSL is required
DigitalOcean
- Add trusted sources in the database settings
- Download the CA certificate if using verify modes
- SSL is available
Example Questions
- "Show me all users who signed up this month"
- "What's the total revenue by product category?"
- "List orders with a value over $1000"
- "Create a time series of daily active users"
Schemas
If your database uses multiple schemas:
- Grant access to relevant schemas:
GRANT USAGE ON SCHEMA marketing TO formulabot;
GRANT SELECT ON ALL TABLES IN SCHEMA marketing TO formulabot;
- Reference tables with schema prefix in questions:
- "Show data from marketing.campaigns table"
Troubleshooting
Connection Timeout
- Verify host and port
- Check firewall/security group rules
- Ensure the database is running
SSL Certificate Error
- Try a less strict SSL mode for testing
- Verify CA certificate if using
verify-ca - Check certificate hasn't expired
Permission Denied
- Verify user has SELECT on the tables
- Check schema permissions (USAGE)
- Grant permissions on new tables if needed