Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 September PostgreSQL: Script to find TOP 10 Long Running Queries using pg_stat_statements (Day 2/2)

PostgreSQL: Script to find TOP 10 Long Running Queries using pg_stat_statements (Day 2/2)

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

This is the second day with the PostgreSQL pg_stat_statements module.
In the previous post, I have shared basic steps to configure and enable pg_stat_statements module for tracking query statistics.

In this post, I have prepared one small DBA script to find query statistics such a way that we can easily see the long executed queries.

The PostgreSQL database administrator can use this script for investigating performance related issues.

1
2
3
4
5
6
7
8
9
10
11
SELECT
pd.datname
,pss.query AS SQLQuery
,pss.rows AS TotalRowCount
,(pss.total_time / 1000 / 60) AS TotalMinute
,((pss.total_time / 1000 / 60)/calls) as TotalAverageTime
FROM pg_stat_statements AS pss
INNER JOIN pg_database AS pd
ON pss.dbid=pd.oid
ORDER BY 1 DESC
LIMIT 10;

Sep 10, 2016Anvesh Patel
PostgreSQL: Track ALL SQL Query Execution Statistics using pg_stat_statements Extension (Day 1/2)PostgreSQL: Create or Change default Tablespace of Table to Migrate on SSD
Comments: 3
  1. kashi
    April 19, 2017 at 6:59 pm

    is this pg_stat_statements available in 9.3?

    • Anvesh Patel
      Anvesh Patel
      April 19, 2017 at 7:26 pm

      Yes, it is possible. Please visit this link… https://www.postgresql.org/docs/9.3/static/pgstattuple.html

  2. Madhav
    July 24, 2018 at 6:58 am

    Does this query require superuser privileges?

Anvesh Patel
Anvesh Patel

Database Engineer

September 10, 2016 PostgreSQL, PostgreSQL DBA ScriptAnvesh Patel, database, database research and development, dbrnd, long running queries, pg_stat_statements, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Programming, PostgreSQL Tips and Tricks
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....