Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Linux tuning to improve PostgreSQL
performance
Ilya Kosmodemiansky
ik@postgresql-consulting.com
The modern linux kernel
• About 1000 sysctl parameters (plus non-sysctl settings, such
as mount options)
• It is not possible to benefit from the modern kernel’s
advantages without wise tuning
Tuning targets in Linux
• CPU
• Memory
• Storage
• Other
PostgreSQL specifics
• Hungry for resources (like any other database)
• Tuning single target can have a very small effect
• We need to maximize throughput
Throughput approach
Disks
*
*
shared_buffers
Kernel buffer
PostgreSQL worker processes
WAL
How to make pages travel faster from disk to memory
• More effective work with memory
• More effective flushing pages to disk
• A proper hardware, of course
More effective work with memory
• NUMA
• Huge pages
• Swap
NUMA
Symptoms that something goes wrong
• Some CPU cores are overloaded without any obvious reason
NUMA
What goes on
• Non Uniform Memory Access
• CPUs have their own memory, CPU + memory nodes
connected via NUMA interconnect
• CPU uses its own memory, then accesses remaining memory by
interconnect
• If node interleaving disabled, CPU tries to use its local memory
(for page cache for example;-))
NUMA
Which NUMA configuration is better for PostgreSQL
• Enable memory interleaving in BIOS
• numa → off or vm.zone_reclaim_mode = 0
• May be better numactl − −interleave = all
/etc/init.d/postgresql start
• kernel.numa_balancing = 0
Blog post from Robert Haas:
http://rhaas.blogspot.co.at/2014/06/linux-disables-
vmzonereclaimmode-by.html
Huge pages
Symptoms that something goes wrong
• You have a lot of RAM and you shared_buffers settings is
32Gb/64Gb or more
• That means that you definitely have an overhead if not using
huge pages
Huge pages
What goes on
• By default OS allocates memory by 4kB chunk
• OS translates physical addresses into virtual addresses and
cache the result in Translation Lookaside Buffer (TLB)
• 1Gb
4kB = 262144 - huge TLB overhead and cache misses
• Better to allocate memory in larger chunks
Huge pages
How can PostgreSQL benefit from huge pages?
• Enable pages in kernel
• vm.nr_hugepages = 3170 via sysctl
• Before 9.2 - libhugetlbfs library
• 9.3 - no way
• 9.4+ huge_pages = try|on|off (postgresql.conf)
• Works on Linux
• Disable Transparent huge pages - PostgreSQL can not benefit
from them
Swap
Symptoms that something goes wrong
• There are enough memory, but swap is used
Swap
What goes on
• It happens when there are a lot of RAM on server
Swap
What is better for PostgreSQL?
• vm.swappiness = 1 or 0
• OOM-killer
• 0 is not a good idea for modern kernels
More effective flushing pages to disk
Symptoms that something goes wrong
• Checkpoint spikes
More effective flushing pages to disk
More effective flushing pages to disk
What goes on
• By default vm.dirty_ratio = 20, vm.dirty_background_ratio
= 10
• Nothing happens until kernel buffer is 10% full of dirty pages
• From 10% to 20% - background flushing
• From 20% IO effectively stops until pdflush/flushd/kdflush
finishes its job
• This is almost crazy if your shared_buffers setting is
32Gb/64Gb or more with any cache on RAID-controller or SSD
More effective flushing pages to disk
What is better for PostgreSQL?
• vm.dirty_background_bytes = 67108864, vm.dirty_bytes =
536870912 (for RAID with 512MB cache on board) looks more
reasonable
• Hardware settings and checkpoint settings in postgresql.conf
must be appropriate
• See my talk about PostgreSQL disc performance for details
(https://www.youtube.com/watch?v=Lbx-JVcGIFo)
What else
• Scheduler tuning
• Power saving
Scheduler tuning
• sysctl kernel.sched_migration_cost_ns supposed to be
reasonably high
• sysctl kernel.sched_autogroup_enabled = 0
• A good explanation http://www.postgresql.org/message-
id/50E4AAB1.9040902@optionshouse.com
• You need a relatively new kernel
Example
$ pgbench -S -c 8 -T 30 -U postgres pgbench transaction type: SELECT only
scaling factor: 30 duration: 30 s
number of clients: 8 number of threads: 1
sched_migration_cost_ns = 50000, sched_autogroup_enabled = 1
- tps: 22621, 22692, 22502
sched_migration_cost_ns = 500000, sched_autogroup_enabled = 0
- tps: 23689, 23930, 23657
tests by Alexey Lesovsky
Power saving policy
• acpi_cpufreq and intel_pstate drivers
• scaling_governor: performance, ondemand, conservative,
powersave, userspace
• acpi_cpufreq + performance can be dramatically faster than
acpi_cpufreq + ondemand
• intel_pstate + powersave
Thanks
to my collegues Alexey Lesovsky and Max Boguk for a lot of
research on this topic
Questions?
ik@postgresql-consulting.com

More Related Content

What's hot (20)

PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
elliando dias
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HA
haroonm
 
Creating a complete disaster recovery strategy
Creating a complete disaster recovery strategyCreating a complete disaster recovery strategy
Creating a complete disaster recovery strategy
MariaDB plc
 
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
ScaleGrid.io
 
MariaDB 마이그레이션 - 네오클로바
MariaDB 마이그레이션 - 네오클로바MariaDB 마이그레이션 - 네오클로바
MariaDB 마이그레이션 - 네오클로바
NeoClova
 
PostgreSQL replication
PostgreSQL replicationPostgreSQL replication
PostgreSQL replication
NTT DATA OSS Professional Services
 
Solving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsSolving PostgreSQL wicked problems
Solving PostgreSQL wicked problems
Alexander Korotkov
 
Get to know PostgreSQL!
Get to know PostgreSQL!Get to know PostgreSQL!
Get to know PostgreSQL!
Oddbjørn Steffensen
 
5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance5 Steps to PostgreSQL Performance
5 Steps to PostgreSQL Performance
Command Prompt., Inc
 
Introduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundIntroduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparound
Masahiko Sawada
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Mydbops
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs
PGConf APAC
 
A Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and HudiA Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and Hudi
Databricks
 
MySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZEMySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZE
Norvald Ryeng
 
PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)
Noriyoshi Shinoda
 
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdfProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
Jesmar Cannao'
 
