Export customer data from PostgreSQL for the EU Data Act
Implement Chapter VI Regulation (EU) 2023/2854 tenant export and reverse-FK erasure in multi-tenant PostgreSQL without SQL injection or egress fees.
Key facts
| Regulation | Regulation (EU) 2023/2854 (Chapter VI) |
| Transition Period | 30 calendar days at most (Art. 25(2)(a)); up to 7 months if technically unfeasible and notified within 14 working days (Art. 25(4)); the customer may extend once (Art. 25(5)) |
| Output Formats | RFC 4180 CSV, NDJSON, SHA-256 manifest.json |
| Switching Charges | Cost-based only until January 12, 2027, none after, including switching-related egress (Art. 29) |
Options compared
| Approach | Tenant Isolation | FK Erasure Order | Manifest Checksums |
|---|---|---|---|
| Ad-hoc pg_dump | Manual WHERE filtering risk | Not scoped per tenant | None |
| Parameterized Tenant Queries | Strict $1 tenant_id binding | Reverse topological order | Per-file SHA-256 |
1. Enforce Parameterized Tenant Queries Across Every Table
Every exportable table in PostgreSQL must resolve back to a verified tenant isolation key such as organization_id or tenant_id. Never concatenate tenant identifiers into raw SQL strings.
Tables lacking a direct tenant_id column must join deterministically through their parent foreign key chain before writing rows to NDJSON or CSV.
export async function exportTenantTable(
client: { query: (sql: string, params: unknown[]) => Promise<{ rows: Record<string, unknown>[] }> },
table: string,
tenantColumn: string,
tenantId: string
): Promise<string> {
const result = await client.query(
`SELECT * FROM "${table}" WHERE "${tenantColumn}" = $1 ORDER BY 1`,
[tenantId]
);
return result.rows.map((row) => JSON.stringify(row)).join("\n");
}2. Execute Post-Retrieval Erasure in Reverse Foreign-Key Order
Article 25(2)(h) requires full erasure of exportable data and customer digital assets after the minimum 30-calendar-day retrieval window closes. Deleting parent rows before child rows triggers foreign-key constraint failures or leaves orphaned objects.
Always run a dry-run count first, delete child tables in reverse dependency order inside a transaction, and emit a structured row-count log for your Certificate of Erasure.
BEGIN;
DELETE FROM invoice_items WHERE invoice_id IN (SELECT id FROM invoices WHERE tenant_id = $1);
DELETE FROM invoices WHERE tenant_id = $1;
DELETE FROM projects WHERE tenant_id = $1;
COMMIT;Close the gaps
The kit gives you the public Art. 26 and Art. 28 pages, code to export a customer's data, and a tracker for switching deadlines.