How much memory does a database currently use?
This is one of those questions that are quick and simple when asked, but not so much when being answered.
PostgreSQL uses memory in a dynamic way across its databases, which is why the question includes the word “currently.” By this, we mean that the shared buffers managed by a database server are used concurrently by all its databases. This is based on demand, so if a database is unused, then the amount of memory it uses will decrease, because the same memory will gradually be reused to cache data files from busier databases.
How to do it…
The largest amount of memory is usually consumed for the shared buffers. This is an area that is shared among all the sessions; e.g., if multiple sessions are working on the same table at the same time, there is only one copy of each table block in the shared buffers.
The pg_buffercache
extension provides a view that has one row for each buffer page. It can be installed...