How to check the number of queries per second (QPS) on the PostgreSQL DB instance?

Dmitry Romanoff - Nov 15 '23 - - Dev Community

To check the number of queries per second (QPS) on the PostgreSQL DB instance run the following SQL query:

with
 t1 as (select sum(calls) n from pg_stat_statements),
 t2 as (select sum(calls) n from pg_stat_statements , pg_sleep(1))
select
 t2.n-t1.n the_num_of_queries_per_second
from
 t1,t2;
Enter fullscreen mode Exit fullscreen mode

Example:

postgres=> with
postgres->  t1 as (select sum(calls) n from pg_stat_statements),
postgres->  t2 as (select sum(calls) n from pg_stat_statements , pg_sleep(1))
postgres-> select
postgres->  t2.n-t1.n the_num_of_queries_per_second
postgres-> from
postgres->  t1,t2;
 the_num_of_queries_per_second 
-------------------------------
                          1234
(1 row)

postgres=> 
Enter fullscreen mode Exit fullscreen mode

ask_dima@yahoo.com

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player