PostgreSQL Integration (QueryWeaver)
Connect PostgreSQL databases and query them using natural language.
Overview
QueryWeaver allows your chatbot to:
- Understand your database schema
- Convert questions to SQL queries
- Execute queries safely
- Format results for users
How It Works
- User asks a question in natural language
- WizChat understands the database schema
- AI generates appropriate SQL query
- Query is executed safely
- Results are formatted and presented
Example:
- User: "How many orders were placed last month?"
- SQL:
SELECT COUNT(*) FROM orders WHERE created_at >= '2024-01-01' AND created_at < '2024-02-01' - Response: "There were 1,247 orders placed last month."
Connecting a Database
- Go to "Settings" > "Integrations"
- Click "PostgreSQL"
- Enter connection details:
- Host
- Port (default: 5432)
- Database name
- Username
- Password
- Click "Test Connection"
- Click "Save"
Connection Options
| Option | Description |
|---|---|
| SSL Mode | Require, prefer, or disable SSL |
| Connection Timeout | Max connection wait time |
| Query Timeout | Max query execution time |
| Read Only | Restrict to SELECT queries |
Schema Scanning
After connecting, WizChat scans your schema:
- Tables and columns are discovered
- Data types are identified
- Relationships are mapped
- Descriptions can be added
Multiple Schema Support
You can select one or more schemas per PostgreSQL connection. This is useful when your database organizes data across schemas (e.g., public, sales, analytics).
- Go to your PostgreSQL MCP server settings
- In the "Schemas" field, select the schemas you want to expose
- Click "Save"
- Re-scan to discover tables from all selected schemas
WizChat will automatically prefix table names with the schema name when multiple schemas are selected, so the AI can distinguish between them.
If different schemas contain tables with the same name, WizChat handles this automatically — no manual disambiguation needed.
Viewing Schema
- Go to "Integrations" > "PostgreSQL"
- Click "Schema"
- Browse tables and columns
Adding Descriptions
Help the AI understand your schema:
- Click on a table or column
- Add a description
- Click "Save"
Example:
- Table
cust: "Customer information table" - Column
amt: "Order amount in USD"
Query Safety
Read-Only Mode
By default, only SELECT queries are allowed:
- No INSERT, UPDATE, DELETE
- No schema changes
- Safe for production databases
Query Review
Optionally review queries before execution:
- Go to "Settings" > "PostgreSQL"
- Enable "Review Queries"
- Queries show SQL before running
Row Limits
Prevent large result sets:
- Default: 100 rows
- Configurable per database
- Pagination for larger results
Example Queries
| Natural Language | Generated SQL |
|---|---|
| "Show me top 10 customers" | SELECT * FROM customers ORDER BY total_purchases DESC LIMIT 10 |
| "What's our monthly revenue?" | SELECT DATE_TRUNC('month', order_date), SUM(amount) FROM orders GROUP BY 1 |
| "Find orders over $1000" | SELECT * FROM orders WHERE amount > 1000 |
Metrics Dashboard
WizChat can automatically detect key metrics from your PostgreSQL data and display them in a visual dashboard.
How It Works
- WizChat analyzes your schema and suggests metrics (counts, averages, totals)
- Metrics are displayed as charts and summary cards
- You can also define custom metrics with your own SQL
Using Metrics
- Open your chatbot
- Go to the "MCP" tab
- Select a PostgreSQL server
- Click the "Metrics" tab
- View auto-detected metrics or add your own
Multiple Servers
If you have more than one PostgreSQL connection, each server gets its own metrics tab. Server names are shown clearly even when multiple databases share the same host.
Custom Metrics
To add a custom metric:
- Click "Add Custom Metric"
- Enter a name and SQL query
- Select the chart type
- Click "Save"
Metric Access Control
Metric visibility is controlled in two layers:
- Server access — controls who can see the PostgreSQL integration at all
- Metric access — additional filtering within the server's user group
Both layers must pass for a user to see a metric. If the server is restricted to specific users, only those users can see any metrics — even ones marked "Public." A public metric means "visible to all server users," not "visible to everyone."
Managing per-metric access
By default, all metrics are visible to every user who has access to the server. You can restrict individual metrics further so only specific users or groups can see them.
- Go to the "Metrics" tab for your PostgreSQL server
- Click the globe icon next to the metric you want to restrict
- Choose "Restricted" and add authorized users or groups
- Click "Save Changes"
| Icon | Meaning |
|---|---|
| Globe (blue) | Visible to all server users |
| Lock (amber) | Restricted to specific users or groups |
You can use Email Groups to manage access for multiple users at once. Create groups in Settings > Email Groups, then add them to any metric.
When the server itself is restricted, the admin UI shows a purple banner reminding you that server-level access applies first. The "Public" option in the metric access dialog means "all server users" rather than "all chatbot users."
How it works for end users:
- Users who don't have server access won't see any metrics from that server
- Within an accessible server, users only see metrics they are authorized for
- Anonymous (unauthenticated) users only see public metrics on public servers
- No error messages or "access denied" notices are shown — restricted metrics are silently hidden
Best Practices
Database Setup
- Use a read-only database user
- Grant minimal required permissions
- Consider using a replica
- Set appropriate timeouts
Schema Optimization
- Add descriptions to tables/columns
- Use clear naming conventions
- Document relationships
- Exclude sensitive tables
Performance
- Add indexes for common queries
- Set appropriate row limits
- Monitor query performance
- Use query timeouts
Security
- Credentials are encrypted
- Connections use SSL when available
- Queries are parameterized
- Access can be revoked anytime
Never connect databases containing sensitive data (passwords, PII) without proper security review.
Troubleshooting
Connection Failed
- Verify host and port
- Check firewall rules
- Confirm credentials
- Test SSL settings
Queries Not Working
- Check schema descriptions
- Verify table permissions
- Review generated SQL
- Add more context to questions
Slow Queries
- Add appropriate indexes
- Reduce row limits
- Check database performance
- Optimize complex queries