Monitor FOR loop progress in postgres I have a Postgres loop as follows, which I am running from the command line via psql:
DO
$do$
BEGIN 
   FOR i IN 1..20000
   -- update some rows
   LOOP
END LOOP;
END; 
$do$;

Is there any way to access the value of the counter i to track the progress of the loop? I've looked in the pgAdmin dashboard with no success.
By adding raise notice. It will keep printing value of i -- so that you will always have idea about loop progress.
    DO
    $do$
    BEGIN 
    FOR i IN 1..20000
    -- update some rows
    raise notice 'Current Progress Value i:%',i;
     LOOP
    END LOOP;
    END; 

Or more better way.

Create a sql file  : vi loop.sql  -- add your loop into this file with raise notice.

Run as a job: psql -U username -d database_name -a -f loop.sql &amp;&gt;progress_log

Keep monitoring latest id : tail progress_log


Note: One more tip- I think you need to initialize i - need to include a declare section. Like below:(sample)
    DO
    $do$
    DECLARE
    i int8;
    BEGIN
    -----your code--
    END;