PostgreSQL Overview
ThePOSTGRESQL route stores MQTT messages in PostgreSQL databases. It supports SSL connections, parameterized queries, and automatic reconnection for reliable data persistence.
Because the route speaks the PostgreSQL wire protocol, it also works with any service built on PostgreSQL — you use the same POSTGRESQL route type and point SQL_CONFIG at that provider’s host, port, database, and credentials.
PostgreSQL is ideal for structured data that requires complex queries, joins, and ACID compliance. Use it when you need relational integrity and powerful SQL capabilities.
Basic Syntax
Connection Configuration
SQL_CONFIG Parameters
PostgreSQL server hostname or IP address.
Target database name.
Database username.
Database password.
Optional Settings
Optional Settings
PostgreSQL port. Default: 5432.
SSL/Security
SSL/Security
Event Configuration
EVENT Parameters
MQTT topic pattern that triggers the INSERT. Supports wildcards.
SQL INSERT statement with placeholders for dynamic values.
Optional Settings
Optional Settings
MQTT topic to publish query result status.
Query Placeholders
Writing Data
- Basic Sensor Storage
- With SSL
- Multiple Events
- JSON Column
- UPSERT
- UPDATE
- DELETE
Store temperature readings with timestamps:Input at
sensors/temp001/temperature:Alternative: STORE IN with Models — Instead of writing EVENT queries, you can bind a model directly to this route. Every See Data Storage Overview for the full STORE IN workflow.
PUBLISH MODEL call automatically inserts a row — no query needed:Reading Data
EVENTs also support SELECT queries to read data back from the database. Publish a message to the event’sSOURCE_TOPIC, and the query result is published to DESTINATION_TOPIC:
db/result/latest, where your actions or external clients can consume it.
Timed Polling
EVENTs can also run SELECT queries on a schedule instead of waiting for an MQTT trigger. UseWITH EVERY to publish fresh data at a fixed interval:
dashboard/devices/active every 10 seconds — no trigger message needed.
Table Schema Examples
Create tables to match your data:Troubleshooting
Connection Refused
Connection Refused
- Verify SERVER and PORT are correct
- Check PostgreSQL is running and accepting connections
- Verify firewall allows connections on port 5432
- Check
pg_hba.confallows your IP address
Authentication Failed
Authentication Failed
- Verify USERNAME and PASSWORD are correct
- Check user has permissions on the DATABASE
- Verify authentication method in
pg_hba.conf
SSL Connection Errors
SSL Connection Errors
- Ensure USE_SSL matches server requirements
- For self-signed certs, set TRUST_SERVER_CERTIFICATE “true”
- Verify SSL is enabled on PostgreSQL server
Query Syntax Errors
Query Syntax Errors
- Check placeholder names match topic structure
- Verify table and column names exist
- Test query manually in psql first
- Ensure proper escaping for special characters
Timeout Errors
Timeout Errors
- Increase CONNECTION_TIMEOUT for slow networks
- Increase COMMAND_TIMEOUT for complex queries
- Check server load and query performance
Next Steps
Data Storage Routes Overview
Compare all storage options.
MySQL Route
Configure MySQL database storage.

