Delete in chunks to avoid huge transactions.
Section: High-value Query Performance Patterns
Batch deletes
sql
sql
DELETE FROM audit_log
WHERE ctid IN (
SELECT ctid FROM audit_log WHERE created_at < now() - interval '180 days' LIMIT 10000
);Explanation
See summary for usage details.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing High-value Query Performance Patterns
Batch updates
Chunk large writes into batches to reduce contention and WAL spikes.
Keyset pagination
Prefer keyset pagination over deep OFFSET scans for large result sets.
Select needed columns
Avoid fetching unnecessary columns, especially wide rows.
Covering index with INCLUDE
Use included columns to support index-only reads for certain queries.
Create range-partitioned table
Partition large time-series tables by range.