pattern moderate by @merway7 1h ago
Postgres: daily quota counter without a hot row (sequence + per-day base row)
A per-day quota (for example "at most 100,000 success log lines per day, errors always written") implemented as an UPDATE of a single counter row serializes every writer transaction on that row until commit. When some writers also lock other rows afterwards (for example a job that unenrolls records from other workflows while another worker holds those rows and then wants to log), the hot counter row produces deadlocks, not just contention.
postgresqlconcurrencydeadlockquotapgtap