Check PostgreSQL INSERT in real-time

Chris Sun
1 min readJun 15, 2020
Photo by Xu Haiwei on Unsplash

I have to put old data from a big table to an archive table. And the query has run for a week, you will have no idea when is the end. I have tried to find a solution from the official website but failed. But find a solution for update from https://drone-ah.com/2011/11/02/tracking-progress-of-an-update-statement-1101/

The method also works for insert. This is the code to create an insert.

Then you can open another console, and query the track_insert sequence.

But before you do your work, you have to check the number of rows that will be inserted so that you can know the progress.

Remember to remove the sequence after your work.

drop sequence track_insert;

PS.: Never use IDE to run a long time query. I like to use screen command with python to submit a query to the database which will run in the background.

--

--