AshKeys

Confessions and Confusions of Ashok M A. Personal and Professional Blog.

Ashok Mannolu Arunachalam, How toPostgresDebug
Back

How to monitor query execution time in postgres

Recently, I had to debug our database to find out why some of the transaction takes more time.

This can be done by making use of the postgresql.conf.

Enable logging of long queries

With the below configuration property, we can tell the postgres to log statements that take too long to execute.

conf
log_min_duration_statement='300' # Time in milliseconds
Other possible settingsMeaning
log_min_duration_statement='-1'disable
log_min_duration_statement='0'log all queries

Now, we can monitor the logs to see the long queries.