I have a case with a TSDB Hypertable looking approximately like this:
CREATE TABLE data (
pool_id INTEGER NOT NULL,
ts TIMESTAMP NOT NULL,
noise_err DECIMAL,
noise_val DECIMAL,
signal_err DECIMAL,
signal_val DECIMAL,
high_val DECIMAL,
low_val DECIMAL,
CONSTRAINT data_pid_fk FOREIGN KEY (pool_id) REFERENCES pools (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX data_pts_idx ON data (pool_id, ts);
SELECT create_hypertable('data', 'ts', 'pool_id', 100);
There are ~1000 pools, data
contains >1 year of minute records for every pool, and quite a few analytical queries working with the last 3 to 5 days of data. New data is coming with arbitrary delay: 10ms to 30s depending on the pool.
Now the problem: I need to run analytical queries as fast as possible after the new record has been received, hence I can't insert in batches, and I need to speed up single row insertions.
I've run timescaledb-tune
, then turned off synchronous commits (synchronous_commit = off
), played with unlogged
table mode, and tried to disable the auto vacuum, which didn't help much.
The best insert time I get is ~37ms and degrading when concurrent inserts start to 110ms.
What else except removing indexes/constraints can I do to speed up single row inserts?