News for hackers. Stuff that matters.
Re:You Don't Need a GUI by sbuttgereit on Friday April 09, 2021 @07:53AM (#26749328)
You can use the .psqlrc for this purpose, though I suppose you could also real that in via a file on demand, too. You make entries something like:

  \set show_slow_queries
  'SELECT 
    (total_time / 1000 / 60) as total_minutes, 
    (total_time/calls) as average_time, query 
  FROM pg_stat_statements 
  ORDER BY 1 DESC 
  LIMIT 100;'
(got from https://www.craigkerstiens.com/2013/02/21/more-out-of-psql/)

and then later at the command prompt you access it as; ":show_slow_queries".

I have a few system queries like this in my .psqlrc file, but I don't do much which this feature often truth be told. I have a pretty strong knowledge of the database schema I work with, I do a lot of work on systems I don't regularly control so its not dependably available, and readline history suffices for more immediate needs.

There are no comments on this comment yet.