Skip to content

replace remaining pg_cron TTL cleanups with Arbiter jobs - #5773

Open
blackheaven wants to merge 3 commits into
developfrom
gdifolco/postgres-drop-pg-cron-ttl
Open

blackheaven wants to merge 3 commits into
developfrom
gdifolco/postgres-drop-pg-cron-ttl

Conversation

@blackheaven

Copy link
Copy Markdown
Contributor

Expired oauth_auth_code and user_cookies rows were deleted by pg_cron jobs that the migrations 20261127110318-oauth-auth-code-ttl-cleanup.sql and 20261110121000-user-cookies-ttl-cleanup.sql scheduled only if the operator had installed pg_cron. Without pg_cron (the default for most installations) these tables grew without bound. pg_cron also needs shared_preload_libraries, superuser setup and a separate place to monitor it. Background-worker already runs Arbiter with recurring cron jobs, so this PR moves both cleanups there.

Changes

  • New Arbiter queue expirations with payload ExpirationsJobPayload (ExpireOAuthAuthCode, ExpireUserCookies). The queue, Wire.ExpirationsCleanupWorker and the worker-pool wiring in Workers.hs are kept identical to the activation-keys PR (WPB-22970), so merging the two only combines constructors.
  • Periodic jobs expire-oauth-auth-code (daily at 04:00 UTC) and expire-user-cookies (hourly at minute 5) keep the schedules of the pg_cron jobs they replace.
  • Batched DELETE ... LIMIT ... FOR UPDATE SKIP LOCKED statements in the Postgres stores: deleteExpiredOAuthAuthCodes and deleteExpiredCookies. Each batch is its own short transaction, and a run loops until a batch comes back short. On failure the job rethrows, so Arbiter retries it.
  • New migration 20261203120000-drop-pg-cron-ttl-cleanups.sql unschedules the old pg_cron jobs that the migrating role owns. Without pg_cron it does nothing. If unscheduling fails it only warns: a leftover job just repeats the same idempotent delete. The applied migrations are not edited.
  • postgres-schema.sql now includes the Arbiter expirations tables. Golden and roundtrip tests cover the new payload, and a unit test covers the batching loop. config-options.md and the changelog are updated.

Every read path already ignores expired rows, so the cleanup only reclaims space and has no effect on authentication behaviour.

@blackheaven
blackheaven requested review from a team as code owners December 3, 2026 18:46
Log and fail the Arbiter job with a short category (connection error,
session error with its SQLSTATE, pool acquisition timeout) instead of the
rendered hasql UsageError, which carries the host, port, user and database
name. The job is failed with throwRetryable so Arbiter still retries it.
@zebot zebot added the ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist label Dec 3, 2026
Move the pool usage error redaction (CleanupFailure, classifyUsageError,
renderCleanupFailure, cleanupFailedMessage) into Wire.UsageErrorRedaction
and use it where background-worker turned a UsageError into text: the
effect runner of adminless, background and meetings cleanup jobs no
longer embeds `show` of the error, and the meetings cleanup log no
longer shows the text again.

Extract runCleanupWith from runExpirationsCleanup and test that it logs
and throws only the redacted category, test the effect runner's mapping,
and make the redaction property assert that rendering ignores the
error's free-form text.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants