Purging deleted datasets from CKAN

Deleted CKAN datasets stay in the database until they are purged, so cleanup is a separate decision with its own risks. This page covers when to purge, the purge options and effects on harvest sources and the search index, and how to keep an audit record.

On this page

Purging deleted datasets from CKAN: what it removes and when to do it

Purging permanently removes a deleted dataset from the CKAN database. Deleting alone is not the end of the record. In CKAN's standard behavior, a deleted dataset is marked as deleted, so it drops out of normal search and dataset pages while its metadata, resources and links stay stored. Teams need a purge when the record itself must stop existing, for example when a data protection obligation or a legal instruction requires removal. Until a purge runs, a sysadmin can still see and restore the dataset. Confirm the exact behavior of deleted and purged datasets in the release your portal runs before you write a procedure around it.

The usual triggers are withdrawn publications, duplicate entries, personal data removal requests and harvest clean-up. A publication withdrawn for legal or policy reasons often needs its record gone, not only hidden from users. Duplicates from a bad import or a repeated harvest are easiest to handle once the surviving record is confirmed. Removal requests that touch personal data in descriptions or resource fields need a documented decision from the data owner and the privacy lead. Harvest clean-up needs its own check, because a harvester may delete datasets that were removed upstream, and purging them can break links from other records that still point to them. Confirm whether a purge also reaches uploaded files and existing backups, since your backup copies sit outside the portal.

Start by identifying the CKAN version from the portal's package or container tag, then read the release notes for that line. The CKAN releases policy explains which minor and patch lines receive fixes, which matters if the portal runs an older patch. Next, restore a recent backup into a staging environment and test the purge there, recording the dataset identifier, the request and the approver so the action can be traced later. Check which extensions hook into dataset deletion, such as harvest sources or activity streams, and whether the search index needs a follow-up step. Confirm the command and its effects against the documentation for your release before running it in production.

How a deleted dataset moves toward a purge

This diagram follows a dataset from its active state to its deleted state, then through a review of harvest sources, linked resources and API consumers, and finally to an audit record with a verified backup. Only after a purge decision does work cross the trust boundary into the admin shell and database access. Inside that boundary, the purge command runs, and then the search index, harvest sources and API are checked. Confirm the command syntax for your running CKAN version before any purge.

Purge path from deleted dataset to post-purge checks.

Purge scope options and what each one fits

This table compares four ways to handle deleted datasets, ordered from the most reversible to the least. Read each row by asking what the action removes and whether it can be undone. The main takeaway is that a purge is permanent, so a narrow scope with a saved record fits most portals. The options your CKAN version and command help offer may differ, so confirm them before you run anything.

OptionWhat it removesWhen it fitsTrade-off
Leave in deleted stateNothing. The dataset stays in the database with its deleted status.Owners are still reviewing, or you are not yet sure the record is no longer needed.Reversible, but deleted records remain in the database until purged.
Purge one dataset after reviewThe single dataset and its stored metadata, removed from the database.One record has been checked, its owner has confirmed it is no longer needed, and a copy is saved.Permanent. Confirm whether linked resources and search index entries are removed too.
Purge a batch by organization or harvest sourceAll deleted datasets matching the filter, if the command supports that filter.A harvest source or organization was retired and its deleted datasets are confirmed as a group.Largest blast radius. Check whether the command offers a preview before running it.
Purge after saving an exported recordThe same datasets as the chosen single or batch purge, after the export is stored elsewhere.Audit or retention rules require a copy of the metadata before removal.Adds an export step and storage to secure. Exports may contain personal data, so apply your retention rules.

When to purge and when to keep datasets deleted

Purge a deleted dataset only when keeping it causes a specific harm that deletion cannot fix. The clearest case is personal data that must leave the portal, such as a named contact or a personal email address published in a dataset description or a resource file. A deleted dataset keeps its record in the database, so the data remains there until the purge runs. A second case is duplicates: a dataset republished under a new name can confuse users and split downloads across two records. A third case is a harvest source that will recreate the same records on its next run. If you delete those datasets without purging them, the harvester may restore them or create conflicting copies, so agree with the source owner who controls the cleanup before you act.

Keep a deleted record when you may still need it. Restoring a dataset is only possible while its record exists, so a dataset a publisher may ask back should stay in place until that question is closed. Keep records tied to an open investigation, a complaint, a takedown request or a pending data subject request, because purging them can destroy evidence or leave a request half answered. Keep harvest-created records while the source is under review, since their history shows what was removed and when. Ask your legal and records owners how long each hold should last, and do not set a purge date until those holds have an end point that someone has signed off.

Treat every purge as irreversible unless a tested backup exists. A backup that has never been restored in a test environment gives little assurance, so confirm that the database rows, uploaded files and search index all return to the expected state. Before the first purge, write one rule for each case described above: who approves it, what evidence is recorded, which harvest sources and search index checks run afterward, and how the decision is kept for audit. Have a sysadmin and a privacy or records owner sign the document, store it with the portal runbook, and apply it the same way every time so that each later purge can be checked against it.

Steps for purging deleted datasets from CKAN safely

This sequence moves deleted CKAN datasets to permanent removal while keeping a record of what was removed, who approved it and how to recover if something goes wrong. Each step produces an artifact the next step depends on, from the agreed list to the audit file, verified backups, a staging rehearsal and post-purge checks. Confirm the purge command and its behavior for your CKAN version in the official documentation before you start.

  1. Inventory deleted datasets and their owners

    Run a read-only query against the CKAN database to list every dataset in the deleted state, with its organization, owner contact, harvest source (if any) and deletion date. Ask each owning organization to confirm in writing which datasets must be kept for legal, contractual or research reasons and which can be purged. The step is done when you hold one agreed list of dataset IDs, approved by the data owner who will sign off the purge. Check: the number of IDs on the approved list matches the query output, with any exclusions documented.

  2. Confirm harvest source behavior

    Identify every harvest source that could have produced the datasets on the list, and check how each one treats datasets it no longer finds at the remote catalog. A source that re-creates a deleted dataset on its next run will undo the purge, so the source owner must remove the upstream record, exclude the identifier or accept that the dataset returns. Record the decision for each source in the change ticket. Check: every source on the list has a named owner and a written decision before the maintenance window is scheduled.

  3. Save and verify the audit record

    Export the metadata of every dataset on the approved list to write-once storage controlled by the operations team. Include the dataset ID, name, title, organization, deletion date, requester, approver and ticket reference. Generate a checksum for the export file and keep a second copy outside the portal host. The step is done when someone who did not create the file can open it, read the entry for one sample dataset and confirm the checksum matches. This record must outlive the datasets it describes.

  4. Back up and verify all three stores

    Take a fresh backup of the main PostgreSQL database, the DataStore database and the FileStore directory, along with the CKAN configuration files, all taken before the purge begins. Store the copies where the purge operator cannot overwrite them. Verify the backups by restoring them on a separate host and confirming the restored portal still shows the deleted datasets. A backup that has not been restored has not been verified, so schedule the restore test before the rehearsal. Check: the restore test log records the restored dataset count and any errors.

  5. Rehearse the purge on staging

    Restore the production backups into a staging environment that runs the same CKAN version and the same extensions, then run the purge against the approved list exactly as you plan to run it in production. Confirm that each purged dataset loses its metadata, its DataStore tables and its uploaded resource files, and note any leftover records, orphaned files or extension errors. Update the runbook with each finding before production. The rehearsal is complete when you have a log containing the command used, its full output and an explicit go or no-go decision.

  6. Run the purge in a maintenance window

    Announce the maintenance window to the owning organizations, pause harvest jobs and background work that touch the listed datasets, and block edits to them for the duration. Run the purge only for dataset IDs on the approved list, using the purge command documented for your CKAN version, and capture the full output in the ticket. The step is done when the number of datasets reported as purged matches the approved list and the export from the audit step, and no dataset outside the list has changed. Resume paused jobs only after that check passes.

  7. Check the search index

    Search the portal for the titles of purged datasets and confirm that none of them return in results. Then compare the dataset total shown on the search page with the active dataset count from the database. Look for index entries that point to removed datasets, and if the counts disagree, plan a Solr index rebuild using the guidance for your CKAN version. The step is done when the purged datasets are absent from search and the totals agree. Record the queries you ran and their results in the ticket.

  8. Verify harvest sources and API

    Run a harvest for each source on the list and confirm that none of them re-creates a purged dataset. Then request one purged dataset ID through the package_show action of the CKAN API and confirm that it returns a not found response. Run a package_search request through the API and check that its total matches the portal count from the previous step. The step is done when each source has a recorded run result, the API responses are saved to the ticket, and the change is closed with the audit record linked.