Redefining tables online without surprises
Redefining tables online without surprisesRedefining tables online without surprises
Redefining tables online without surprises
Nelson Calero
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
PgDay.Seoul
 
PostgreSQL and RAM usage
PostgreSQL and RAM usagePostgreSQL and RAM usage
PostgreSQL and RAM usage
Alexey Bashtanov
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0
Mydbops
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
elliando dias
 
PostgreSQL HA
PostgreSQL   HAPostgreSQL   HA
PostgreSQL HA
haroonm
 
Creating a complete disaster recovery strategy
Creating a complete disaster recovery strategyCreating a complete disaster recovery strategy
Creating a complete disaster recovery strategy
MariaDB plc
 
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
What’s the Best PostgreSQL High Availability Framework? PAF vs. repmgr vs. Pa...
ScaleGrid.io
 
MariaDB 마이그레이션 - 네오클로바
MariaDB 마이그레이션 - 네오클로바MariaDB 마이그레이션 - 네오클로바
MariaDB 마이그레이션 - 네오클로바
NeoClova
 
Solving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsSolving PostgreSQL wicked problems
Solving PostgreSQL wicked problems
Alexander Korotkov
 
Introduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparoundIntroduction VAUUM, Freezing, XID wraparound
Introduction VAUUM, Freezing, XID wraparound
Masahiko Sawada
 
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera ) Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Wars of MySQL Cluster ( InnoDB Cluster VS Galera )
Mydbops
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs
PGConf APAC
 
A Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and HudiA Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and Hudi
Databricks
 
MySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZEMySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZE
Norvald Ryeng
 
PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)PGConf.ASIA 2017 Logical Replication Internals (English)
PGConf.ASIA 2017 Logical Replication Internals (English)
Noriyoshi Shinoda
 
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdfProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
Jesmar Cannao'
 
Redefining tables online without surprises
Redefining tables online without surprisesRedefining tables online without surprises
Redefining tables online without surprises
Nelson Calero
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
PgDay.Seoul
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0
Mydbops
 

Viewers also liked (6)

