I've not tried it myself but I believe that's what pgtune does: https://github.com/gregs1104/pgtune