Scheduling Estimates Computations
Understand how to schedule estimates computations in PostgreSQL.
We'll cover the following...
To calculate unique visitor estimates from the heavy insert table, we need a background process to do this from time to time.
The easiest way to do that here would be to create a new API endpoint on our back-end server and set up a cron-like utility to use that endpoint for our specified schedule. In case of emergency, though, it’s nice to be able to run this updating process interactively. A solution to have both the back-end API integration and the interactive approaches available consist of packaging our SQL query as a stored procedure.
SQL function
While stored procedures aren’t covered, it’s easy enough to write a SQL function around the statement we have already:
And here’s an interactive session where we use the newly defined stored procedure to update our unique visitors hll table. ...