Некоторые улучшения производительности: Huge Pages – Илья Космодемьянский
Некоторые улучшения производительности: Huge Pages – Илья КосмодемьянскийНекоторые улучшения производительности: Huge Pages – Илья Космодемьянский
Некоторые улучшения производительности: Huge Pages – Илья Космодемьянский
Yandex
 
Best Practices of running PostgreSQL in Virtual Environments
Best Practices of running PostgreSQL in Virtual EnvironmentsBest Practices of running PostgreSQL in Virtual Environments
Best Practices of running PostgreSQL in Virtual Environments
Jignesh Shah
 
PostgreSQL 資料可靠性及WAL
PostgreSQL 資料可靠性及WALPostgreSQL 資料可靠性及WAL
PostgreSQL 資料可靠性及WAL
Yen-Wen Chen
 
雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング
yoku0825
 
DeNAの分析を支える分析基盤
DeNAの分析を支える分析基盤DeNAの分析を支える分析基盤
DeNAの分析を支える分析基盤
Kenshin Yamada
 
Pythonによる機械学習の最前線
Pythonによる機械学習の最前線Pythonによる機械学習の最前線
Pythonによる機械学習の最前線
Kimikazu Kato
 
Некоторые улучшения производительности: Huge Pages – Илья Космодемьянский
Некоторые улучшения производительности: Huge Pages – Илья КосмодемьянскийНекоторые улучшения производительности: Huge Pages – Илья Космодемьянский
Некоторые улучшения производительности: Huge Pages – Илья Космодемьянский
Yandex
 
Best Practices of running PostgreSQL in Virtual Environments
Best Practices of running PostgreSQL in Virtual EnvironmentsBest Practices of running PostgreSQL in Virtual Environments
Best Practices of running PostgreSQL in Virtual Environments
Jignesh Shah
 
PostgreSQL 資料可靠性及WAL
PostgreSQL 資料可靠性及WALPostgreSQL 資料可靠性及WAL
PostgreSQL 資料可靠性及WAL
Yen-Wen Chen
 
雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング雑なMySQLパフォーマンスチューニング
雑なMySQLパフォーマンスチューニング
yoku0825
 
DeNAの分析を支える分析基盤
DeNAの分析を支える分析基盤DeNAの分析を支える分析基盤
DeNAの分析を支える分析基盤
Kenshin Yamada
 
Pythonによる機械学習の最前線
Pythonによる機械学習の最前線Pythonによる機械学習の最前線
Pythonによる機械学習の最前線
Kimikazu Kato
 

Similar to Linux tuning to improve PostgreSQL performance (20)

Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014
marvin herrera
 
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar AhmedPGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
Equnix Business Solutions
 
In-memory Caching in HDFS: Lower Latency, Same Great Taste
In-memory Caching in HDFS: Lower Latency, Same Great TasteIn-memory Caching in HDFS: Lower Latency, Same Great Taste
In-memory Caching in HDFS: Lower Latency, Same Great Taste
DataWorks Summit
 
Tuning Linux for your database FLOSSUK 2016
Tuning Linux for your database FLOSSUK 2016Tuning Linux for your database FLOSSUK 2016
Tuning Linux for your database FLOSSUK 2016
Colin Charles
 
In-memory Data Management Trends & Techniques
In-memory Data Management Trends & TechniquesIn-memory Data Management Trends & Techniques
In-memory Data Management Trends & Techniques
Hazelcast
 
Responding rapidly when you have 100+ GB data sets in Java
Responding rapidly when you have 100+ GB data sets in JavaResponding rapidly when you have 100+ GB data sets in Java
Responding rapidly when you have 100+ GB data sets in Java
Peter Lawrey
 
Linux Huge Pages
Linux Huge PagesLinux Huge Pages
Linux Huge Pages
Geraldo Netto
 
Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2
Marco Tusa
 
Accelerating HBase with NVMe and Bucket Cache
Accelerating HBase with NVMe and Bucket CacheAccelerating HBase with NVMe and Bucket Cache
Accelerating HBase with NVMe and Bucket Cache
Nicolas Poggi
 
August 2013 HUG: Removing the NameNode's memory limitation
August 2013 HUG: Removing the NameNode's memory limitation August 2013 HUG: Removing the NameNode's memory limitation
August 2013 HUG: Removing the NameNode's memory limitation
Yahoo Developer Network
 
OSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin CharlesOSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin Charles
NETWAYS
 
