CrateDB Overview
TheCRATEDB connector stores MQTT messages in CrateDB, a distributed SQL database optimized for time-series and machine data. It combines the familiarity of SQL with the scalability needed for IoT workloads.
CrateDB excels at high-volume time-series data with fast ingestion and SQL query capabilities. Use it when you need real-time analytics on sensor data at scale.
Basic Syntax
Connection Configuration
CRATEDB_CONFIG Parameters
Optional Settings
Optional Settings
Schema for unqualified table names and for
STORE IN. Default: doc. Kept exactly as written, so it is case-sensitive.Connect over TLS. Default: false. Without it the connection is plain text. See TLS.
Require TLS and accept a certificate the broker cannot verify, such as a self-signed one. Default: false. Applies only when
USE_SSL is true.HOST, a PORT outside 1–65535, a CONNECTION_TIMEOUT below 1, a COMMAND_TIMEOUT that is not a whole number, and a USE_SSL or TRUST_SERVER_CERTIFICATE that is not true or false. A password, user, or database that contains ;, =, or a quote is sent as typed.
TLS
Use
USE_SSL "true" with TRUST_SERVER_CERTIFICATE "true" for a CrateDB node with a self-signed certificate:
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.
The clauses below belong in CRATEDB_CONFIG.
CrateDB is refused unless you set
AGENT_USERNAME and AGENT_PASSWORD, or AGENT_CONNECTION_STRING. It does not fall back to a read-only transaction on the connector login.
The person who asks and the agent’s DEFAULT_USER both need PublishSys on $SYS/Coreflux/Routes/<connector>/Query.
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 Time-Series
- High-Volume Metrics
- Multiple Tables
- UPSERT
- UPDATE
- DELETE
Store sensor readings with timestamps:
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:Storing models with STORE IN
STORE IN writes to the schema set by DATABASE, or to doc when DATABASE is omitted or blank. That is the same schema an event uses for a table name without a schema, so an event can read back what a model stored. The table name is folded to lower case, and column names come from the model fields in lower case.
The first store creates a missing table. A table that already exists keeps its columns. If the table is dropped later, the next store creates it again.
A model
INT is a 32-bit whole number. A topic value outside -2147483648 to 2147483647 is logged and the model does not publish, so nothing is stored. The value is no longer stored as 2147483647.
Upgrading: Rows that earlier versions stored are in the
doc schema. When DATABASE names another schema, new rows go to that schema, and the old rows stay in doc. Copy them over, or query doc.<table>, if you still need them.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.
CrateDB makes new rows visible to reads about once a second. A
SELECT event that runs right after an insert may not see that row yet. Run REFRESH TABLE <table> first when you need it.Timed Polling
EVENTs can also run SELECT queries on a fixed schedule usingWITH EVERY. This is especially powerful with CrateDB’s fast aggregations:
While CrateDB is unreachable
After a connection failure, the next event orSTORE IN checks CrateDB at once. If CrateDB answers, the work runs. If not, the work is skipped and later checks run at most every 5 seconds. Work that arrives between checks is skipped instead of waiting out CONNECTION_TIMEOUT.
Each check logs how many events and STORE IN rows were skipped: a warning while CrateDB is still down, and an information line with the total when the connector reconnects.
Checking the connection
-checkConnectorConnection <Name> connects to CrateDB and runs SELECT 1. A wrong host, port, or login fails the check, and the reply names the host and port it tried. The password is not included. The check waits at most 10 seconds.
Table Schema Examples
Create tables optimized for time-series:Troubleshooting
Connection Failed
Connection Failed
- Run
-checkConnectorConnectionand read the host and port in the reply - Verify HOST and PORT are correct
- Check CrateDB is running and accepting connections
- Verify firewall allows connections on port 5432
- If the node only accepts TLS, set
USE_SSL "true". See TLS
Authentication Failed
Authentication Failed
- Verify USERNAME and PASSWORD are correct
- Check user has permissions on the DATABASE
Query Errors
Query Errors
- Verify table exists and has correct schema
- 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
- Check column types match inserted data
STORE IN rows are missing
STORE IN rows are missing
- Look in the schema set by
DATABASE, ordocwhen it is omitted. The name is case-sensitive - An
INTvalue outside the 32-bit range is logged and not stored
Next Steps
Data Storage Connectors Overview
Compare all storage options.
Snowflake Connector
Configure Snowflake cloud data warehouse.

