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

dm8ry

Dmitry Romanoff

Posted on November 15, 2023

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

ask_dima@yahoo.com

💖 💪 🙅 🚩
dm8ry
Dmitry Romanoff

Posted on November 15, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related