Keeping the Audit Log Tidy¶
pgrelay.log grows over time, since every processed event adds a row. Purge old records periodically to keep it a manageable size:
-- Keep only the last 7 days:
SELECT pgrelay.purge(p_hours := 168);
-- Keep only the most recent 100,000 records:
SELECT pgrelay.purge(p_keep_quantity := 100000);
-- Remove processed rows from the event queue (keeps pending rows):
SELECT pgrelay.purge_queue();
You can schedule these calls with pg_cron (a PostgreSQL extension for running SQL on a schedule), or use pg_relay's own deferred-event feature to have it schedule its own daily purge. See Purging Historical Data in the Technical Guide for a full self-scheduling example.
For a complete, realistic walkthrough that builds on everything covered so far, see the Worked Example book. Otherwise, continue to Where to Go Next.