It’s a complicated issue. You can search postgres documentation for details. There are some topics that discuss tuning here
The defaults work reasonably well.
If you are having a problem, you can describe the problem and how much traffic you have and how big your database is.