Watch all postgres processes, sorted by memory use

watch -n 1 '{ ps aux | head -n 1; ps aux --sort -rss | grep postgres | grep -v grep; } | cat'
Continuously watches postgres, showing the instances using the most RAM at the top.
Sample Output
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
postgres 26208  1.9 15.2 2079280 1874652 ?     Ss   08:52   1:12 postgres: app applications 127.0.0.1(33962) idle
postgres 28228  1.8 14.9 2079104 1837488 ?     Ss   09:08   0:52 postgres: app applications 127.0.0.1(36580) idle
postgres 26199  0.2 13.0 2077080 1610028 ?     Ss   08:52   0:07 postgres: checkpointer process
postgres 31773  1.2  9.9 2079112 1229632 ?     Ss   09:36   0:14 postgres: app applications 127.0.0.1(41738) idle
postgres 26200  0.0  2.0 2076948 246704 ?      Ss   08:52   0:01 postgres: writer process

0
2017-05-14 17:01:44

These Might Interest You

  • This is a alternate command I like to use instead of TOP or HTOP to see what are the processes which are taking up the most memory on a system. It shows the username, process ID, CPU usage, Memory usage, thread ID, Number of threads associated with parent process, Resident Set Size, Virtual Memory Size, start time of the process, and command arguments. Then it's sorted by memory and showing the top 10 with head. This of course can be changed to suit you needs. I have a small system which is why Firefox is taking so much resources. Show Sample Output


    0
    watch -n .8 'ps -eaLo uname,pid,pcpu,pmem,lwp,nlwp,rss,vsz,start_time,args --sort -pmem| head -10'
    ubercoo · 2016-05-11 01:05:53 0

  • 0
    ps axo %mem,pid,euser,cmd | sort -nr | head -n 10
    lainme · 2012-10-12 03:27:26 0
  • ps returns all running processes which are then sorted by the 4th field in numerical order and the top 10 are sent to STDOUT. Show Sample Output


    99
    ps aux | sort -nk +4 | tail
    root · 2009-01-23 17:12:33 9

  • 0
    watch "ps aux | sort -nrk 3,3 | head -n 10"
    sidneycrestani · 2016-11-20 02:43:41 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: