Time-series data is a sequence of observations associated with time. Examples include temperature readings from a sensor, requests per second from an application, daily sales, and changes in a stock price. Observations do not have to arrive at perfectly regular intervals: devices can disconnect, events can be delayed, and people can correct records.
The right storage choice depends less on the label "time-series database" than on how much data you collect, how you query it, and how long you need to keep raw detail. For a small application, a regular relational database is often a sensible place to start. Add specialized storage only when measured requirements justify its extra cost and operational work.
What makes time-series data different?
Each observation usually has at least an event time, a measured value, and some identity or dimensions that describe what produced it. A useful model distinguishes:
- Event time: when the measurement or event actually happened.
- Ingestion time: when your system received and stored it.
- Dimensions: identifiers such as device, metric, customer, or location.
Event time is not the same as row insertion order. A device may upload buffered readings after reconnecting, and a delayed event may belong in an earlier reporting window. Keep the event timestamp, and keep an ingestion timestamp when you need to measure delay, diagnose pipelines, or decide how to handle late arrivals.
Choose storage for your workload
Start with PostgreSQL for a small application
Use ordinary PostgreSQL when the data volume is manageable, the application already uses it, and time-based queries are straightforward. Keeping readings alongside application records can simplify transactions, permissions, backups, and development.
For example, this table assumes one value per sensor and metric at a given instant:
CREATE TABLE readings (
sensor_id bigint NOT NULL,
metric text NOT NULL,
observed_at timestamptz NOT NULL,
value double precision NOT NULL,
received_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY (sensor_id, metric, observed_at)
);
Use timestamptz for an instant in time and send timestamps with an explicit offset, commonly UTC. PostgreSQL converts these values internally and displays them using the session time zone. If the original local time zone itself matters for a business rule, store that separately. The PostgreSQL date and time documentation explains the available types and their behavior.
The primary key supports lookups for one sensor and metric over a time range. Query a bounded interval and aggregate only what the screen or report needs:
SELECT date_trunc('hour', observed_at) AS hour,
avg(value) AS average_value
FROM readings
WHERE sensor_id = $1
AND metric = $2
AND observed_at >= $3
AND observed_at < $4
GROUP BY hour
ORDER BY hour;
For consistent bucket boundaries, choose the time zone deliberately. PostgreSQL's date_trunc uses the session time zone for timestamptz values unless a zone is supplied, so UTC is a useful default for operational charts while business reports may need a named local zone. This matters around daylight-saving changes as well as when users in different regions compare results; see the date and time functions reference.
Add indexes for real query patterns rather than indexing every dimension. If reports often scan a time range across all sensors, compare an index beginning with observed_at against the actual query plan. The sample key also defines a deduplication rule; if your source can legitimately emit multiple values at the same instant, include an event identifier or another stable key instead.
Time filters also put a bound on the amount of history a request can scan. A dashboard that repeatedly reads every raw row may become expensive even if each query is correct. Check query plans and timings with representative data, then consider a rollup for repeated summaries. Every extra index can make inserts and storage more expensive, so compare read improvements with ingestion costs rather than adding indexes speculatively.
PostgreSQL also supports declarative range, list, and hash partitioning. Partitioning can help with particular large-table queries or make bulk data removal easier, but it introduces lifecycle and query-planning considerations. The PostgreSQL partitioning guide notes that the benefits generally matter for very large tables; measure the workload before splitting a table into partitions.
Consider a time-series extension when database operations become the problem
If PostgreSQL remains a good fit but managing large time windows, retention, or repeated rollups becomes cumbersome, a time-series extension such as TimescaleDB may help. Its hypertables partition time-series rows into time-based chunks while keeping a PostgreSQL table interface. Timescale's hypertable guide describes how that partitioning works.
For recurring reports, continuous aggregates can maintain time-bucketed summaries in the background. Retention policies can remove old raw chunks; pair them with summaries only when those summaries meet the application's historical needs. See the continuous aggregates guide and data retention guide. Check extension support, hosting options, version compatibility, and backup procedures before adopting it. A specialized database is not automatically cheaper: include the cost of the extension or service, migration, monitoring, and another recovery path in the decision.
Use Prometheus for operational metrics
Prometheus is designed for monitoring metrics such as request counts, latency, and resource utilization. A metric name plus its label values identifies a time series, so a label that changes for every request, user, or unique URL can create an excessive number of series. Its data model documentation explains this dimensional model.
Prometheus includes local disk storage and optional remote-storage integrations. The local store is not clustered or replicated, so plan backups and availability separately. Set retention based on both time and disk capacity; the storage guide documents these controls and recommends leaving headroom for compaction when using a size limit. Prometheus is usually a better fit for service metrics than as the only database for a product's transactional records.
Evaluate an analytical store for large scans
A column-oriented system such as ClickHouse may suit workloads that scan and aggregate large volumes across many dimensions. It adds another database and data pipeline to operate, so compare it with your existing database using representative data and queries before moving data. The ClickHouse time-series guide covers its time-series data types, operations, storage, and query tuning.
Plan for late events, retention, and cost
Decide what should happen when an event arrives late or is resent. A stable event ID or a carefully chosen uniqueness rule can make retries idempotent. Allow a defined lateness window for reports that must include delayed readings, and make corrections explicit rather than assuming records always arrive in order.
Retention is a product and operations decision, not just a database setting. Estimate how quickly raw data grows, identify which records must remain available, and choose a retention period that fits user needs, contractual or regulatory obligations, and storage budget. If older fine-grained data is no longer needed, you can archive it, delete it, or retain coarser summaries such as hourly or daily averages. Aggregation loses detail, so keep raw data for the period needed to investigate faults or recompute reports.
Choose rollup fields that preserve the questions you expect to ask. For example, retaining a sum and count lets you calculate a weighted average over several buckets; averaging bucket averages can give the wrong answer when the buckets contain different numbers of readings. A late event may also require refreshing the affected summary window. Raw-data retention and backup retention are separate policies: deleting old rows is not a substitute for testing that required backups can be restored.
Budget for more than the primary data files: indexes, replicas, backups, monitoring, and temporary space during maintenance can all affect total storage and cost. Measure insert volume, series or dimension cardinality, common query windows, concurrent readers, and backup size with realistic workloads. Do not promise performance based on a benchmark from a different dataset or machine.
For time-series data from the Internet of Things, see IBM's IoT overview. Measurements can also represent sensitive health records or security events; account for access controls, retention, and applicable safeguards, including the guidance in our articles on patient data safety and data security.
A practical decision checklist
- Start with the database your application already operates, often PostgreSQL, and store an explicit event timestamp.
- Record the queries you actually need: which time ranges, filters, aggregates, and freshness requirements?
- Add a matching index and measure query plans and storage growth before introducing partitions.
- Consider a time-series extension when automated time-based chunking, retention, or rollups solve a demonstrated operational problem.
- Use a monitoring system such as Prometheus for operational metrics, and avoid unbounded label values.
- Move analytical scans to a columnar store only when a representative evaluation justifies the extra infrastructure.
- Set retention and backup policies together, and test that the data you need can be restored.
There is no universally best time-series database. A modest schema, a clear event-time policy, bounded queries, and a deliberate retention plan are a reliable starting point; specialize as the actual workload grows.
Cover Photo by Lukas from Pexels