PostgreSQL: Track ALL SQL Query Execution Statistics using pg_stat_statements Extension (Day 1/2)

Are you facing performance related issues in PostgreSQL?

Do you want to know all your SQL Query Execution Statistics like: How many times same query executed, What is total and average time for queries and others.

If you are looking for these questions, this post is very helpful for you.

PostgreSQL provides pg_stat_statements module or extension which automatically records different types of statistic all running queries.

During the activity of Performance Optimization, We are always keen for long running queries of our Database Server.

We should configure pg_stat_statements module so that we can easily use require statistics for Performance Tuning.

Steps to configure and enable pg_stat_statements module:

First, Install pg_stat_statements Extension:

Once we install the extension, It starts to log require query execution information in pg_stat_statements table.
Select the data of pg_stat_statements:

If you get a below error, require to change few parameters in postgresql.conf file:

You can solve above error by changing this parameter in postgresql.conf file.
After changes in postgresql.conf, restart PostgreSQL service.

Execute few sample queries to check, how pg_stat_statements works:

Check the tracked statistics in pg_stat_statements:

Using below function, You can also reset pg_stat_statements:


Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from dbrnd.com

Leave a Reply

Be the First to Comment!

Notify of
avatar

wpDiscuz