If you can break up the query into many components which can be executed separately, you can keep asking the server what is the progress.
For example, if you have to insert a lot of data into the db, instead of making one giant request to the db:
INSERT INTO table VALUES (..), (..), .. ;
you can break it into many insert statements:
INSERT INTO table VALUES (..);
...
INSERT INTO table VALUES (..);
Then at any stage you can always count the number of rows which can give you the percentage.
For example, you know that you are suppose to insert 20000 rows. Then using an ajax call to the server which will do this:
SELECT COUNT(*) FROM table
which will return a number up to 20000 you can calculate the percentage.
Another solution is to use websockets but this will require a lot of config.