Keeping an audit record before datasets are purged

Write the audit record before the purge runs, so that every purged dataset has an entry even if the run stops partway. Each entry should capture the dataset ID and title, the organization that owned the dataset, the reason for the purge, the name of the person who approved it, the date, the reference to the backup taken beforehand, and the operator who ran the command. The backup reference matters most, because it is the only route back if someone later needs the content. Confirm that the reference points to a backup you have verified with the restore steps in your backup and restore runbook. Keep one row per dataset, and log the run as a batch with start and finish times so a partial run can be traced.

Store the record outside the CKAN database and outside the host that runs the purge. Rows deleted from the portal are gone, so a record kept in the same database cannot show what was removed. A shared, append-only location managed by your records or compliance team is a sound choice. That team should set the access rules and the retention period in writing. The length of retention depends on your legal and records obligations, so ask those owners for it instead of assuming a period. Limit read access to people who handle audits and to sysadmins who need it for restores, and log who opens the file. The backup usually holds the full dataset content, so the record and the backup should share the same retention end date.

Treat the record itself as sensitive. Dataset titles, organization names and free-text reasons can reveal unpublished work, a complaint or a person. Keep the reason to a short category plus an internal ticket reference, and leave narrative out. The record should also avoid the personal data the purge is meant to remove. If the purge responds to a deletion request, do not copy a user's name, email address or contact details into the log. Check the maintainer, author and author_email fields of each purged dataset before you save the record, because those fields often carry personal contact details. The dataset ID is usually enough to find the entry later. Ask your privacy lead to confirm whether the dataset ID and title count as personal data in your context.

Access, approvals and sensitive data around a purge

A purge removes records that cannot be undone from within the portal, so it needs tighter control than editing a dataset. The five controls below cover who can run it, who approves it, what happens to personal data that survives in backups and logs, and how the change is rehearsed first. Write each one into the portal team's runbook before the first purge.

Limit who can run purges

Purge rights should sit with a small group of named sysadmins, kept apart from the editors and organization admins who manage datasets every day. Shell and database access for the purge should follow the same rule, so a routine editing session cannot reach the command. Review the membership on a set schedule and remove accounts when people change roles. Confirm with your CKAN version which account types can run the purge command.

Approve every purge first

Treat each purge as a change with a written request that lists the dataset identifiers, the reason for removal and the owning organization. A second person who did not prepare the request should approve it, and the approval should be filed with the request before anyone runs the command. Re-check the list on the day of the run, because a dataset may have been restored, moved to another organization or linked to a harvest source since the request was written.

Handle personal data in backups

A purge removes the dataset from the live database, but copies of its metadata and uploaded files can remain in existing backups and exports. Agree with your privacy lead how long those copies are kept, who can restore them and how the timing of removal will be explained to affected people. Before any restore, check whether it would bring a purged record back into the live portal. Store dumps encrypted, and confirm how your backup tooling handles deletion before you promise anyone a removal date.

Log the command and output

Record who ran the purge, when, from which host, the exact command, the dataset identifiers passed to it and the full output, including errors. Write the log to a store that portal administrators cannot edit, such as a central syslog server or a write-once bucket you control. Link each entry to the approved request so an auditor can follow the path from approval to execution. Check that the log does not repeat the personal details the purge was meant to remove.

