Repository navigation
fix(db): give service_role a 120s statement timeout - #860
Merged
Merged
Conversation
service_role had no statement_timeout of its own, so over PostgREST it inherited authenticator's 8s. On the largest brand refresh_insights_ daily timed out every day, both in the nightly sweep and when the run stamped, so that brand's current day never reached the Insights rollups (30 Sep: 3,965 results, none rolled up). Pulse, signal and report work runs under the same cap. Background jobs now get two minutes; authenticated stays at 8s and anon at 3s. Applied to production, with the missing day rebuilt.
This was referenced Sep 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
service_rolehad nostatement_timeoutof its own, so requests made over PostgREST with the service-role key inheritedauthenticator's 8s. That is the same cap as a user's page load. Several code comments assume the service role runs without a timeout; that assumption was wrong.Impact found
refresh_insights_dailyreturned 500 (canceling statement due to statement timeout) every day, both in the nightly sweep at the start of the cycle and when the brand's run stamped.prompt_resultsand none ininsights_brand_daily, so the 7/30/90-day Insights views were missing the day.Change (migration
00100_service_role_statement_timeout)alter role service_role set statement_timeout = '120s'gives background work two minutes.authenticatedstays at 8s andanonat 3s.notify pgrst, 'reload config'so PostgREST picks up the per-role setting without a restart.Already applied to production.
pg_rolesshows the new setting. The missing day was rebuilt through the service role, and the rollup now matches the raw results for 30 Sep (3,965 answers). This PR brings the repo in line with the database.Related issue
None. Found while investigating a Topics detail page failure.
Type of change
How to test
select rolname, rolconfig from pg_roles where rolname in ('service_role', 'authenticated', 'anon');showsstatement_timeout=120sforservice_role, with the other two unchanged.refresh_insights_dailyno longer returns 500 for the largest brand, either in the 02:00 sweep or at the run's stamp.insights_brand_dailyholds the current day for that brand, matching the raw result count.Checklist
supabase/schema.sqlregenerated withbuild-schema.sh🤖 Generated with Claude Code