There are several key parameters that should be adjusted for optimal performance, security, and stability. The default settings are usually designed for small systems and need tuning based on your hardware, workload, and specific use cases. Here's a breakdown of important parameters to adjust:
1. Memory Settings
- shared_buffers
- Memory the database server uses for shared memory buffers
- 25% of physical RAM if physical RAM > 1GB
- Larger settings for shared_buffers usually require a corresponding increase in max_wal_size and setting huge_pages
- wal_buffers
- The amount of shared memory used for WAL data that has not yet been written to disk
- Default value: 3% of shared_buffers, but not less than 64kB nor more than the size of one WAL segment (16MB)
- The contents of the WAL buffers are written out to disk at every transaction commit, so extremely large values are unlikely to provide a significant benefit. However, setting this value to at least a few megabytes can improve write performance on a busy server where many clients are committing at once. The auto-tuning selected by the default setting of -1 should give reasonable results in most cases
- work_mem
- Used for sorting tuples by ORDER BY and DISTINCT operations, and for joining tables by merge-join and hash-join operations.
- Be careful with high values, as this is allocated per query, potentially consuming a large amount of RAM during heavy workloads
- Consider with formular "Total RAM * 0.25 / max_connections"
- temp_buffers
- Used for temporary buffers within each database session and for storing temporary tables.
- This setting can be changed within individual sessions, but only before the first use of temporary tables within the session; subsequent attempts to change the value will have no effect on that session