Skip to content

Instantly share code, notes, and snippets.

@AlexBaranowski
Created February 1, 2019 16:54
Show Gist options
  • Save AlexBaranowski/d51fad72838f414204a712a553900825 to your computer and use it in GitHub Desktop.
Save AlexBaranowski/d51fad72838f414204a712a553900825 to your computer and use it in GitHub Desktop.
Simple script to calculate huge pages for PostgreSQL. Please note that this is baseline and require further tunning.
#!/usr/bin/env bash
[ -z "$PGDATA" ] && echo "PGDATA is not defined!" && exit 1
[ ! -e $PGDATA/postmaster.pid ] && echo "Cannot find $PGDATA/postmaster.pid is PostgreSQL server running?" && exit 1
PG_PID=$(head -1 $PGDATA/postmaster.pid)
PG_MEM_U=$(grep ^VmPeak /proc/$PG_PID/status | awk '{print $3}')
HP_MEM_U=$(grep ^Hugepagesize /proc/meminfo | awk '{print $3}')
[ "$PG_MEM_U" != "$HP_MEM_U" ] && echo "The units differ please calculate the Huge Pages manually" && exit 1
PG_MEM=$(grep ^VmPeak /proc/$PG_PID/status | awk '{print $2}')
HP_MEM=$(grep ^Hugepagesize /proc/meminfo | awk '{print $2}')
echo "Advised number of HugePages $((PG_MEM/HP_MEM))"
echo "You can use: sysctl -w vm.nr_hugepages=$((PG_MEM/HP_MEM))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment