Tuesday, October 22, 2019

Using tuned to Configure PostgreSQL Database Management System

Tuned is a profile-based system tuning tool for dynamic and static tuning of system settings. I find it very useful even if for configuring system settings. Tuned comes from recent release of Fedora Linux distribution. The following steps are just to make sure that we have the tuned package in the system, and start and enable the tuned service.

sudo dnf install tuned
sudo systemctl start tuned
sudo systemctl enable tuned

Below are a few steps to show how we use tuned to manually adjust system settings (or static-tuning):

  • Listing existing profiles
    
    tuned-adm list
    

  • To activate a profile or to reactivate a profile after you have revised it,
    
    sudo tuned-adm active postgresql
    

    In this example, we have created a profile of our own to tune the system for running PostgreSQL Database Management System.
To create such a profile, follow the steps:
  1. Create a directory at /etc/tuned, e.g., if we wish to have a profile called postgresql, we create the directory postgresql at /etc/tuned,
    
    sudo mkdir /etc/tuned/postgresql
    

  2.  Create a profile at the directory you created, e.g., create tuned.conf at /etc/tuned/postgresql. The following is an example profile for PostgreSQL
    
    $ cat /etc/tuned/postgresql/tuned.conf
    #
    # tuned configuration
    #
    
    [main]
    summary=Optimize for running PostgreSQL inside a virtual guest
    
    [cpu]
    governor=performance
    energy_perf_bias=performance
    min_perf_pct=100
    
    [disk]
    readahead=>4096
    
    [sysctl]
    vm.dirty_ratio = 2
    vm.dirty_background_ratio=1
    vm.overcommit_memory=2
    vm.swappiness = 0
    vm.nr_hugepages=1192
    
    [vm]
    transparent_hugepages=never
    
    

    This profile basically sets the system to use 2MB hugepages for PostgreSQL. It is worth nothing that in the PostgreSQL's $PGDATA/postgresql.conf configuration file, we have these lines:
    
    shared_buffers = 2GB
    huge_pages = on
    

    Since shared buffers is 2GB/(hugepage size) = 2GB/2MB = 1024 pages, the vm.nr_hugepages (the number of reserved hugepages) cannot be less than 1024 pages plus additional pages for the process itself and others; otherwise, PostgreSQL will fail to start.

No comments:

Post a Comment