Skip to content

Implement pg-boss completed jobs cleanup to prevent table bloat #2739

Description

@ygrishajev

Problem

The pgboss.job table in the notifications service grows unbounded with completed jobs. In production we observed ~791K rows (440K created, 350K completed), causing:

  1. 24MB temp files on every poll query — the pg-boss work query (SELECT ... FOR UPDATE SKIP LOCKED) cannot sort in memory, creating ~24MB temp files every ~250ms
  2. Connection drops — excessive I/O from the bloated table causes Broken pipe / connection to client lost errors
  3. Container restart loops — connection loss triggers pg-boss stopped event, health check fails, orchestrator kills container, backlog grows

The maintenance cycle that should clean up completed jobs never completes because pg-boss keeps crashing and restarting before it runs.

Action needed

Implement proper cleanup of completed jobs from the pgboss.job table.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions