Sobes.tech
Senior

How long have data been stored in PostgreSQL/TimescaleDB? What happened to the old data?

sobes.tech AI

Answer from AI

In PostgreSQL/TimescaleDB, data is usually stored for the period necessary for business analytics and compliance requirements.

In TimescaleDB, automatic deletion policies (retention policies) are often used for old data to prevent overload:

  • They configure continuous aggregates for aggregating old data.
  • They set a drop_chunks policy that deletes data older than a certain period (e.g., 1 year).

Example of setting a retention policy in TimescaleDB:

SELECT add_retention_policy('metrics_table', INTERVAL '1 year');

If the data is important for long-term storage, it can be archived to a separate storage (e.g., S3) and deleted from the database.

In projects with PostgreSQL without TimescaleDB, custom scripts or cron jobs are usually implemented to delete or archive old data.

Thus, with old data, they either aggregate, archive, or delete it to maintain performance and database size.

How long have data been stored in… - sobes.tech