DEV Community

Dmitry Romanoff
Dmitry Romanoff

Posted on

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

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

Top comments (0)