Accelerating hbase with nvme and bucket cache
Accelerating hbase with nvme and bucket cacheAccelerating hbase with nvme and bucket cache
Accelerating hbase with nvme and bucket cache
David Grier
 
Loadays MySQL
Loadays MySQLLoadays MySQL
Loadays MySQL
lefredbe
 
Running MySQL on Linux
Running MySQL on LinuxRunning MySQL on Linux
Running MySQL on Linux
Great Wide Open
 
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Alluxio, Inc.
 
SQream DB - Bigger Data On GPUs: Approaches, Challenges, Successes
SQream DB - Bigger Data On GPUs: Approaches, Challenges, SuccessesSQream DB - Bigger Data On GPUs: Approaches, Challenges, Successes
SQream DB - Bigger Data On GPUs: Approaches, Challenges, Successes
Arnon Shimoni
 
Tuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadTuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy Workload
Marius Adrian Popa
 
MariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & Optimization
MariaDB plc
 
Taking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout SessionTaking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout Session
Splunk
 
Optimizing elastic search on google compute engine
Optimizing elastic search on google compute engineOptimizing elastic search on google compute engine
Optimizing elastic search on google compute engine
Bhuvaneshwaran R
 
Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014Colvin exadata mistakes_ioug_2014
Colvin exadata mistakes_ioug_2014
marvin herrera
 
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar AhmedPGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
Equnix Business Solutions
 
In-memory Caching in HDFS: Lower Latency, Same Great Taste
In-memory Caching in HDFS: Lower Latency, Same Great TasteIn-memory Caching in HDFS: Lower Latency, Same Great Taste
In-memory Caching in HDFS: Lower Latency, Same Great Taste
DataWorks Summit
 
Tuning Linux for your database FLOSSUK 2016
Tuning Linux for your database FLOSSUK 2016Tuning Linux for your database FLOSSUK 2016
Tuning Linux for your database FLOSSUK 2016
Colin Charles
 
In-memory Data Management Trends & Techniques
In-memory Data Management Trends & TechniquesIn-memory Data Management Trends & Techniques
In-memory Data Management Trends & Techniques
Hazelcast
 
Responding rapidly when you have 100+ GB data sets in Java
Responding rapidly when you have 100+ GB data sets in JavaResponding rapidly when you have 100+ GB data sets in Java
Responding rapidly when you have 100+ GB data sets in Java
Peter Lawrey
 
Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2Scaling with sync_replication using Galera and EC2
Scaling with sync_replication using Galera and EC2
Marco Tusa
 
Accelerating HBase with NVMe and Bucket Cache
Accelerating HBase with NVMe and Bucket CacheAccelerating HBase with NVMe and Bucket Cache
Accelerating HBase with NVMe and Bucket Cache
Nicolas Poggi
 
August 2013 HUG: Removing the NameNode's memory limitation
August 2013 HUG: Removing the NameNode's memory limitation August 2013 HUG: Removing the NameNode's memory limitation
August 2013 HUG: Removing the NameNode's memory limitation
Yahoo Developer Network
 
OSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin CharlesOSDC 2016 - Tuning Linux for your Database by Colin Charles
OSDC 2016 - Tuning Linux for your Database by Colin Charles
NETWAYS
 
Accelerating hbase with nvme and bucket cache
Accelerating hbase with nvme and bucket cacheAccelerating hbase with nvme and bucket cache
Accelerating hbase with nvme and bucket cache
David Grier
 
Loadays MySQL
Loadays MySQLLoadays MySQL
Loadays MySQL
lefredbe
 
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Optimizing Latency-sensitive queries for Presto at Facebook: A Collaboration ...
Alluxio, Inc.
 
SQream DB - Bigger Data On GPUs: Approaches, Challenges, Successes
SQream DB - Bigger Data On GPUs: Approaches, Challenges, SuccessesSQream DB - Bigger Data On GPUs: Approaches, Challenges, Successes
SQream DB - Bigger Data On GPUs: Approaches, Challenges, Successes
Arnon Shimoni
 
Tuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadTuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy Workload
Marius Adrian Popa
 
MariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & Optimization
MariaDB plc
 
Taking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout SessionTaking Splunk to the Next Level - Architecture Breakout Session
Taking Splunk to the Next Level - Architecture Breakout Session
Splunk
 
Optimizing elastic search on google compute engine
Optimizing elastic search on google compute engineOptimizing elastic search on google compute engine
Optimizing elastic search on google compute engine
Bhuvaneshwaran R
 

More from PostgreSQL-Consulting (14)

Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
PostgreSQL-Consulting
 
Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...
Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...
Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...
PostgreSQL-Consulting
 
PostgreSQL worst practices, version PGConf.US 2017 by Ilya Kosmodemiansky
PostgreSQL worst practices, version PGConf.US 2017 by Ilya KosmodemianskyPostgreSQL worst practices, version PGConf.US 2017 by Ilya Kosmodemiansky
PostgreSQL worst practices, version PGConf.US 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya KosmodemianskyPostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
Linux internals for Database administrators at Linux Piter 2016
Linux internals for Database administrators at Linux Piter 2016Linux internals for Database administrators at Linux Piter 2016
Linux internals for Database administrators at Linux Piter 2016
PostgreSQL-Consulting
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL
PostgreSQL-Consulting
 
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 ViennaAutovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
PostgreSQL-Consulting
 
PostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQPostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL-Consulting
 
Как PostgreSQL работает с диском
Как PostgreSQL работает с дискомКак PostgreSQL работает с диском
Как PostgreSQL работает с диском
PostgreSQL-Consulting
 
Максим Богук. Postgres-XC
Максим Богук. Postgres-XCМаксим Богук. Postgres-XC
Максим Богук. Postgres-XC
PostgreSQL-Consulting
 
Иван Фролков. Tricky SQL
Иван Фролков. Tricky SQLИван Фролков. Tricky SQL
Иван Фролков. Tricky SQL
PostgreSQL-Consulting
 
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQL
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQLИлья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQL
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQL
PostgreSQL-Consulting
 
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
PostgreSQL-Consulting
 
Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...
Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...
Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...
PostgreSQL-Consulting
 
PostgreSQL worst practices, version PGConf.US 2017 by Ilya Kosmodemiansky
PostgreSQL worst practices, version PGConf.US 2017 by Ilya KosmodemianskyPostgreSQL worst practices, version PGConf.US 2017 by Ilya Kosmodemiansky
PostgreSQL worst practices, version PGConf.US 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya KosmodemianskyPostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL worst practices, version FOSDEM PGDay 2017 by Ilya Kosmodemiansky
PostgreSQL-Consulting
 
Linux internals for Database administrators at Linux Piter 2016
Linux internals for Database administrators at Linux Piter 2016Linux internals for Database administrators at Linux Piter 2016
Linux internals for Database administrators at Linux Piter 2016
PostgreSQL-Consulting
 
10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL10 things, an Oracle DBA should care about when moving to PostgreSQL
10 things, an Oracle DBA should care about when moving to PostgreSQL
PostgreSQL-Consulting
 
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 ViennaAutovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
Autovacuum, explained for engineers, new improved version PGConf.eu 2015 Vienna
PostgreSQL-Consulting
 
PostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQPostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL Meetup Berlin at Zalando HQ
PostgreSQL-Consulting
 
Как PostgreSQL работает с диском
Как PostgreSQL работает с дискомКак PostgreSQL работает с диском
Как PostgreSQL работает с диском
PostgreSQL-Consulting
 
Максим Богук. Postgres-XC
Максим Богук. Postgres-XCМаксим Богук. Postgres-XC
Максим Богук. Postgres-XC
PostgreSQL-Consulting
 
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQL
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQLИлья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQL
Илья Космодемьянский. Использование очередей асинхронных сообщений с PostgreSQL
PostgreSQL-Consulting
 

Recently uploaded (20)

Sachpazis: Foundation Analysis and Design: Single Piles
Sachpazis: Foundation Analysis and Design: Single PilesSachpazis: Foundation Analysis and Design: Single Piles
Sachpazis: Foundation Analysis and Design: Single Piles
Dr.Costas Sachpazis
 
Taykon-Kalite belgeleri
Taykon-Kalite belgeleriTaykon-Kalite belgeleri
Taykon-Kalite belgeleri
TAYKON
 
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
slayshadow705
 
decarbonization steel industry rev1.pptx
decarbonization steel industry rev1.pptxdecarbonization steel industry rev1.pptx
decarbonization steel industry rev1.pptx
gonzalezolabarriaped
 
