Skip to main content

CrateDB Overview

The CRATEDB route 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

HOST
string
required
CrateDB server hostname or IP address.
USERNAME
string
required
Database username.
PASSWORD
string
required
Database password.
PORT
integer
CrateDB PostgreSQL protocol port. Default: 5432.
DATABASE
string
Target database/schema name.
Never hardcode credentials in production. Use environment variables and encrypted secrets to keep sensitive values out of your route definitions:
See Environment Variables & Secrets for setup and usage.

Writing Data

Store sensor readings with timestamps:
Alternative: STORE IN with Models — Instead of writing EVENT queries, you can bind a model directly to this route. Every PUBLISH MODEL call automatically inserts a row — no query needed:
See Data Storage Overview for the full STORE IN workflow.

Reading Data

EVENTs also support SELECT queries to read data back from the database. Publish a message to the event’s SOURCE_TOPIC, and the query result is published to DESTINATION_TOPIC:
To trigger this query, publish the sensor ID to the source topic:
The query result is published to db/result/latest, where your actions or external clients can consume it.

Timed Polling

EVENTs can also run SELECT queries on a fixed schedule using WITH EVERY. This is especially powerful with CrateDB’s fast aggregations:

Table Schema Examples

Create tables optimized for time-series:

Troubleshooting

  • Verify HOST and PORT are correct
  • Check CrateDB is running and accepting connections
  • Verify firewall allows connections on port 5432
  • Verify USERNAME and PASSWORD are correct
  • Check user has permissions on the DATABASE
  • Verify table exists and has correct schema
  • Check column types match inserted data

Next Steps

Data Storage Routes Overview

Compare all storage options.

Snowflake Route

Configure Snowflake cloud data warehouse.
Last modified on May 22, 2026