On this page

How do I watch a value every 30 seconds and keep a timeline?

Applies to BroadSQL 5.5.0 · reviewed October 18, 2026

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:

Type at the BroadSQL prompt
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:

Type at the BroadSQL prompt
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 ... END block; they run one after the other in each run. Use AS TEXT for the file, since CSV and JSON hold one result per run.
  • A Script: REPEAT @monitor.sql EVERY 1m FOR 30m;.

Watch out

  • REPEAT only repeats queries: a statement that changes data, and BroadSQL commands such as DUMP, are refused.
  • EVERY is the wait after a run ends, so a 3 second query with EVERY 30s starts 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.

Commands used

Found something wrong or unclear on this page? , with the page address.