TM-ASP-101-RF_Air Press manual crimping machine.pdf
TM-ASP-101-RF_Air Press manual crimping machine.pdfTM-ASP-101-RF_Air Press manual crimping machine.pdf
TM-ASP-101-RF_Air Press manual crimping machine.pdf
ChungLe60
 
Unit II: Design of Static Equipment Foundations
Unit II: Design of Static Equipment FoundationsUnit II: Design of Static Equipment Foundations
Unit II: Design of Static Equipment Foundations
Sanjivani College of Engineering, Kopargaon
 
Turbocor Product and Technology Review.pdf
Turbocor Product and Technology Review.pdfTurbocor Product and Technology Review.pdf
Turbocor Product and Technology Review.pdf
Totok Sulistiyanto
 
Equipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding ProcessEquipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding Process
AhmadKamil87
 
AI, Tariffs and Supply Chains in Knowledge Graphs
AI, Tariffs and Supply Chains in Knowledge GraphsAI, Tariffs and Supply Chains in Knowledge Graphs
AI, Tariffs and Supply Chains in Knowledge Graphs
Max De Marzi
 
How Engineering Model Making Brings Designs to Life.pdf
How Engineering Model Making Brings Designs to Life.pdfHow Engineering Model Making Brings Designs to Life.pdf
How Engineering Model Making Brings Designs to Life.pdf
Maadhu Creatives-Model Making Company
 
CFOT Fiber Optics FOA CERTIFICATION.pptx
CFOT Fiber Optics FOA CERTIFICATION.pptxCFOT Fiber Optics FOA CERTIFICATION.pptx
CFOT Fiber Optics FOA CERTIFICATION.pptx
MohamedShabana37
 
CS3451 INTRODUCTIONN TO OS unit ONE .pdf
CS3451 INTRODUCTIONN TO OS unit ONE .pdfCS3451 INTRODUCTIONN TO OS unit ONE .pdf
CS3451 INTRODUCTIONN TO OS unit ONE .pdf
PonniS7
 
Lessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the CloudLessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the Cloud
Igor Donchovski
 
Best KNow Hydrogen Fuel Production in the World The cost in USD kwh for H2
Best KNow  Hydrogen Fuel Production in the World The cost in USD kwh for H2Best KNow  Hydrogen Fuel Production in the World The cost in USD kwh for H2
Best KNow Hydrogen Fuel Production in the World The cost in USD kwh for H2
Daniel Donatelli
 
Water Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control Monthly - March 2025.pdfWater Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control Monthly - March 2025.pdf
Water Industry Process Automation & Control
 
Multi objective genetic approach with Ranking
Multi objective genetic approach with RankingMulti objective genetic approach with Ranking
Multi objective genetic approach with Ranking
namisha18
 
Syntax Directed Definitions Synthesized Attributes and Inherited Attributes
Syntax Directed Definitions  Synthesized Attributes  and  Inherited AttributesSyntax Directed Definitions  Synthesized Attributes  and  Inherited Attributes
Syntax Directed Definitions Synthesized Attributes and Inherited Attributes
GunjalSanjay
 
Optimization of Cumulative Energy, Exergy Consumption and Environmental Life ...
Optimization of Cumulative Energy, Exergy Consumption and Environmental Life ...Optimization of Cumulative Energy, Exergy Consumption and Environmental Life ...
Optimization of Cumulative Energy, Exergy Consumption and Environmental Life ...
J. Agricultural Machinery
 
GM Meeting 070225 TO 130225 for 2024.pptx
GM Meeting 070225 TO 130225 for 2024.pptxGM Meeting 070225 TO 130225 for 2024.pptx
GM Meeting 070225 TO 130225 for 2024.pptx
crdslalcomumbai
 
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Brian Gongol
 
Sachpazis: Foundation Analysis and Design: Single Piles
Sachpazis: Foundation Analysis and Design: Single PilesSachpazis: Foundation Analysis and Design: Single Piles
Sachpazis: Foundation Analysis and Design: Single Piles
Dr.Costas Sachpazis
 
Taykon-Kalite belgeleri
Taykon-Kalite belgeleriTaykon-Kalite belgeleri
Taykon-Kalite belgeleri
TAYKON
 
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
Structural QA/QC Inspection in KRP 401600 | Copper Processing Plant-3 (MOF-3)...
slayshadow705
 
