PostgreSQL Engine Configuration
PostgreSQL is a realtime database that stores the materialized views and tables generated by your DataSQRL pipeline for low-latency querying.
Configuration Optionsโ
No mandatory configuration keys are required. Physical DDL (tables, indexes, views) is produced automatically by the DataSQRL compiler.
| Key | Type | Default | Description |
|---|---|---|---|
partition-ttl-divisor | integer | 100 | Controls the number of partitions for range-partitioned tables with a TTL (see Partitioning). |
partition-premake | integer | 4 | Number of future partitions pg_partman pre-creates ahead of the current one (p_premake). |
Basic Configurationโ
{
"engines": {
"postgres": {
"partition-ttl-divisor": 100,
"partition-premake": 4
}
}
}
Partitioningโ
Tables annotated with partition_key on a timestamp column and a ttl hint are range-partitioned with pg_partman, and expired partitions are dropped automatically. The partition width is derived from the TTL:
- The TTL duration divided by
partition-ttl-divisorcaps the number of partitions. - The unit the TTL is declared with sets the minimum width:
ttl(14 days)never produces partitions smaller than 1 day, whilettl(336 hours)allows hourly partitions. - The result is snapped down to the closest calendar-aligned width from: 15 min, 30 min, 1, 2, 4, 6, 8, 12 hours, 1, 2, 4 days, 1, 2, 4, 8, 12 weeks.
For example, ttl(14 days) with the default divisor produces 1-day partitions.
At setup time, pg_partman pre-creates the historical partitions covering the full TTL window (via p_start_partition), so replayed or late-arriving data within the retention period lands in a dated partition rather than the DEFAULT partition. The partition-premake key controls how many future partitions are created ahead of the current one.
Conflict Handlingโ
When a generated PostgreSQL table receives a row that conflicts with an existing row on a primary key or unique constraint, DataSQRL chooses one of the following conflict handling strategies:
| Strategy | PostgreSQL behavior | Description |
|---|---|---|
| Update | ON CONFLICT (...) DO UPDATE SET ... | The existing row is overwritten with the incoming row. |
| Timestamp update | ON CONFLICT (...) DO UPDATE SET ... WHERE incoming timestamp >= existing timestamp | The existing row is overwritten only when the incoming timestamp is not older than the existing one. Otherwise, the conflicting insert is silently skipped, which prevents out-of-order events from rolling back newer state. |
| Ignore | ON CONFLICT (...) DO NOTHING | The existing row is kept, and the conflicting insert is silently skipped. |
DataSQRL applies these strategies automatically based on the generated table type:
STATEtables use timestamp update with the appropriate timestamp column.STREAMtables use ignore.- Other PostgreSQL tables use update.
To override the automatic choice, set sink.on-conflict.action to UPDATE, TIMESTAMP, or IGNORE in the postgres connector template.
The template applies to every PostgreSQL table, and TIMESTAMP also requires sink.on-conflict.timestamp-column to name a timestamp column that exists in each table.
The primary key of a STREAM table is expected to identify each row, and a STREAM table without a primary key is keyed on a hash of all its columns.
DataSQRL does not enforce this. When it holds, a conflict is a replay of a row that was already written, for example after the pipeline restarts from a checkpoint, and every strategy stores the same row.
When rows with the same key differ, those in one write batch are first reduced to the last one, and the strategy then decides between that row and the stored one. Ignore keeps the stored row.
Usage Notesโ
- Database schema is automatically generated from your SQRL script
- Tables, indexes, and views are created based on the compiled data pipeline
- Connection parameters are typically provided via environment variables
- The engine handles both real-time data ingestion and query serving
- Optimized for low-latency reads of materialized data
- Read replicas improve query performance and provide redundancy
Internal Environment Variablesโ
When running pipelines with the DataSQRL run command, the following environment variables are used
in the configuration:
POSTGRES_VERSIONPOSTGRES_HOSTPOSTGRES_PORTPOSTGRES_DATABASEPOSTGRES_AUTHORITYPOSTGRES_JDBC_URLPOSTGRES_USERNAMEPOSTGRES_PASSWORD