SlideShare a Scribd company logo
Tuning Linux for Databases.
About
PostgreSQL DBA.
Linux system administrator.
PostgreSQL-Consulting.com:
● 24/7 support.
● Audit, performance optimizations.
● Consulting and Training.
● Monitoring and Emergency.
● Capacity planning.
Slides: https://goo.gl/awmZ2H
Agenda
RDBMS on Linux, why?
Databases and Resources.
OS subsystems.
CPU, Process scheduling, Power saving policies.
Memory, VM, NUMA, Huge pages.
Storage, File Systems, Input/Output.
Other misc.
Why Linux?
Linux is a good choice:
● Active development & Community support.
● A lot of features & Fast implementation.
● Stable & Mature & Durable.
Databases & Resources
Concurrency
Query speed
Sort, group, hash,...
OS page cache
DB buffer pool
Local process cache
DB data files
Transaction Log
Cold start
CPU Memory
Storage
Databases & Resources
CPU Scheduling
NUMA
Power Saving
Virtual Memory
NUMA
Huge Pages
File Systems
Storage I/O
CPU Memory
Storage
Resources
CPU scheduler.
Virtual memory and NUMA.
Huge pages.
File systems.
Storage IO.
Power saving policy.
Others.
CPU scheduling
CPU scheduler responsible for proper processes planning:
Sysctl:
● kernel.sched_migration_cost_ns = 5000000 (default: 500000).
● kernel.sched_autogroup_enabled = 0 (default: 1).
http://www.postgresql.org/message-id/50E4AAB1.9040902@optionshouse.com
http://kernelnewbies.org/Linux_2_6_38#head-59575a6aeafa38490226a560ee02de89829a5b20
CPU scheduling
CPU scheduler responsible for proper processes planning:
Sysctl:
● kernel.sched_migration_cost_ns = 5000000 (default: 500000).
● kernel.sched_autogroup_enabled = 0 (default: 1).
http://www.postgresql.org/message-id/50E4AAB1.9040902@optionshouse.com
http://kernelnewbies.org/Linux_2_6_38#head-59575a6aeafa38490226a560ee02de89829a5b20
Be aware on Ubuntu: 12.04 #1055222 and 14.04 #1422016.
Use noautogroup kernel param instead of sysctl.conf.
Virtual Memory
What is it?
Allocator, Caching, Dirty pages and Writeback.
Virtual Memory
Virtual Memory
Sysctl:
vm.dirty_background_ratio & vm.dirty_ratio = disable it.
vm.dirty_background_bytes & vm.dirty_bytes = depends on ...
RAID cache size, 64MB/128MB otherwise
Virtual Memory
Out-of-memory & OOM-Killer
Sysctl: vm.swappiness = 1 (default: 60)
NUMA
S — Socket C — CPU core M — Memory bank
NUMA
BIOS: enable memory node interleaving.
Kernel boot: numa=off.
numactl utility.
Sysctl:
● vm.zone_reclaim_mode = 0 (default: 0).
● kernel.numa_balancing = 0 (default: 0).
Huge Pages
Huge pages vs. Transparent huge pages.
Huge pages are supported by many RDBMS.
Always disable transparent huge pages.
Huge Pages
Huge pages vs. Transparent huge pages.
Huge pages are supported by many RDBMS.
Always disable transparent huge pages.
/etc/rc.local:
● echo never > /sys/kernel/mm/transparent_hugepage/enabled
● echo never > /sys/kernel/mm/transparent_hugepage/defrag
Filesystems
Ext3 vs Ext4 vs XFS: what is better?
Filesystem Barriers.
Filesystems
Ext3 vs Ext4 vs XFS: what is better?
Filesystem Barriers.
Disable Write Cache:
● hdparm -W0 /dev/device
● MegaCli64 -LDSetProp -DisDskCache -Lall -aALL
Filesystems
Ext3 vs Ext4 vs XFS: what is better?
Filesystem Barriers.
Disable Write Cache:
● hdparm -W0 /dev/device
● MegaCli64 -LDSetProp -DisDskCache -Lall -aALL
Hardware RAID + BBU = barrier=0 (disable).
Software RAID = barrier=1 (enable).
Filesystems
Ext3 vs Ext4 vs XFS: what is better?
Filesystem Barriers.
Disable Write Cache:
● hdparm -W0 /dev/device
● MegaCli64 -LDSetProp -DisDskCache -Lall -aALL
Hardware RAID + BBU = barrier=0 (disable).
Software RAID = barrier=1 (enable).
Enterprise SSD with Power Loss Protection = barrier=0 (disable).
Storage IO
SATA/SAS vs SSD.
IO elevators.
Storage IO
SATA/SAS vs SSD.
IO elevators:
● noop: SSD, PCIe SSD, hi-end storages.
● deadline: RAID, SATA/SAS.
● cfq: good default.
● none (multi-queue block IO): SSD, PCIe SSD.
Storage IO
SATA/SAS vs SSD.
IO elevators:
● noop: SSD, PCIe SSD, hi-end storages.
● deadline: RAID, SATA/SAS.
● cfq: good default.
● none (multi-queue block IO): SSD, PCIe SSD.
# echo 'elevator_name' > /sys/block/<device>/queue/scheduler
kernel boot: elevator=<name>
/sys/block/*/queue/: rotational, rq_affinity, read_ahead_kb
Power Saving Policy
Drivers: acpi_cpufreq vs. intel_pstate.
scaling_governor.
Power Saving Policy
Drivers: acpi_cpufreq vs. intel_pstate.
scaling_governor:
● /sys/devices/system/cpu/cpuX/cpufreq/scaling_available_governors
● /sys/devices/system/cpu/cpuX/cpufreq/scaling_governor
Power Saving Policy
Drivers: acpi_cpufreq vs. intel_pstate.
scaling_governor:
● /sys/devices/system/cpu/cpuX/cpufreq/scaling_available_governors
● /sys/devices/system/cpu/cpuX/cpufreq/scaling_governor
acpi_cpufreq + performance.
intel_pstate + powersave.
Misc: Clocksources
What is clocksource?
acpi_pm vs. hpet vs. tsc.
/sys/devices/system/clocksource/clocksource0/available_clocksource.
/sys/devices/system/clocksource/clocksource0/current_clocksource.
Summary
Linux is a good choice for RDBMS:
Modern, Universal, Flexible, Stable.
Adapt Linux for your workloads.
Test → Change → Test → Commit/Rollback.
Questions?
Alexey Lesovsky
lesovsky@pgco.me
PostgreSQL-Consulting.com: Data maintenance at its best
https://postgresql-consulting.com

More Related Content

What's hot (20)

PDF
Linux internals for Database administrators at Linux Piter 2016
PostgreSQL-Consulting
 
PDF
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
PostgreSQL-Consulting
 
PDF
PostgreSQL WAL for DBAs
PGConf APAC
 
PDF
Really Big Elephants: PostgreSQL DW
PostgreSQL Experts, Inc.
 
PDF
Pgcenter overview
Alexey Lesovsky
 
PDF
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
PDF
Linux tuning for PostgreSQL at Secon 2015
Alexey Lesovsky
 
PDF
PostgreSQL High Availability in a Containerized World
Jignesh Shah
 
PDF
Troubleshooting PostgreSQL Streaming Replication
Alexey Lesovsky
 
ODP
Shootout at the PAAS Corral
PostgreSQL Experts, Inc.
 
ODP
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Experts, Inc.
 
PDF
Toro DB- Open-source, MongoDB-compatible database, built on top of PostgreSQL
InMobi Technology
 
PDF
Out of the box replication in postgres 9.4
Denish Patel
 
PPTX
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
Ontico
 
PDF
Clug 2012 March web server optimisation
grooverdan
 
PDF
High Availability PostgreSQL with Zalando Patroni
Zalando Technology
 
PDF
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
Wei Shan Ang
 
PDF
PostgreSQL Replication Tutorial
Hans-Jürgen Schönig
 
PDF
PostgreSQL Streaming Replication Cheatsheet
Alexey Lesovsky
 
PDF
PostgreSQL HA
haroonm
 
Linux internals for Database administrators at Linux Piter 2016
PostgreSQL-Consulting
 
Ilya Kosmodemiansky - An ultimate guide to upgrading your PostgreSQL installa...
PostgreSQL-Consulting
 
PostgreSQL WAL for DBAs
PGConf APAC
 
Really Big Elephants: PostgreSQL DW
PostgreSQL Experts, Inc.
 
Pgcenter overview
Alexey Lesovsky
 
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
Linux tuning for PostgreSQL at Secon 2015
Alexey Lesovsky
 
PostgreSQL High Availability in a Containerized World
Jignesh Shah
 
Troubleshooting PostgreSQL Streaming Replication
Alexey Lesovsky
 
Shootout at the PAAS Corral
PostgreSQL Experts, Inc.
 
PostgreSQL Replication in 10 Minutes - SCALE
PostgreSQL Experts, Inc.
 
Toro DB- Open-source, MongoDB-compatible database, built on top of PostgreSQL
InMobi Technology
 
Out of the box replication in postgres 9.4
Denish Patel
 
100500 способов кэширования в Oracle Database или как достичь максимальной ск...
Ontico
 
Clug 2012 March web server optimisation
grooverdan
 
High Availability PostgreSQL with Zalando Patroni
Zalando Technology
 
pgDay Asia 2016 - Swapping Pacemaker-Corosync for repmgr (1)
Wei Shan Ang
 
PostgreSQL Replication Tutorial
Hans-Jürgen Schönig
 
PostgreSQL Streaming Replication Cheatsheet
Alexey Lesovsky
 
PostgreSQL HA
haroonm
 

Viewers also liked (20)

PDF
PostgreSQL Vacuum: Nine Circles of Hell
Alexey Lesovsky
 
PDF
Managing PostgreSQL with PgCenter
Alexey Lesovsky
 
PDF
Nine Circles of Inferno or Explaining the PostgreSQL Vacuum
Alexey Lesovsky
 
PDF
GitLab PostgresMortem: Lessons Learned
Alexey Lesovsky
 
PDF
PostgreSQL Tuning: O elefante mais rápido que um leopardo
elliando dias
 
PDF
Девять кругов ада или PostgreSQL Vacuum / Алексей Лесовский (PostgreSQL-Consu...
Ontico
 
PDF
PostgreSQLレプリケーション徹底紹介
Masao Fujii
 
PDF
Cat @ scale
Rohit Jnagal
 
PDF
VHPC'12: Pre-Copy and Post-Copy VM Live Migration for Memory Intensive Applic...
aidanshribman
 
PPTX
CPU Caches
shinolajla
 
PPTX
Leveraging memory in sql server
Chris Adkin
 
PDF
SLES Performance Enhancements for Large NUMA Systems
Davidlohr Bueso
 
PDF
美团技术沙龙04 - 高性能服务器架构设计和调优
美团点评技术团队
 
PDF
Summit2014 riel chegu_w_0340_automatic_numa_balancing_0
sprdd
 
PPT
Aca 2
parbhatverma
 
PDF
Technical update KVM and Red Hat Enterprise Virtualization (RHEV) by syedmshaaf
Syed Shaaf
 
PPTX
Cache & CPU performance
so61pi
 
PDF
Linux NUMA & Databases: Perils and Opportunities
Raghavendra Prabhu
 
PDF
美团技术团队 - KVM性能优化
美团点评技术团队
 
PDF
QEMU Disk IO Which performs Better: Native or threads?
Pradeep Kumar
 
PostgreSQL Vacuum: Nine Circles of Hell
Alexey Lesovsky
 
Managing PostgreSQL with PgCenter
Alexey Lesovsky
 
Nine Circles of Inferno or Explaining the PostgreSQL Vacuum
Alexey Lesovsky
 
GitLab PostgresMortem: Lessons Learned
Alexey Lesovsky
 
PostgreSQL Tuning: O elefante mais rápido que um leopardo
elliando dias
 
Девять кругов ада или PostgreSQL Vacuum / Алексей Лесовский (PostgreSQL-Consu...
Ontico
 
PostgreSQLレプリケーション徹底紹介
Masao Fujii
 
Cat @ scale
Rohit Jnagal
 
VHPC'12: Pre-Copy and Post-Copy VM Live Migration for Memory Intensive Applic...
aidanshribman
 
CPU Caches
shinolajla
 
Leveraging memory in sql server
Chris Adkin
 
SLES Performance Enhancements for Large NUMA Systems
Davidlohr Bueso
 
美团技术沙龙04 - 高性能服务器架构设计和调优
美团点评技术团队
 
Summit2014 riel chegu_w_0340_automatic_numa_balancing_0
sprdd
 
Technical update KVM and Red Hat Enterprise Virtualization (RHEV) by syedmshaaf
Syed Shaaf
 
Cache & CPU performance
so61pi
 
Linux NUMA & Databases: Perils and Opportunities
Raghavendra Prabhu
 
美团技术团队 - KVM性能优化
美团点评技术团队
 
QEMU Disk IO Which performs Better: Native or threads?
Pradeep Kumar
 
Ad

Similar to Tuning Linux for Databases. (20)

PDF
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 
PDF
OSDC 2016 - Tuning Linux for your Database by Colin Charles
NETWAYS
 
PPTX
Oracle Performance On Linux X86 systems
Baruch Osoveskiy
 
PDF
Tuning Linux for your database FLOSSUK 2016
Colin Charles
 
PDF
Tuning Linux Windows and Firebird for Heavy Workload
Marius Adrian Popa
 
PDF
Best Practices with PostgreSQL on Solaris
Jignesh Shah
 
PDF
Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...
PostgreSQL-Consulting
 
PDF
MySQL Performance for DevOps
Sveta Smirnova
 
PDF
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
Equnix Business Solutions
 
PPTX
VLDB Administration Strategies
Murilo Miranda
 
PPTX
RAC-Installing your First Cluster and Database
Nikhil Kumar
 
PPTX
Tuning linux for mongo db
Soumya Bhattacharyya
 
PDF
5 Steps to PostgreSQL Performance
Command Prompt., Inc
 
PDF
Five steps perform_2009 (1)
PostgreSQL Experts, Inc.
 
PPTX
Refining Linux
Jason Murray
 
PDF
Rhel Tuningand Optimizationfor Oracle V11
Yusuf Hadiwinata Sutandar
 
PDF
Improving Hadoop Performance via Linux
Alex Moundalexis
 
PDF
PGConf.ASIA 2019 Bali - AppOS: PostgreSQL Extension for Scalable File I/O - K...
Equnix Business Solutions
 
PDF
MySQL Performance Tuning London Meetup June 2017
Ivan Zoratti
 
PPT
Mysql talk
LogicMonitor
 
Linux tuning to improve PostgreSQL performance
PostgreSQL-Consulting
 
OSDC 2016 - Tuning Linux for your Database by Colin Charles
NETWAYS
 
Oracle Performance On Linux X86 systems
Baruch Osoveskiy
 
Tuning Linux for your database FLOSSUK 2016
Colin Charles
 
Tuning Linux Windows and Firebird for Heavy Workload
Marius Adrian Popa
 
Best Practices with PostgreSQL on Solaris
Jignesh Shah
 
Linux IO internals for database administrators (SCaLE 2017 and PGDay Nordic 2...
PostgreSQL-Consulting
 
MySQL Performance for DevOps
Sveta Smirnova
 
PGConf.ASIA 2019 Bali - Tune Your LInux Box, Not Just PostgreSQL - Ibrar Ahmed
Equnix Business Solutions
 
VLDB Administration Strategies
Murilo Miranda
 
RAC-Installing your First Cluster and Database
Nikhil Kumar
 
Tuning linux for mongo db
Soumya Bhattacharyya
 
5 Steps to PostgreSQL Performance
Command Prompt., Inc
 
Five steps perform_2009 (1)
PostgreSQL Experts, Inc.
 
Refining Linux
Jason Murray
 
Rhel Tuningand Optimizationfor Oracle V11
Yusuf Hadiwinata Sutandar
 
Improving Hadoop Performance via Linux
Alex Moundalexis
 
PGConf.ASIA 2019 Bali - AppOS: PostgreSQL Extension for Scalable File I/O - K...
Equnix Business Solutions
 
MySQL Performance Tuning London Meetup June 2017
Ivan Zoratti
 
Mysql talk
LogicMonitor
 
Ad

More from Alexey Lesovsky (13)

PDF
Отладка и устранение проблем в PostgreSQL Streaming Replication.
Alexey Lesovsky
 
PDF
Call of Postgres: Advanced Operations (part 5)
Alexey Lesovsky
 
PDF
Call of Postgres: Advanced Operations (part 4)
Alexey Lesovsky
 
PDF
Call of Postgres: Advanced Operations (part 3)
Alexey Lesovsky
 
PDF
Call of Postgres: Advanced Operations (part 2)
Alexey Lesovsky
 
PDF
Call of Postgres: Advanced Operations (part 1)
Alexey Lesovsky
 
PDF
Troubleshooting PostgreSQL with pgCenter
Alexey Lesovsky
 
PDF
PostgreSQL Streaming Replication
Alexey Lesovsky
 
PDF
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
PDF
Streaming replication in practice
Alexey Lesovsky
 
PDF
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
PDF
Highload 2014. PostgreSQL: ups, DevOps.
Alexey Lesovsky
 
PDF
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
Alexey Lesovsky
 
Отладка и устранение проблем в PostgreSQL Streaming Replication.
Alexey Lesovsky
 
Call of Postgres: Advanced Operations (part 5)
Alexey Lesovsky
 
Call of Postgres: Advanced Operations (part 4)
Alexey Lesovsky
 
Call of Postgres: Advanced Operations (part 3)
Alexey Lesovsky
 
Call of Postgres: Advanced Operations (part 2)
Alexey Lesovsky
 
Call of Postgres: Advanced Operations (part 1)
Alexey Lesovsky
 
Troubleshooting PostgreSQL with pgCenter
Alexey Lesovsky
 
PostgreSQL Streaming Replication
Alexey Lesovsky
 
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
Streaming replication in practice
Alexey Lesovsky
 
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
Highload 2014. PostgreSQL: ups, DevOps.
Alexey Lesovsky
 
PostgreSQL Troubleshoot On-line, (RITfest 2015 meetup at Moscow, Russia).
Alexey Lesovsky
 

Recently uploaded (20)

PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Horarios de distribución de agua en julio
pegazohn1978
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 

Tuning Linux for Databases.

  • 2. About PostgreSQL DBA. Linux system administrator. PostgreSQL-Consulting.com: ● 24/7 support. ● Audit, performance optimizations. ● Consulting and Training. ● Monitoring and Emergency. ● Capacity planning. Slides: https://goo.gl/awmZ2H
  • 3. Agenda RDBMS on Linux, why? Databases and Resources. OS subsystems. CPU, Process scheduling, Power saving policies. Memory, VM, NUMA, Huge pages. Storage, File Systems, Input/Output. Other misc.
  • 4. Why Linux? Linux is a good choice: ● Active development & Community support. ● A lot of features & Fast implementation. ● Stable & Mature & Durable.
  • 5. Databases & Resources Concurrency Query speed Sort, group, hash,... OS page cache DB buffer pool Local process cache DB data files Transaction Log Cold start CPU Memory Storage
  • 6. Databases & Resources CPU Scheduling NUMA Power Saving Virtual Memory NUMA Huge Pages File Systems Storage I/O CPU Memory Storage
  • 7. Resources CPU scheduler. Virtual memory and NUMA. Huge pages. File systems. Storage IO. Power saving policy. Others.
  • 8. CPU scheduling CPU scheduler responsible for proper processes planning: Sysctl: ● kernel.sched_migration_cost_ns = 5000000 (default: 500000). ● kernel.sched_autogroup_enabled = 0 (default: 1). http://www.postgresql.org/message-id/[email protected] http://kernelnewbies.org/Linux_2_6_38#head-59575a6aeafa38490226a560ee02de89829a5b20
  • 9. CPU scheduling CPU scheduler responsible for proper processes planning: Sysctl: ● kernel.sched_migration_cost_ns = 5000000 (default: 500000). ● kernel.sched_autogroup_enabled = 0 (default: 1). http://www.postgresql.org/message-id/[email protected] http://kernelnewbies.org/Linux_2_6_38#head-59575a6aeafa38490226a560ee02de89829a5b20 Be aware on Ubuntu: 12.04 #1055222 and 14.04 #1422016. Use noautogroup kernel param instead of sysctl.conf.
  • 10. Virtual Memory What is it? Allocator, Caching, Dirty pages and Writeback.
  • 12. Virtual Memory Sysctl: vm.dirty_background_ratio & vm.dirty_ratio = disable it. vm.dirty_background_bytes & vm.dirty_bytes = depends on ... RAID cache size, 64MB/128MB otherwise
  • 13. Virtual Memory Out-of-memory & OOM-Killer Sysctl: vm.swappiness = 1 (default: 60)
  • 14. NUMA S — Socket C — CPU core M — Memory bank
  • 15. NUMA BIOS: enable memory node interleaving. Kernel boot: numa=off. numactl utility. Sysctl: ● vm.zone_reclaim_mode = 0 (default: 0). ● kernel.numa_balancing = 0 (default: 0).
  • 16. Huge Pages Huge pages vs. Transparent huge pages. Huge pages are supported by many RDBMS. Always disable transparent huge pages.
  • 17. Huge Pages Huge pages vs. Transparent huge pages. Huge pages are supported by many RDBMS. Always disable transparent huge pages. /etc/rc.local: ● echo never > /sys/kernel/mm/transparent_hugepage/enabled ● echo never > /sys/kernel/mm/transparent_hugepage/defrag
  • 18. Filesystems Ext3 vs Ext4 vs XFS: what is better? Filesystem Barriers.
  • 19. Filesystems Ext3 vs Ext4 vs XFS: what is better? Filesystem Barriers. Disable Write Cache: ● hdparm -W0 /dev/device ● MegaCli64 -LDSetProp -DisDskCache -Lall -aALL
  • 20. Filesystems Ext3 vs Ext4 vs XFS: what is better? Filesystem Barriers. Disable Write Cache: ● hdparm -W0 /dev/device ● MegaCli64 -LDSetProp -DisDskCache -Lall -aALL Hardware RAID + BBU = barrier=0 (disable). Software RAID = barrier=1 (enable).
  • 21. Filesystems Ext3 vs Ext4 vs XFS: what is better? Filesystem Barriers. Disable Write Cache: ● hdparm -W0 /dev/device ● MegaCli64 -LDSetProp -DisDskCache -Lall -aALL Hardware RAID + BBU = barrier=0 (disable). Software RAID = barrier=1 (enable). Enterprise SSD with Power Loss Protection = barrier=0 (disable).
  • 22. Storage IO SATA/SAS vs SSD. IO elevators.
  • 23. Storage IO SATA/SAS vs SSD. IO elevators: ● noop: SSD, PCIe SSD, hi-end storages. ● deadline: RAID, SATA/SAS. ● cfq: good default. ● none (multi-queue block IO): SSD, PCIe SSD.
  • 24. Storage IO SATA/SAS vs SSD. IO elevators: ● noop: SSD, PCIe SSD, hi-end storages. ● deadline: RAID, SATA/SAS. ● cfq: good default. ● none (multi-queue block IO): SSD, PCIe SSD. # echo 'elevator_name' > /sys/block/<device>/queue/scheduler kernel boot: elevator=<name> /sys/block/*/queue/: rotational, rq_affinity, read_ahead_kb
  • 25. Power Saving Policy Drivers: acpi_cpufreq vs. intel_pstate. scaling_governor.
  • 26. Power Saving Policy Drivers: acpi_cpufreq vs. intel_pstate. scaling_governor: ● /sys/devices/system/cpu/cpuX/cpufreq/scaling_available_governors ● /sys/devices/system/cpu/cpuX/cpufreq/scaling_governor
  • 27. Power Saving Policy Drivers: acpi_cpufreq vs. intel_pstate. scaling_governor: ● /sys/devices/system/cpu/cpuX/cpufreq/scaling_available_governors ● /sys/devices/system/cpu/cpuX/cpufreq/scaling_governor acpi_cpufreq + performance. intel_pstate + powersave.
  • 28. Misc: Clocksources What is clocksource? acpi_pm vs. hpet vs. tsc. /sys/devices/system/clocksource/clocksource0/available_clocksource. /sys/devices/system/clocksource/clocksource0/current_clocksource.
  • 29. Summary Linux is a good choice for RDBMS: Modern, Universal, Flexible, Stable. Adapt Linux for your workloads. Test → Change → Test → Commit/Rollback.
  • 30. Questions? Alexey Lesovsky [email protected] PostgreSQL-Consulting.com: Data maintenance at its best https://postgresql-consulting.com