Rehearse the purge in staging

Run every purge first in a staging environment that mirrors production: the same CKAN and extension versions, a recent copy of the main and DataStore databases, the same search index configuration and comparable harvest sources. Check the result in the search index, the API, the harvest sources that point at the dataset and the organization pages. Time the job and test the restore path from backup, since a purge cannot be reversed from within the portal. Copy production data to staging only under the same access controls.

What purging deleted datasets from CKAN costs and needs from your team

What factors make purging deleted datasets from CKAN more or less effort?

Five factors drive the effort most: portal size, the number of deleted datasets in scope, how many harvest sources feed the portal, which extensions are installed, and how heavily the portal uses the DataStore and FileStore. A small portal with a few deleted datasets and no harvesting is a short exercise. A large portal with years of deleted records, several harvesters and custom extensions needs more analysis, because each extension may hold its own tables or references to datasets that must be checked before removal. DataStore tables and FileStore uploads sit outside the main catalog record, so their cleanup needs its own plan. The effort also grows with the number of owners who must review the candidate list. Ask any partner to explain how they will identify deleted datasets and their linked resources in your environment before they quote.

Can our in-house team purge deleted datasets from CKAN without a partner?

Yes, a team with CKAN administration skills can purge deleted datasets in-house. The task needs database access, a tested backup, a clear list of what to remove, and someone who understands how harvest sources and the search index respond to the change. Teams often bring in a partner when the portal runs several extensions, when harvest sources are tied to the deletions, or when the team lacks time to write a review process and a record of what was removed. A purge is hard to undo, so the person running it should have restore experience. If your team does the work, write the steps and the approval record before anyone runs a command. DeployOpen plans, implements, documents and supports self-hosted open-source platforms in your own infrastructure, so a partner can carry the work from planning through documentation, or support your team on specific steps.

What does a CKAN dataset purge need from our team before work starts?

Plan on providing access, a current backup, and named owners who can approve the list. Access means an administrator account for the portal, read access to the database servers, the DataStore and the file storage, and any staging environment used for rehearsal. The backup must be complete and tested before the purge. It should cover the main database, the DataStore database, FileStore and configuration, and it should be stored where the purge cannot touch it. Owners need to confirm which deleted datasets are unwanted, because a deleted record may still be referenced by a harvest source, a link from another site or a citation. Name someone who can decide edge cases while the work is underway. Confirm these inputs before the timeline is agreed, since missing inputs usually add time.

How long does purging deleted datasets from CKAN usually take?

Duration depends on scope, so no single figure applies to every portal. The main variables are the number of deleted datasets, the number of extensions and harvest sources that must be checked, the size of the DataStore and FileStore footprint, and how quickly owners can review the list. A tightly bounded purge on a small portal with a clear approval path is a short engagement. A purge that includes harvest source reconciliation, search index checks, a staging rehearsal and a written record for audit takes longer, because each step has its own review. Ask for a schedule in the written scope with milestones and the dependencies on your team, such as access grants and approvals. A timeline in a quote should state its assumptions, so you can see what would move it.

What does a quote for a CKAN dataset purge depend on?

A quote follows from a written scope agreed before work starts. DeployOpen does not publish a price list. The scope should list the portal and its environment, the datasets or categories in the purge, the extensions and harvest sources to check, whether DataStore and FileStore cleanup is included, the staging rehearsal, the audit record and the deliverables. The main cost components are the analysis of the portal, the preparation and rehearsal, the execution in your environment, the documentation and any retest. The purge itself is one-time work. Ongoing support, upgrades or continuous testing are separate retainers. When you request a quote, ask which items are fixed, which depend on your team's response times, and what changes the price if the list of deleted datasets grows.

Can a purged CKAN dataset be restored after it is removed?

