Uh oh!
There was an error while loading. Please reload this page.
feat(db): attribute Postgres connections by runtime via application_name - #5211
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview Shared Reviewed by Cursor Bugbot for commit 5cd82ba. Bugbot is set up for automated code reviews on this repo. Configure here. |
Uh oh!
There was an error while loading. Please reload this page.
…DB_APP_NAME comment
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit b5c2995. Configure here.
Uh oh!
There was an error while loading. Please reload this page.
The realtime process uses both its own socketDb pool and the shared @sim/db client (handlers, preflight, permissions). Only socketDb was labeled, so the shared client defaulted to sim-app, mislabeling much of realtime's DB traffic. Set DB_APP_NAME=sim-realtime at the process level (bootstrap before the dynamic @/index import for prod; dev/start scripts for local) so both clients report it.
TheodoreSpeaks
commented
Jun 25, 2026
Addressed the Bugbot finding (realtime traffic mislabeled Root cause: the realtime process opens two Postgres clients — its own Fix: set
Now every connection the realtime process opens reports |

Summary
application_nameper runtime so DB activity is attributable:sim-app(Next.js),sim-trigger(trigger.dev workers),sim-realtime(socket server). Previously every connection reported thepostgres.jslibrary default, making it impossible to tell whether lock spikes / advisory-lock contention / statement timeouts come from a request-path query or a background task.packages/db/db.ts+apps/realtime/src/database/operations.ts: addconnection: { application_name }fromDB_APP_NAME(defaultssim-app/sim-realtime).apps/sim/trigger.config.ts: declareDB_APP_NAME=sim-triggerin code via thesyncEnvVarsbuild extension — the worker's separate deploy scope gets the label without a manual dashboard step or sniffing trigger internals (the obviousTRIGGER_*vars are present in the web app too).apps/sim/lib/core/config/env.ts: documentDB_APP_NAME.Validated against prod (
sim-studio-production):application_namepropagates through PlanetScale's pooler to the backend, and apg_locks ⋈ pg_stat_activityjoin attributes locks by app on the existingpg_read_all_datarole (nopg_monitorneeded). Finer-grained per-request/run comment tags, lock-victim logging, and a Grafana Alloy lock-by-app metric are deferred follow-ups.Type of Change
Testing
Tested manually.
bun run lint,bun run check:api-validation:strict, and the@sim/dbvitest suite (19/19) pass. Live verification post-deploy viaSELECT application_name, count(*) FROM pg_stat_activity GROUP BY 1.Checklist