Data retention
| Also called | Storage limitation (GDPR) |
|---|---|
| Legal source | GDPR Article 5(1)(e); erasure on request in Article 17; telling people the period in Article 13(2)(a) |
| End of a period | Deletion, or anonymisation |
| Affects | Database tables, uploaded files, logs, backups, and copies held by other companies |
Data retention is the set of rules an application follows for how long it keeps each kind of record and what happens to the record when that time is up. For personal data under the GDPR the rule is called storage limitation: data that can identify a person may stay in that form only as long as the purpose it was collected for still needs it.1 After that the data is deleted, or changed so that nobody can be identified from it.2
Choosing a period
The regulation names no periods. It leaves the length to the controller, the organisation that decides why the data is used, which must be able to show that each period is justified.12 Recital 39 asks the controller to set time limits for deletion or for a periodic review,3 and Article 13 requires the period, or the criteria used to set it, to be given to people at the moment their data is collected.4
A period lasts as long as a purpose still applies. A shop can keep some details of a former customer so that it can answer a complaint, and keeps enough about someone who opted out of marketing to leave them off later mailings. Tax and audit laws require some records to be kept, and data kept to meet such a rule is not kept too long. Holding records indefinitely on the chance that they turn out useful is not a purpose.2 Archiving in the public interest, research and statistics are the exception: with safeguards, such data may be stored longer.1
A person can also ask for erasure before the period ends. The controller then has to erase the data without undue delay where it is no longer needed, consent has been withdrawn or the processing was unlawful, unless the data is still required by a legal obligation or for a legal claim.5 The wider obligations are in GDPR for application builders.
Retention schedules
The periods are written down in a retention schedule, a list of the kinds of record an organisation holds, what each is used for and how long it is kept.2 In an application the entries are its tables, storage buckets and log streams: sign-ups, orders, support messages, uploaded files, request logs. A small organisation with occasional low-risk processing may manage without a written policy, but it still has to review what it holds and remove what it no longer needs.2
Old records go out of date and get used by mistake. They also cost money to store and secure, and each one has to be found and handed over when its subject makes an access request.2
Deletion and anonymisation
At the end of a period a record is deleted or anonymised, meaning it no longer identifies anyone. Pseudonymised data, in which a name is swapped for a code that can be linked back, usually still identifies people, and the time limit applies to it unchanged.2
Dropping the name column is often not enough. In October 2018 the Danish data protection authority found that Taxa 4x35, a Copenhagen taxi company with a booking app, had kept the records of nearly 9 million rides for five years. The company removed customer names after two years and treated what remained as anonymous. Each trip still carried the customer's phone number, so pick-up and drop-off addresses could be tied to a person until the full record went at five years.6 The company gave business development as the reason for keeping the rides for five years. It faced a fine of 1.2 million kroner, about 160,000 euros.6
Copies
A row deleted from the live database still exists in every copy of it. Data removed from a live system is expected to be removed from that system's backups as well, which covers a Backup and restore file and a Point-in-time recovery archive. Data moved offline is still being processed: it must still be produced for access requests and still falls under the other rules.2 Logs and Audit logs that hold personal data need periods of their own; Personal data in logs covers what should never be written to them.
In Amazon S3, a lifecycle rule with an Expiration action removes objects of a set age from a bucket. In a bucket without versioning, S3 queues the object and deletes it permanently in the background. In a versioned bucket the same rule deletes nothing: it adds a delete marker, the old object becomes a noncurrent version, and noncurrent versions stay until a NoncurrentVersionExpiration rule deletes them a chosen number of days after they stopped being current.7
Data passed to another company needs an agreement on what happens to it afterwards: either the copy is returned, or every party deletes its own.2
Scheduled deletion in Postgres
Jobs that flag or delete records after a fixed period suit data held as many records of the same type.2 Supabase runs the pg_cron extension as Supabase Cron, where such a job is one SQL statement on a cron job schedule. The example below runs every Saturday at 03:30 GMT:8
select cron.schedule(
'saturday-cleanup',
'30 3 * * 6',
$$ delete from events where event_time < now() - interval '1 week' $$
);The scheduler keeps a history of its own. Every run adds a row to cron.job_run_details, and nothing clears that table, even after the job is removed, so it needs a cleanup job too.8
On a very large table a bulk DELETE is slow and leaves dead rows for VACUUM, the Postgres cleanup process, to clear. A table split into partitions, one child table per month, can drop its oldest partition instead, which removes millions of rows without deleting them one at a time. DROP TABLE on a partition takes an ACCESS EXCLUSIVE lock on the parent table; DETACH PARTITION ... CONCURRENTLY takes only a SHARE UPDATE EXCLUSIVE lock and leaves the old partition as a separate table to drop afterwards. Partitioning tends to pay off once a table is larger than the database server's physical memory.9
Prompt for a coding agent
List every place in this project that stores personal data: database tables and columns, storage buckets, log output, analytics events, backups and third-party services we send data to. For each, say what the data is used for, how long it is kept now and what deletes it, if anything. Then propose a retention period for each and write the scheduled jobs, lifecycle rules or log settings that delete or anonymise the data when the period ends. Do not delete anything yet; show me the list and the changes first.
See also
- GDPR for application builders
- Personal data in logs
- Backup and restore
- Point-in-time recovery
- Audit logs
- Security logging and alerting
- Breach notification
- Category: Data exposure
References
- a b c "Art. 5 GDPR: Principles relating to processing of personal data". gdpr-info.eu (text of Regulation (EU) 2016/679).
- a b c d e f g h i j Information Commissioner's Office. "Principle (e): Storage limitation". ico.org.uk. Retrieved 22 November 2026.
- back "Recital 39: Principles of data processing". gdpr-info.eu (text of Regulation (EU) 2016/679).
- back "Art. 13 GDPR: Information to be provided where personal data are collected from the data subject". gdpr-info.eu (text of Regulation (EU) 2016/679).
- back "Art. 17 GDPR: Right to erasure ('right to be forgotten')". gdpr-info.eu (text of Regulation (EU) 2016/679).
- a b GDPR.eu (2019). "Data anonymization and GDPR compliance: the case of Taxa 4x35". GDPR.eu.
- back Amazon Web Services. "Expiring objects". Amazon S3 User Guide.
- a b Supabase (2026). "Cron Quickstart". Supabase Docs.
- back PostgreSQL Global Development Group. "Table Partitioning". PostgreSQL documentation.