Customizing PostgreSQL For Performance: User-Specific work_mem Setting
Did you know it’s possible to assign different work_mem
values to each database user in PostgreSQL?
This approach can lead to considerable memory savings and performance gains. For instance, the web-facing fleet, which generally runs simpler queries, can operate efficiently with a lower work_mem
. On the other hand, admin portals, which issue more complex or work against larger data-sets, benefit from a higher work_mem
setting.
Set up different usernames for the different parts of your server fleet and then adjust the work_mem
to match their needs. Go with a lower setting for the regular web requests and raise it up for the admin servers that run heavier (longer) queries against the database. This way, everyone gets just the right amount of memory—no more, no less.
Hope this helps!