High Performance PostgreSQL, Tuning and Optimization Guide - FileId - 160682
High Performance PostgreSQL, Tuning and Optimization Guide - FileId - 160682
Optimization Guide
Ibrar Ahmed
Senior Software Engineer @ Percona LLC
PostgreSQL Consultant
PostgreSQL
Licence?
PostgreSQL: Released under the PostgreSQL
Who? License. (Similar to BSD or MIT)
● Web technology
● Financial
● No-SQL Workload
● Small & Large Scale Business
!2
PostgreSQL Architecture
!3
Database Performance
• Hardware
• Workload
• Queries
• Application
!4
Tune PostgreSQL
!5
PostgreSQL Tuning - Configuration Parameter
• shared_buffer
• wal_buffers
• effective_cache_size
• work_mem
• maintenance_work_mem
• synchronous_commit
• checkpoint_timeout
• checkpoint_completion_target
!6
PostgreSQL Tuning - shared_buffer
• PostgreSQL uses its own buffer and also uses kernel buffered I/O.
The proper size for the POSTGRESQL shared buffer cache is the largest useful size
that does not adversely affect other activity.
—Bruce Momjian
!7
PostgreSQL Tuning - shared_buffer
!8
PostgreSQL Tuning - wal_buffer
• PostgreSQL writes its WAL (write ahead log) record into the buffers and then these buffers are
flushed to disk.
• Bigger value for wal_buffer in case of lot of concurrent connection gives better performance.
!9
PostgreSQL Tuning - effective_cache_size
• It should be large enough to hold most accessed tables, but at the same time small enough to
avoid swap.
!10
PostgreSQL Tuning - work_mem
!11
PostgreSQL Tuning - maintenance_work_mem
• Setting a large value helps in tasks like VACUUM, RESTORE, CREATE INDEX, ADD FOREIGN KEY and ALTER TABLE.
!12
PostgreSQL Tuning - synchronous_commit
• This is used to enforce that commit will wait for WAL to be written on disk before returning a
!13
PostgreSQL Tuning - checkpoint_timeout
• PostgreSQL writes changes into WAL. The checkpoint process flushes the data into the data
files.
!14
Tune Linux
!15
Linux Tuning - Huge Pages
!16
Linux Tuning - vm.swappiness
This is another kernel parameter that can affect the performance of the database.
• Used to control the swappiness (swapping pages to and from swap memory into RAM) behaviour
on a Linux system.
!17
Linux Tuning / vm.overcommit_memory and vm.overcommit_ratio
• Applications acquire memory and free that memory when it is no longer needed.
• But in some cases an application acquires too much memory and does not release it. This can
!18
Linux Tuning - vm.dirty_background_ratio / vm.dirty_background_bytes
• The vm.dirty_background_ratio is the percentage of memory filled with dirty pages that need
to be flushed to disk.
!19
Linux Tuning - vm.dirty_ratio / vm.dirty_bytes
• The vm.dirty_ratio is the percentage of memory filled with dirty pages that need to be flushed
to disk.
!20
Blogs
https://www.percona.com/blog/2018/08/31/tuning-postgresql-database-
parameters-to-optimize-performance/
https://www.percona.com/blog/2018/08/29/tune-linux-kernel-parameters-for-
postgresql-optimization/
!21