PostgreSQL Overview
ThePOSTGRESQL connector stores MQTT messages in PostgreSQL databases. It supports SSL connections, parameterized queries, and automatic reconnection for reliable data persistence.
Because the connector speaks the PostgreSQL wire protocol, it also works with any service built on PostgreSQL — you use the same POSTGRESQL connector 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
Database password. Characters such as
;, =, and quotes work as typed, here and in USERNAME and DATABASE.SSL/Security
SSL/Security
Timeouts
Timeouts
Pool and writes
Pool and writes
Maximum connections in the pool. Passed to the PostgreSQL driver. Omit to keep the driver default.
Minimum connections in the pool. Passed to the PostgreSQL driver. Omit to keep the driver default. Must be less than or equal to
MAX_POOL_SIZE.How long an idle pooled connection may be kept. Passed to the PostgreSQL driver. Omit to keep the driver default.
How long a pooled connection may be kept. Passed to the PostgreSQL driver. Omit to keep the driver default.
What to do when MQTT-triggered writes are already at
WRITE_CONCURRENCY. block waits, and WRITE_QUEUE_CAPACITY is ignored. drop_oldest and drop_newest apply WRITE_QUEUE_CAPACITY. Dropping an event logs a Warning and counts the drop.MIN_POOL_SIZE must be less than or equal to MAX_POOL_SIZE.
A failed query does not mark the connector Disconnected. A constraint violation, a cast error, PostgreSQL 53300 (too_many_connections), an exhausted pool, and any other query failure leave it connected. Only a transport or connection failure marks it Disconnected, so one bad row does not stop later telemetry.
Reconnecting after a dropped connection
When the database ends the connector’s sessions, the connection drops, or a query runs pastCOMMAND_TIMEOUT, the connector is marked Disconnected. The next event reconnects it, straight away and then at most every 5 seconds until the database answers, and runs once the connection is back. No redeploy is needed. The event that was running on the dropped session fails and is not retried.
Agent queries
An agent can read this database when the connector opts in and the agent grantsconnector_query. The agent runs one read statement. It cannot insert, update, or delete. See Database queries.
If you omit the agent login, PostgreSQL uses the connector user inside a read-only transaction and rolls it back. The broker logs a warning. Give the agent its own read-only user.
The person who asks and the agent’s
DEFAULT_USER both need PublishSys on $SYS/Coreflux/Routes/<connector>/Query.
Event Configuration
EVENT Parameters
Query Placeholders
How placeholders are quoted
The broker places each placeholder in an eventQUERY by the quotes around it. A publisher on the source topic can no longer change the SQL by putting SQL in the payload.
{env.NAME} and {secret.NAME} are placed as written. A value that itself contains {topic} is stored as text and is not expanded again. The same rules on the other SQL engines are in How placeholders are quoted. MongoDB and OpenSearch JSON queries place each value as one JSON value instead (see OpenSearch 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:{value.json.value} stays unquoted because 23.5 is a number. If that field is text, put it in single quotes ('{value.json.value}'), or the event is refused.Alternative: STORE IN with Models — Instead of writing EVENT queries, you can bind a model directly to this connector. 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
- Put text placeholders in single quotes, and table or column placeholders in double quotes. An unquoted text value refuses the event. See How placeholders are quoted
- Verify table and column names exist
- Test query manually in psql first
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 Connectors Overview
Compare all storage options.
MySQL Connector
Configure MySQL database storage.