decarbonization steel industry rev1.pptx
decarbonization steel industry rev1.pptxdecarbonization steel industry rev1.pptx
decarbonization steel industry rev1.pptx
gonzalezolabarriaped
 
TM-ASP-101-RF_Air Press manual crimping machine.pdf
TM-ASP-101-RF_Air Press manual crimping machine.pdfTM-ASP-101-RF_Air Press manual crimping machine.pdf
TM-ASP-101-RF_Air Press manual crimping machine.pdf
ChungLe60
 
Turbocor Product and Technology Review.pdf
Turbocor Product and Technology Review.pdfTurbocor Product and Technology Review.pdf
Turbocor Product and Technology Review.pdf
Totok Sulistiyanto
 
Equipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding ProcessEquipment for Gas Metal Arc Welding Process
Equipment for Gas Metal Arc Welding Process
AhmadKamil87
 
AI, Tariffs and Supply Chains in Knowledge Graphs
AI, Tariffs and Supply Chains in Knowledge GraphsAI, Tariffs and Supply Chains in Knowledge Graphs
AI, Tariffs and Supply Chains in Knowledge Graphs
Max De Marzi
 
CFOT Fiber Optics FOA CERTIFICATION.pptx
CFOT Fiber Optics FOA CERTIFICATION.pptxCFOT Fiber Optics FOA CERTIFICATION.pptx
CFOT Fiber Optics FOA CERTIFICATION.pptx
MohamedShabana37
 
CS3451 INTRODUCTIONN TO OS unit ONE .pdf
CS3451 INTRODUCTIONN TO OS unit ONE .pdfCS3451 INTRODUCTIONN TO OS unit ONE .pdf
CS3451 INTRODUCTIONN TO OS unit ONE .pdf
PonniS7
 
Lessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the CloudLessons learned when managing MySQL in the Cloud
Lessons learned when managing MySQL in the Cloud
Igor Donchovski
 
Best KNow Hydrogen Fuel Production in the World The cost in USD kwh for H2
Best KNow  Hydrogen Fuel Production in the World The cost in USD kwh for H2Best KNow  Hydrogen Fuel Production in the World The cost in USD kwh for H2
Best KNow Hydrogen Fuel Production in the World The cost in USD kwh for H2
Daniel Donatelli
 
Multi objective genetic approach with Ranking
Multi objective genetic approach with RankingMulti objective genetic approach with Ranking
Multi objective genetic approach with Ranking
namisha18
 
Syntax Directed Definitions Synthesized Attributes and Inherited Attributes
Syntax Directed Definitions  Synthesized Attributes  and  Inherited AttributesSyntax Directed Definitions  Synthesized Attributes  and  Inherited Attributes
Syntax Directed Definitions Synthesized Attributes and Inherited Attributes
GunjalSanjay
 
Optimization of Cumulative Energy, Exergy Consumption and Environmental Life ...
Optimization of Cumulative Energy, Exergy Consumption and Environmental Life ...Optimization of Cumulative Energy, Exergy Consumption and Environmental Life ...
Optimization of Cumulative Energy, Exergy Consumption and Environmental Life ...
J. Agricultural Machinery
 
GM Meeting 070225 TO 130225 for 2024.pptx
GM Meeting 070225 TO 130225 for 2024.pptxGM Meeting 070225 TO 130225 for 2024.pptx
GM Meeting 070225 TO 130225 for 2024.pptx
crdslalcomumbai
 
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Gauges are a Pump's Best Friend - Troubleshooting and Operations - v.07
Brian Gongol
 

