{"id":922,"date":"2020-12-09T11:18:06","date_gmt":"2020-12-09T10:18:06","guid":{"rendered":"http:\/\/www.streppone.it\/cosimo\/blog\/?p=922"},"modified":"2020-12-09T11:23:19","modified_gmt":"2020-12-09T10:23:19","slug":"pgtop-a-top-clone-for-postgresql","status":"publish","type":"post","link":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/","title":{"rendered":"pgtop &#8211; a top clone for PostgreSQL"},"content":{"rendered":"<p>According to <a href=\"https:\/\/metacpan.org\">meta::cpan<\/a> records, the <a href=\"https:\/\/metacpan.org\/release\/COSIMO\/pgtop-0.02\">first release of pgtop<\/a> is dated April 26, 2005, which makes this little software <b>more than 15 years old<\/b>!<\/p>\n<p>Back then I had just found out about the brilliant <a href=\"http:\/\/jeremy.zawodny.com\/mysql\/mytop\/\">mytop<\/a> by Jeremy Zawodny, and my day-to-day experience being on Postgres, IIRC version 6.5.3, I decided to try and &#8220;convert&#8221; mytop to Postgres.<\/p>\n<p>Being quite naive, I thought the endeavour would be much easier than it really was. I&#8217;m glad I started though, which is why pgtop exists in the first place. It&#8217;s not the only one either. I seem to remember a few similar pgtop projects by other programmers.<\/p>\n<p>After using MySQL and Percona Server for many years, due to a new job, I have gone back to Postgres, version 9.5 and 10 at this time. In recent months, I have done some work to improve performance of our database queries, and remembered writing and using pgtop years before.<\/p>\n<p>Since I lost(*) the original sources, I tried the pgtop version I last uploaded to CPAN, 0.05, dated 2008. It did work, in the sense that <b>I could run the same perl code unmodified, a great testament to Perl as language and as runtime<\/b>. It didn&#8217;t work because the underlying Postgres meta tables that were used in version 6 changed their schema in the 10-12 years since :-)<\/p>\n<p>I spent some time to adapt the metadata queries to work with recent Postgres versions, and was slightly amused by the quality of my 15 year old code&#8230; The best feeling about this little tool was to <b>rediscover how useful a few dozen lines of code can be<\/b>. The service provider monitoring helps, but doesn&#8217;t even come close to the level of detail pgtop can provide.<\/p>\n<p>After getting pgtop to work again, I quickly added a few more useful features. I was pleased by the efficiency with which I could work on this tool, considering its age.<\/p>\n<p>So far I added just what was strictly necessary to me:<\/p>\n<ul>\n<li>Updated pgtop to the current decade. Now requires perl >= 5.014<\/li>\n<li>Fixed to work with Postgres >= 9.0<\/li>\n<li>Added a sample Dockerfile to build and run pgtop as Docker container<\/li>\n<li>Added a <code>--config<\/code> option, to load arbitrary config files. This is useful if you want to monitor several databases at once, for example in a tmux session. The config file supports all the options that are available on the command line.<\/li>\n<li>Implemented a query killer command, activated pressing <kbd>K<\/kbd> to kill at once all queries slower than a given threshold, in seconds. This is useful if the database is overwhelmed by a lot of slow queries. I don&#8217;t recommend using it, <b>particularly if it involves killing UPDATE or INSERT queries<\/b>, but it can be quite useful.<\/li>\n<li>Added a <code>--slow_threshold option<\/code>, to consider queries slow if they have been running for longer than the given value (in seconds). Now the tool highlights slow queries in bold yellow, and logs all the slow queries to a <code>pgtop.log<\/code> file.<\/li>\n<li>Added a <code>--slack_webhook<\/code> option, to automatically notify a slack channel if a query crosses the slow threshold runtime value. All the information about the slow query including the SQL will be included in the slack message.<\/li>\n<\/ul>\n<p>Please let me know if you give it a try! :-)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>According to meta::cpan records, the first release of pgtop is dated April 26, 2005, which makes this little software more than 15 years old! Back then I had just found out about the brilliant mytop by Jeremy Zawodny, and my day-to-day experience being on Postgres, IIRC version 6.5.3, I decided to try and &#8220;convert&#8221; mytop [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":923,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[537,512,556],"tags":[518,559,219,50,558,557,560,61],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>pgtop - a top clone for PostgreSQL - Random hacking<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"pgtop - a top clone for PostgreSQL - Random hacking\" \/>\n<meta property=\"og:description\" content=\"According to meta::cpan records, the first release of pgtop is dated April 26, 2005, which makes this little software more than 15 years old! Back then I had just found out about the brilliant mytop by Jeremy Zawodny, and my day-to-day experience being on Postgres, IIRC version 6.5.3, I decided to try and &#8220;convert&#8221; mytop [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/\" \/>\n<meta property=\"og:site_name\" content=\"Random hacking\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-09T10:18:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-12-09T10:23:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.streppone.it\/cosimo\/blog\/wp-content\/uploads\/2020\/12\/capture.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1342\" \/>\n\t<meta property=\"og:image:height\" content=\"442\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"cosimo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"cosimo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/\"},\"author\":{\"name\":\"cosimo\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"headline\":\"pgtop &#8211; a top clone for PostgreSQL\",\"datePublished\":\"2020-12-09T10:18:06+00:00\",\"dateModified\":\"2020-12-09T10:23:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/\"},\"wordCount\":537,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"image\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.streppone.it\/cosimo\/blog\/wp-content\/uploads\/2020\/12\/capture.png\",\"keywords\":[\"monitoring\",\"mytop\",\"operations\",\"perl\",\"pgtop\",\"postgresql\",\"tmux\",\"webops\"],\"articleSection\":[\"mysql\",\"Operations\",\"postgresql\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/\",\"name\":\"pgtop - a top clone for PostgreSQL - Random hacking\",\"isPartOf\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.streppone.it\/cosimo\/blog\/wp-content\/uploads\/2020\/12\/capture.png\",\"datePublished\":\"2020-12-09T10:18:06+00:00\",\"dateModified\":\"2020-12-09T10:23:19+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#primaryimage\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/wp-content\/uploads\/2020\/12\/capture.png\",\"contentUrl\":\"https:\/\/www.streppone.it\/cosimo\/blog\/wp-content\/uploads\/2020\/12\/capture.png\",\"width\":1342,\"height\":442},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"pgtop &#8211; a top clone for PostgreSQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#website\",\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/\",\"name\":\"Random hacking\",\"description\":\"Assume nothing. Code defensively. Keep it simple, stupid!\",\"publisher\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1\",\"name\":\"cosimo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g\",\"caption\":\"cosimo\"},\"logo\":{\"@id\":\"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"pgtop - a top clone for PostgreSQL - Random hacking","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/","og_locale":"en_US","og_type":"article","og_title":"pgtop - a top clone for PostgreSQL - Random hacking","og_description":"According to meta::cpan records, the first release of pgtop is dated April 26, 2005, which makes this little software more than 15 years old! Back then I had just found out about the brilliant mytop by Jeremy Zawodny, and my day-to-day experience being on Postgres, IIRC version 6.5.3, I decided to try and &#8220;convert&#8221; mytop [&hellip;]","og_url":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/","og_site_name":"Random hacking","article_published_time":"2020-12-09T10:18:06+00:00","article_modified_time":"2020-12-09T10:23:19+00:00","og_image":[{"width":1342,"height":442,"url":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-content\/uploads\/2020\/12\/capture.png","type":"image\/png"}],"author":"cosimo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"cosimo","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#article","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/"},"author":{"name":"cosimo","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"headline":"pgtop &#8211; a top clone for PostgreSQL","datePublished":"2020-12-09T10:18:06+00:00","dateModified":"2020-12-09T10:23:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/"},"wordCount":537,"commentCount":2,"publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"image":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-content\/uploads\/2020\/12\/capture.png","keywords":["monitoring","mytop","operations","perl","pgtop","postgresql","tmux","webops"],"articleSection":["mysql","Operations","postgresql"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/","url":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/","name":"pgtop - a top clone for PostgreSQL - Random hacking","isPartOf":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#primaryimage"},"image":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-content\/uploads\/2020\/12\/capture.png","datePublished":"2020-12-09T10:18:06+00:00","dateModified":"2020-12-09T10:23:19+00:00","breadcrumb":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#primaryimage","url":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-content\/uploads\/2020\/12\/capture.png","contentUrl":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-content\/uploads\/2020\/12\/capture.png","width":1342,"height":442},{"@type":"BreadcrumbList","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/2020\/12\/pgtop-a-top-clone-for-postgresql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.streppone.it\/cosimo\/blog\/"},{"@type":"ListItem","position":2,"name":"pgtop &#8211; a top clone for PostgreSQL"}]},{"@type":"WebSite","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#website","url":"https:\/\/www.streppone.it\/cosimo\/blog\/","name":"Random hacking","description":"Assume nothing. Code defensively. Keep it simple, stupid!","publisher":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.streppone.it\/cosimo\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/c443bedbf6ecf99550d6395620801df1","name":"cosimo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cb1d938720df45a2720724aae99e3bfc?s=96&r=g","caption":"cosimo"},"logo":{"@id":"https:\/\/www.streppone.it\/cosimo\/blog\/#\/schema\/person\/image\/"},"url":"https:\/\/www.streppone.it\/cosimo\/blog\/author\/cosimo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/922"}],"collection":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/comments?post=922"}],"version-history":[{"count":3,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/922\/revisions"}],"predecessor-version":[{"id":926,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/posts\/922\/revisions\/926"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/media\/923"}],"wp:attachment":[{"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/media?parent=922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/categories?post=922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.streppone.it\/cosimo\/blog\/wp-json\/wp\/v2\/tags?post=922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}