Skip to content

Instantly share code, notes, and snippets.

@OndrejValenta
Last active April 6, 2024 23:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OndrejValenta/c4ecad735cef8b409fdf5594dd46c9fd to your computer and use it in GitHub Desktop.
Save OndrejValenta/c4ecad735cef8b409fdf5594dd46c9fd to your computer and use it in GitHub Desktop.
Install PostgreSQL 15 on RockyLinux 9

Installation of PostgreSQL 15 on RockyLinux 9 with OS configuration for better performance

Based on various sources

Installation and initialization

sudo dnf module list postgresql
sudo dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y
sudo dnf update -y
sudo dnf -qy module disable postgresql
sudo dnf install -y postgresql15-server

psql -V

sudo /usr/pgsql-15/bin/postgresql-15-setup initdb

Service configuration

sudo systemctl enable postgresql-15
sudo systemctl start postgresql-15
sudo systemctl status postgresql-15

Securing postgres account

Update password in SQL script below

sudo passwd postgres
su - postgres
psql -c "ALTER USER postgres WITH PASSWORD 'your-password';"

(OPTIONAL) Install Postgrestuner.pl

sudo dnf install epel-release -y
sudo dnf install postgresqltuner -y

BEFORE RUNNING THIS TOOL Create ~/.pgpass for postgres account so no passwords are visible in logs/console history https://www.postgresql.org/docs/current/libpq-pgpass.html OR ran under postgres user

~/.pgpass

localhost:5342:template1:postgres:your-password

OS Configuration

If first line returns pse 2MB page size is supported If second line returns pdpe1gb 1GB page size is supported - BETTER VARIANT for bigger servers

cat /proc/cpuinfo | grep -o ".\{0,0\}pse.\{0,0\}" | head -n 1
cat /proc/cpuinfo | grep -o ".\{0,0\}pdpe1gb.\{0,0\}" | head -n 1
  • Disable Transparent Huge Pages, PostgreSQL doesn't like them
  • Update grup configuration

/etc/default/grub

# add following configurations as last parameters in GRUB_CMDLINE_LINUX
# this line disables transparent hugepages and allocated 4 1GB blocks and 2*1024MB memory blocks

transparent_hugepage=never default_hugepagesz=1G hugepagesz=1G hugepages=4 hugepagesz=2M hugepages=1024

After that run this command to update grup settings and reboot

grub2-mkconfig -o /boot/grub2/grub.cfg
reboot

To check if the settings are valid you could run this command, but it only shows 4 1GB block allocated, if you use them

grep Huge /proc/meminfo

You can also check /sys/devices/system/node/node0/hugepages where you'll find, for example, nr_hugepages for total number of 1GB huge pages in /hugepages-1048576kB folder and number of free 1GB huge pages in free_hugepages file

image

System configuration

This change in /etc/sysctl.conf will disable memory overcommitment

# PostgreSQL required settings
vm.overcommit_memory=2

@OndrejValenta
Copy link
Author

So far tested and seems working quite fine. New configurations as I learn them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment