I found a good answer here: Tracking update instruction execution
The trick is to first create a sequence (name it whatever you want):
CREATE SEQUENCE query_progress START 1;
Then add the WHERE part to your query:
AND NEXTVAL('query_progress')!=0
Now you can request progress:
SELECT NEXTVAL('query_progress');
Finally, be sure to get rid of the sequence:
DROP SEQUENCE query_progress;
Note that this is likely to make your request run even slower, and each time you check the progress, it will increment the value further. The link above suggests creating a time sequence, but PostgreSQL does not seem to make them visible in the sessions.
source share