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

FieldDescriptionExample
HostServer hostname or IPdb.example.com
PortPostgreSQL port (default 5432)5432
DatabaseDatabase nameanalytics
UsernameDatabase userreadonly_user
PasswordUser password********
SSL ModeSSL connection moderequire

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

  1. Go to Connectors > Add Connector
  2. Select PostgreSQL
  3. Enter your connection details
  4. Set SSL Mode (recommended: require)
  5. Click Test Connection
  6. Save when successful

SSL Configuration

PostgreSQL supports several SSL modes:

ModeDescription
disableNo SSL (not recommended)
allowPrefer SSL, fall back to unencrypted
preferPrefer SSL, fall back to unencrypted
requireRequire SSL, skip verification
verify-caRequire SSL, verify CA certificate
verify-fullRequire 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

  1. Enable public accessibility or use VPC peering
  2. Add Formula Bot IPs to your security group
  3. SSL is enabled by default

Heroku Postgres

  1. Get credentials from Heroku dashboard
  2. SSL is required (require mode)
  3. Credentials may rotate - update if connection fails

Supabase

  1. Find connection details in project settings
  2. Use the connection pooler for better performance
  3. SSL is required

DigitalOcean

  1. Add trusted sources in the database settings
  2. Download the CA certificate if using verify modes
  3. 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:

  1. Grant access to relevant schemas:
GRANT USAGE ON SCHEMA marketing TO formulabot;
GRANT SELECT ON ALL TABLES IN SCHEMA marketing TO formulabot;
  1. 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

Next Steps