Linux tuning to improve PostgreSQL performance

  • 1. Linux tuning to improve PostgreSQL performance Ilya Kosmodemiansky ik@postgresql-consulting.com
  • 2. The modern linux kernel • About 1000 sysctl parameters (plus non-sysctl settings, such as mount options) • It is not possible to benefit from the modern kernel’s advantages without wise tuning
  • 3. Tuning targets in Linux • CPU • Memory • Storage • Other
  • 4. PostgreSQL specifics • Hungry for resources (like any other database) • Tuning single target can have a very small effect • We need to maximize throughput
  • 6. How to make pages travel faster from disk to memory • More effective work with memory • More effective flushing pages to disk • A proper hardware, of course
  • 7. More effective work with memory • NUMA • Huge pages • Swap
  • 8. NUMA Symptoms that something goes wrong • Some CPU cores are overloaded without any obvious reason
  • 9. NUMA What goes on • Non Uniform Memory Access • CPUs have their own memory, CPU + memory nodes connected via NUMA interconnect • CPU uses its own memory, then accesses remaining memory by interconnect • If node interleaving disabled, CPU tries to use its local memory (for page cache for example;-))
  • 10. NUMA Which NUMA configuration is better for PostgreSQL • Enable memory interleaving in BIOS • numa → off or vm.zone_reclaim_mode = 0 • May be better numactl − −interleave = all /etc/init.d/postgresql start • kernel.numa_balancing = 0 Blog post from Robert Haas: http://rhaas.blogspot.co.at/2014/06/linux-disables- vmzonereclaimmode-by.html
  • 11. Huge pages Symptoms that something goes wrong • You have a lot of RAM and you shared_buffers settings is 32Gb/64Gb or more • That means that you definitely have an overhead if not using huge pages
  • 12. Huge pages What goes on • By default OS allocates memory by 4kB chunk • OS translates physical addresses into virtual addresses and cache the result in Translation Lookaside Buffer (TLB) • 1Gb 4kB = 262144 - huge TLB overhead and cache misses • Better to allocate memory in larger chunks
  • 13. Huge pages How can PostgreSQL benefit from huge pages? • Enable pages in kernel • vm.nr_hugepages = 3170 via sysctl • Before 9.2 - libhugetlbfs library • 9.3 - no way • 9.4+ huge_pages = try|on|off (postgresql.conf) • Works on Linux • Disable Transparent huge pages - PostgreSQL can not benefit from them
  • 14. Swap Symptoms that something goes wrong • There are enough memory, but swap is used
  • 15. Swap What goes on • It happens when there are a lot of RAM on server
  • 16. Swap What is better for PostgreSQL? • vm.swappiness = 1 or 0 • OOM-killer • 0 is not a good idea for modern kernels
  • 17. More effective flushing pages to disk Symptoms that something goes wrong • Checkpoint spikes
  • 18. More effective flushing pages to disk
  • 19. More effective flushing pages to disk What goes on • By default vm.dirty_ratio = 20, vm.dirty_background_ratio = 10 • Nothing happens until kernel buffer is 10% full of dirty pages • From 10% to 20% - background flushing • From 20% IO effectively stops until pdflush/flushd/kdflush finishes its job • This is almost crazy if your shared_buffers setting is 32Gb/64Gb or more with any cache on RAID-controller or SSD
  • 20. More effective flushing pages to disk What is better for PostgreSQL? • vm.dirty_background_bytes = 67108864, vm.dirty_bytes = 536870912 (for RAID with 512MB cache on board) looks more reasonable • Hardware settings and checkpoint settings in postgresql.conf must be appropriate • See my talk about PostgreSQL disc performance for details (https://www.youtube.com/watch?v=Lbx-JVcGIFo)
  • 21. What else • Scheduler tuning • Power saving
  • 22. Scheduler tuning • sysctl kernel.sched_migration_cost_ns supposed to be reasonably high • sysctl kernel.sched_autogroup_enabled = 0 • A good explanation http://www.postgresql.org/message- id/50E4AAB1.9040902@optionshouse.com • You need a relatively new kernel
  • 23. Example $ pgbench -S -c 8 -T 30 -U postgres pgbench transaction type: SELECT only scaling factor: 30 duration: 30 s number of clients: 8 number of threads: 1 sched_migration_cost_ns = 50000, sched_autogroup_enabled = 1 - tps: 22621, 22692, 22502 sched_migration_cost_ns = 500000, sched_autogroup_enabled = 0 - tps: 23689, 23930, 23657 tests by Alexey Lesovsky
  • 24. Power saving policy • acpi_cpufreq and intel_pstate drivers • scaling_governor: performance, ondemand, conservative, powersave, userspace • acpi_cpufreq + performance can be dramatically faster than acpi_cpufreq + ondemand • intel_pstate + powersave
  • 25. Thanks to my collegues Alexey Lesovsky and Max Boguk for a lot of research on this topic