postgres10 configure page

Keywords: CentOS Linux PostgreSQL Database

operating system

Modify / boot/grub2/grub.cfg

Navigate to the first 'menu' CentOS Linux 'and add it on the last side of "linux16 /vmlinuz"

numa=off transparent_hugepage=never default_hugepagesz=2M hugepagesz=2M hugepages=1536

*hugepagesz indicates the page size. Choose one of 2M and 1G, and the default is 2m.

hugepages indicates the number of large pages

The total large page memory is hugepagesz*hugepages, here is 3G

example:

menuentry 'CentOS Linux (3.10.0-693.5.2.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-693.el7.x86_64-advanced-d8179b22-8b44-4552-bf2a-04bae2a5f5dd' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  34f87a8d-8b73-4f80-b0ff-8d49b17975ca
        else
          search --no-floppy --fs-uuid --set=root 34f87a8d-8b73-4f80-b0ff-8d49b17975ca
        fi
        linux16 /vmlinuz-3.10.0-693.5.2.el7.x86_64 root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rhgb quiet LANG=en_US.UTF-8 numa=off transparent_hugepage=never default_hugepagesz=2M hugepagesz=2M hugepages=1536
        initrd16 /initramfs-3.10.0-693.5.2.el7.x86_64.img
}

Restart the system

After restart, you can use grep Huge /proc/meminfo to view the configuration. See the following data to show that it has taken effect

HugePages_Total:    1536
HugePages_Free:     1499
HugePages_Rsvd:     1024
HugePages_Surp:        0
Hugepagesize:       2048 kB

Database configuration

postgresql.conf

huge_pages = on
shared_buffers = 2GB  # Using 2G memory, this value needs to be less than the total large page memory

Be careful

If postgresql.conf is configured with page = on, and the value of shared buffers is equal to the total memory of page (hugepagesz * huge pages), the database cannot be started, and an error is reported as follows:

This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space. 

Solution: the values of shared and buffers should be less than the total memory of page

Posted by Wildbug on Sun, 03 May 2020 05:44:10 -0700