# Under 100m sensor rows, plain Postgres partitioning is enough

> The vendor measured its own drop from 67 seconds to 1.8ms; at the plant, an FDE has to decide on row counts, dashboard resolution and the client's cloud.

Original: https://fdetimes.net/en/tools/postgres-vs-timescaledb-factory-sensor-data/

An hourly-average query over one week fell from more than 67 seconds to 1.8 ms. That is the result Tiger Data, the company formerly called Timescale, published on its blog for a factory scenario: 50 rotating machines sending vibration data at 10 samples per second, running continuously for six months.

The test used an 8 CPU / 32 GiB instance, and the vendor ran it itself. It is not an independent benchmark.

The number looks good, but it does not answer the question an FDE actually faces at a plant. The client already runs PostgreSQL, the operations team knows it, and they want to know whether they need to install anything else.

Getting it wrong is expensive in either direction. Install an extension you do not need and there is one more thing to operate; skip it when you do need it and a few months later the dashboard takes more than ten seconds to load.

## What does TimescaleDB do that plain Postgres does not?

TimescaleDB is a PostgreSQL extension. According to a blog post by Ajay Kulkarni and Mike Freedman, Timescale launched around 2017 with the aim of bringing time-series data into Postgres.

Plain Postgres is no slouch with time data. It has native partitioning, and the PostgreSQL documentation advises partitioning only when a table is genuinely large, with the rule of thumb being a table that exceeds the server's physical memory.

It also has BRIN indexes, designed for very large tables whose columns correlate naturally with their physical location on disk, such as the timestamp column of sensor data written in sequence.

Gabriel Anhaia, an independent author, benchmarked 1 billion rows across 500 series on Postgres 18. He concluded that below 100 million rows native partitioning is enough, and at that size BRIN is not even needed yet.

Yet he also argues that continuous aggregates are where plain Postgres cannot keep up: in his test, a 90-day dashboard query took 14.2 seconds natively but only 38 ms with a continuous aggregate.

These are one person's measurements and have not been independently verified. Even so, they tell you where to measure first: aggregate queries that span many days.

## Running the numbers for a 50-machine plant

Take Tiger Data's own scenario. Fifty machines at 10 samples per second is 500 rows per second; multiplied by 86,400 seconds, that is 43.2 million rows per day. Over six months, or 180 days, the table holds about 7.8 billion rows, and Anhaia's 100-million-row mark is crossed after just over two days.

That arithmetic gives you the first answer. A line of 5 machines sampling once a minute would take years to reach 100 million rows, so by Anhaia's threshold plain Postgres is enough, perhaps without partitioning at all.

High-frequency vibration data, by contrast, quickly outgrows the server's RAM. Then the second question decides the matter: if the client wants "a chart of hourly averages over the last 90 days", every dashboard load has to scan billions of rows.

That is when a continuous aggregate earns its keep.

**Key point:** Row count tells you how big the table gets; the dashboard tells you whether you need pre-aggregation.

## A minimal setup, and the retention trap

The usual setup has three parts: a raw table, an hourly aggregate and a policy that deletes old raw data.

```sql
CREATE TABLE vibration (
  time       timestamptz NOT NULL,
  machine_id int         NOT NULL,
  value      double precision
);
SELECT create_hypertable('vibration', 'time');

CREATE MATERIALIZED VIEW vibration_hourly
WITH (timescaledb.continuous) AS
SELECT time_bucket('1 hour', time) AS bucket, machine_id, avg(value) AS avg_value
FROM vibration
GROUP BY bucket, machine_id;

SELECT add_continuous_aggregate_policy('vibration_hourly',
  start_offset => INTERVAL '7 days', end_offset => INTERVAL '1 hour',
  schedule_interval => INTERVAL '1 hour');

-- Keep raw data for 30 days: longer than the 7-day refresh window
SELECT add_retention_policy('vibration', INTERVAL '30 days');
```

The last line is the easiest to get wrong. Tiger Data's documentation warns that the raw-data retention interval must be longer than the continuous aggregate's refresh window.

Set retention to 3 days while the refresh looks back 7 days, and the first refresh after the raw data is dropped may also delete the hours already aggregated for days 4 through 7.

The client will only notice when last week's chart suddenly shows a gap.

## Can the client's infrastructure run the full edition?

TimescaleDB comes in two editions: the Apache 2 Edition and the Community Edition under the TSL license. According to the vendor's comparison page, compression/columnstore, continuous aggregates and retention policies are available only in the Community Edition. The hourly aggregate and `add_retention_policy` in the setup above therefore will not run on the Apache edition.

That has immediate consequences for the architecture. Azure Database for PostgreSQL flexible server offers only the Apache-2 edition, so if the client runs on that service, the main feature you planned to use will not be there.

The TSL license permits internal use but forbids using the software to provide a database-as-a-service. If your company's product packages a database shared by many customers, have legal review that clause before you write the first line of SQL.

The sensible order for the first working session is therefore: calculate rows per day, ask the client what resolution the dashboard needs and over what time span, then ask where they run Postgres and which TimescaleDB edition that environment offers. Only after those three questions should you choose between native partitioning and TimescaleDB.

On a CV, a line such as "evaluated native Postgres and TimescaleDB for 43 million rows/day of sensor data, cutting dashboard load time from X to Y" shows a hiring manager that you measure before you pick a tool, a skill every FDE needs.

Tiger Data's 67 seconds and Anhaia's 14.2 seconds were both measured on someone else's machines. The most reliable number is the multiplication you do yourself from your own client's machine count and sampling rate.

**Try this week:**

- Take the machine count and sampling rate of a real or hypothetical client, then calculate rows per day and how many days it takes to pass the 100-million-row mark from Anhaia's benchmark.
- Run TimescaleDB on your own machine, create an hourly continuous aggregate, and time a 90-day dashboard query before and after adding the aggregate.
- Ask a client where they run Postgres (self-hosted, Azure Database for PostgreSQL flexible server or another service) and note which TimescaleDB edition that environment provides.

## Sources

- [timescale/timescaledb (GitHub)](https://github.com/timescale/timescaledb)

- [Speed Without Sacrifice: Building the Modern PostgreSQL for the Analytical and Agentic Era](https://www.tigerdata.com/blog/timescale-becomes-tigerdata)

- [TimescaleDB editions (Tiger Data docs)](https://www.tigerdata.com/docs/get-started/choose-your-path/timescaledb-editions)

- [Software Licensing: Timescale License (TSL)](https://www.tigerdata.com/legal/licenses)

- [Considerations when Using Extensions and Modules in Azure Database for PostgreSQL Flexible Server](https://learn.microsoft.com/en-us/azure/postgresql/extensions/concepts-extensions-considerations)

- [TimescaleDB for Manufacturing IoT: Optimizing for High-Volume Production Data](https://www.tigerdata.com/blog/timescaledb-for-manufacturing-iot-optimizing-for-high-volume-production-data)

- [Data lifecycle (Tiger Data docs)](https://www.tigerdata.com/docs/learn/data-management/data-lifecycle)

- [PostgreSQL Documentation: Table Partitioning](https://www.postgresql.org/docs/current/ddl-partitioning.html)

- [PostgreSQL Documentation: BRIN Indexes](https://www.postgresql.org/docs/current/brin.html)

- [Time-series in Postgres: when TimescaleDB wins, when native partitioning beats it](https://dev.to/gabrielanhaia/time-series-in-postgres-when-timescaledb-wins-when-native-partitioning-beats-it-1bk0)
