You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Additional tools for tracking the progress of the running query:* function progress_bar(pid), which returns a numeric from 0 to 1,characterizing the number of processed rows in relation to their planned number.* function progress_bar_visual(pid, delay), which displaysthis numeric with a delay of several seconds.Developers:Ekaterina SokolovaVyacheslav Makarov
Copy file name to clipboardExpand all lines: README.md
+114Lines changed: 114 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -308,3 +308,117 @@ Do not hesitate to post your issues, questions and new ideas at the [issues](htt
308
308
##Authors
309
309
[Maksim Milyutin](https://github.com/maksm90)
310
310
Alexey Kondratov <a.kondratov@postgrespro.ru> Postgres Professional Ltd., Russia
311
+
312
+
##Function progress\_bar
313
+
```plpgsql
314
+
progress_bar(
315
+
integer pid
316
+
) returns FLOAT
317
+
```
318
+
extracts the current query state from backend with specified 'pid'. Then gets the numerical values of the actual rows and total rows and count progress for the whole query tree. Function returns numeric value from 0 to 1 describing the measure of query fulfillment. If there is no information about current state of the query, or the impossibility of counting, the corresponding messages will be displayed.
319
+
320
+
##Function progress\_bar\_visual
321
+
```plpgsql
322
+
progress_bar(
323
+
integer pid,
324
+
integer delay
325
+
) returns VOID
326
+
```
327
+
cyclically extracts and print the current query state in numeric value from backend with specified 'pid' every period specified by 'delay' in seconds. This is the looping version of the progress\_bar function that returns void value.
328
+
329
+
**_Warning_**: Calling role have to be superuser or member of the role whose backend is being called. Otherwise function prints ERROR message`permission denied`.
330
+
331
+
##Examples
332
+
Assume first backend executes some function:
333
+
```sql
334
+
postgres=# insert into table_name select generate_series(1,10000000);
335
+
```
336
+
Other backend can get the follow output:
337
+
```sql
338
+
postgres=# SELECT pid FROM pg_stat_activity where query like 'insert%';
339
+
pid
340
+
-------
341
+
23877
342
+
(1 row)
343
+
344
+
postgres=# SELECT progress_bar(23877);
345
+
progress_bar
346
+
--------------
347
+
0.6087927
348
+
(1 row)
349
+
```
350
+
Or continuous version:
351
+
```sql
352
+
postgres=# SELECT progress_bar_visual(23877, 1);
353
+
Progress=0.043510
354
+
Progress=0.085242
355
+
Progress=0.124921
356
+
Progress=0.168168
357
+
Progress=0.213803
358
+
Progress=0.250362
359
+
Progress=0.292632
360
+
Progress=0.331454
361
+
Progress=0.367509
362
+
Progress=0.407450
363
+
Progress=0.448646
364
+
Progress=0.488171
365
+
Progress=0.530559
366
+
Progress=0.565558
367
+
Progress=0.608039
368
+
Progress=0.645778
369
+
Progress=0.654842
370
+
Progress=0.699006
371
+
Progress=0.735760
372
+
Progress=0.787641
373
+
Progress=0.832160
374
+
Progress=0.871077
375
+
Progress=0.911858
376
+
Progress=0.956362
377
+
Progress=0.995097
378
+
Progress=1.000000
379
+
progress_bar_visual
380
+
---------------------
381
+
1
382
+
(1 row)
383
+
```
384
+
Also uncountable queries exist. Assume first backend executes some function:
385
+
```sql
386
+
DELETEfrom table_name;
387
+
```
388
+
Other backend can get the follow output:
389
+
```sql
390
+
postgres=# SELECT pid FROM pg_stat_activity where query like 'delete%';
391
+
pid
392
+
-------
393
+
23877
394
+
(1 row)
395
+
396
+
postgres=# SELECT progress_bar(23877);
397
+
INFO: Counting Progress doesn't available
398
+
progress_bar
399
+
--------------
400
+
-1
401
+
(1 row)
402
+
403
+
postgres=# SELECT progress_bar_visual(23877, 5);
404
+
INFO: Counting Progress doesn't available
405
+
progress_bar_visual
406
+
---------------------
407
+
-1
408
+
(1 row)
409
+
```
410
+
411
+
##Reinstallation
412
+
If you already have a module 'pg_query_state' without progress bar functions installed, execute this in the module's directory:
413
+
```
414
+
make install USE_PGXS=1
415
+
```
416
+
It is essential to restart the PostgreSQL instance. After that, execute the following queries in psql:
417
+
```sql
418
+
DROP EXTENSION IF EXISTS pg_query_state;
419
+
CREATE EXTENSION pg_query_state;
420
+
```
421
+
422
+
##Authors
423
+
Ekaterina Sokolova <e.sokolova@postgrespro.ru> Postgres Professional Ltd., Russia
424
+
Vyacheslav Makarov <v.makarov@postgrespro.ru> Postgres Professional Ltd., Russia