AI Hints
Home›PostgreSQL Tutorial›Finding and Fixing Slow Queries
PostgreSQL · Lesson 93 of 120

Configuration Basics

The settings that matter.

⏱ 2 min read▶ Video at 1:23:52🎓 Free
Watch this lesson in the PostgreSQL courseWatch on YouTube ↗Full PostgreSQL course

Postgres has hundreds of settings, but a handful matter most. Memory for caching, memory for sorting, and how many connections to allow.

  • Hundreds of settings
  • A few matter
  • Memory, connections

See and change settings

Show reads a setting. Set changes it for this session. Pg settings explains each one, with its unit. Run it. The current values, and a bigger work memory for this session.

query.sqlsql
SHOW shared_buffers;
SET work_mem = '64MB';
SELECT name, setting, unit FROM pg_settings
WHERE name IN ('shared_buffers', 'work_mem', 'max_connections', 'effective_cache_size');
Output
 shared_buffers
----------------
 128MB
(1 row)

SET
         name         | setting | unit
----------------------+---------+------
 effective_cache_size | 524288  | 8kB
 max_connections      | 100     |
 shared_buffers       | 16384   | 8kB
 work_mem             | 65536   | kB
(4 rows)

Settings that matter

Shared buffers is Postgres's own cache, often a quarter of memory. Work mem is memory per sort or hash. Effective cache size tells the planner about the operating system cache. And max connections limits connections.

SettingRule of thumb
shared_buffers~25% of RAM
work_mem4–64 MB, per sort
effective_cache_size~50–75% of RAM
max_connectionslow hundreds, use a pool

Summary

A few settings, memory and connections, matter most. Next, backups with pg dump.

Key takeaways
  • shared_buffers
  • work_mem
  • max_connections
Next up: Backups with pg_dump — save a copy