TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial…

Member-only story

How to track statistics on all queries in your Postgres database to prevent slow queries or bottlenecks

Mike Huls
TDS Archive
Published in
5 min readDec 1, 2021

--

This extension is like al life vest; you never hope you need it but it can be very helpful in tough situations (image by Karsten Winnegaert on Unsplash)

Have you ever wondered why some parts of your application are suddenly very slow? Can it be your database? How would you find out? Wouldn’t it be nice to have an extensions that tracks statistics over all queries that it executes so that you can analyze your database performance and clear up bottlenecks?

In this article we’ll look at a Postgres extension called pg_stat_statements. It keeps statistics on all queries that your database executes and thusly offers crucial information on the performance of your database. With it, you can easily track the performance of your database, detect slow queries, eliminate bottlenecks and prevent problems from happening.

We’ll first go through the very simple installation. Then we demo how to use it. Let’s code!

What does this extension do?

Pg_stat_statements is an extension of Postgres that tracks execution statistics of all queries executed by a server. This extensions keeps track of statics like

  • number of times the…

--

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Mike Huls
Mike Huls

Written by Mike Huls

I write about interesting programming-related things: techniques, system architecture, software design and how to apply them in the best way. — mikehuls.com

No responses yet