Cap query load with a traffic budget

postgres roles & traffic

// what it does

Database Traffic Control lets you define budgets that cap how much capacity a class of queries may consume on a Postgres branch — a brake pedal for the analytics job or batch import that keeps starving your app. Start in the default warn mode to observe, then flip to enforce.

// shell

$ pscale traffic-control budget create mydb main --name batch-jobs --capacity 2000 --rate 20 --mode warn
$ pscale traffic-control budget update mydb main <budget-id> --mode enforce

// gotcha

Going straight to --mode enforce on production without a warn-mode observation period is how you throttle your own app at peak traffic. Watch the warnings first, then enforce.