Plan on recovery only from a backup taken before the purge. Confirm that the backup restores into a test environment and that it includes the DataStore and FileStore, since the main database alone may not bring back every part of a dataset. Treat the purge as permanent for the live portal. Keep a record of what was removed, who approved it and when, so an auditor or a steward can trace the decision even though the content is gone. Ask for the restore steps and the record format in the written scope.

What to confirm before purging deleted datasets from CKAN in your portal

Each card lists one item to confirm in your own environment before a purge runs. Together they cover the CKAN release you run, the extensions and harvest sources that may refer back to a purged dataset, the storage outside the main database, and the restore path if the purge was wrong.

Purge command in your release line

Purge behavior depends on the CKAN release you run. Confirm the purge command and its options in the exact version installed on your portal. CKAN supports the latest patch of the current minor version and the previous minor version, and older patch releases lose support once a newer patch is out. Check your installed version against the release policy, save the command's help output with your change record, and run the purge first on a staging copy of your portal.

CKAN release policy

Extensions that keep references

Extensions can store their own records that point to a dataset ID, such as followers, activity entries, or custom tables. Confirm which enabled extensions keep references to datasets and what each one does when the dataset is gone. Start from the plugins listed in your ckan.plugins setting. A purge that completes in core CKAN can still leave orphaned rows, broken links, or errors on pages that request the old ID. Test a sample purge in staging and check each of those pages.

Harvest sources after a purge

A harvest source can bring back a dataset you purged if the remote catalog still lists it. Confirm how each harvest source handles a dataset you purged before its next scheduled run. Check whether the source creates or updates records, whether remote deletions carry over, and whether a purged local ID is matched again on import. Run one harvest job in staging after a test purge, compare the result with the catalog you intended, and record the outcome for each source.

DataStore tables and FileStore

A purge can leave data in places outside the dataset record. The DataStore keeps structured resource data in a separate PostgreSQL database, and FileStore holds uploaded files. Confirm whether each purged dataset's DataStore tables and uploaded files are removed, left in place, or need a separate cleanup step in your version. After a test purge, check both locations and confirm that the read-only DataStore user can no longer query the removed tables.

DataStore docs

A tested restore path

A purge is hard to reverse, so confirm that a restore works before you run one on production. Take a full backup that covers the main database, the DataStore database, FileStore, and configuration, then restore it into a separate environment. Confirm that the restored portal loads, the purged dataset returns, and the rest of the catalog is intact. Keep the backup protected, because dumps can contain user data.

Custom extensions and purged records

Custom extensions, scheduled jobs, reports, and integrations written against the CKAN API or database may assume a dataset record exists. Confirm which of your own code paths read deleted or purged datasets, including exports, dashboards, identifier services, and background jobs. Review each path for errors when a record is missing and add handling where needed. Run your test suite and a sample purge in staging, and assign an owner to each custom component.

How DeployOpen scopes and delivers CKAN purge work

DeployOpen treats purging deleted datasets from CKAN as a planned change to a production portal. We agree the scope in writing, build and test the purge in a non-production copy, and hand over the procedure and records your governance team can review. All work runs inside infrastructure you control, such as your cloud accounts, data centers or air-gapped networks.

How we scope

  • The written scope names which deleted datasets, organizations and harvest sources are in the purge.
  • Scope also covers the search index, the database backup taken beforehand and the audit record kept.
  • Engagements are fixed-scope, so deliverables and timelines are agreed in writing before work starts.

How we build

  • We map the purge steps against your CKAN version, deployment and extensions before changing anything.
  • We rehearse the purge on a portal copy and check dataset pages, search results and harvest sources afterward.
  • Production runs follow a written change record, with a verified backup taken first.

How we hand over

  • You receive the purge procedure, the commands used and the steps to confirm each result.
  • The audit record keeps what was purged, when, by whom and under which approval.
  • Your team gets a runbook for future purges, written so your own staff can repeat it.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers.
  • A retainer can be scoped to repeat purges after CKAN upgrades and to review harvest source changes.
  • Ask for the retainer terms in writing, including what is included and how changes are priced.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.