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
postgres 26208  1.9 15.2 2079280 1874652 ?     Ss   08:52   1:12 postgres: app applications idle
postgres 28228  1.8 14.9 2079104 1837488 ?     Ss   09:08   0:52 postgres: app applications 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 idle
postgres 26200  0.0  2.0 2076948 246704 ?      Ss   08:52   0:01 postgres: writer process

2017-05-14 17:01:44

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? 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.


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: