On this page
How do I watch a value every 30 seconds and keep a timeline?
What you'll accomplish
During an incident or a long job, you need to see a value move: rows waiting in a queue, jobs still running, a count that should reach zero. Running the same query by hand every few seconds ties you to the keyboard, and you keep no trace of how the value changed.
You will run a query once, then have BroadSQL run it again at a fixed interval, each run marked with its number and time. You will also write every run to a CSV file, so you end up with a timeline you can open in a spreadsheet.
Short answer
Run the query once, then REPEAT EVERY 30s;. It runs the last query again 30 seconds after each run ends, until Ctrl+C. Add TO <file> AS CSV to append every run to a file.
Example
Connected to WORLD, count the cities, then repeat that query every 30 seconds, three times:
SELECT COUNT(*) AS CITIES FROM CITY;
REPEAT EVERY 30s COUNT 3;Each run starts with a line such as === Repeat #2 at 2026-10-18 10:40:13 ===, then the result as usual. On WORLD the count stays at 4081, since nothing changes the sample while you watch; on your own databases, watch a queue table or the rows of a running job the same way. Without COUNT, it runs until you press Ctrl+C, and you stay connected.
Keep a timeline in a file
A block of queries between BEGIN and END runs at each repetition. This one records the number of countries per continent every 30 seconds, for five minutes, in a CSV file of the export folder:
REPEAT
BEGIN
SELECT TRIM(CONTINENT) AS CONTINENT, COUNT(*) AS COUNTRIES FROM COUNTRY GROUP BY CONTINENT;
END
EVERY 30s
FOR 5m
TO world-monitor.csv AS CSV;Every run is appended to world-monitor.csv, with a first column TIMESTAMP, the time the run started. Nothing already in the file is overwritten, so after five minutes the file holds about ten blocks of seven rows: a timeline you can open in a spreadsheet or load into a chart.
Variations
- A fixed number of runs:
REPEAT EVERY 10s COUNT 6;. - Several queries together: put them in one
BEGIN ... ENDblock; they run one after the other in each run. UseAS TEXTfor the file, sinceCSVandJSONhold one result per run. - A Script:
REPEAT @monitor.sql EVERY 1m FOR 30m;.
Watch out
REPEATonly repeats queries: a statement that changes data, and BroadSQL commands such asDUMP, are refused.EVERYis the wait after a run ends, so a 3 second query withEVERY 30sstarts about every 33 seconds.- It runs in the foreground and keeps the prompt until it ends. It does not stop by itself when a value changes: watch the screen or the file.
- The first error ends it.
Clean up
Delete world-monitor.csv from the export folder when you no longer need it.
Related
Commands used
Found something wrong or unclear on this page? Tell us, with the page address.