Created
May 8, 2013 19:58
-
-
Save miere/5543174 to your computer and use it in GitHub Desktop.
Generate PostgreSQL optimized memory parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# autotunning.sh | |
# Constants | |
TWO_GIGABYTES="2056772" | |
# Variables | |
# Utils | |
removeTabs(){ tr '\t' '@' | sed 's/@//'; } | |
int(){ echo "$1" | sed 's/\..*//'; } | |
print(){ echo "$@" >&2; } | |
return(){ echo "$@"; } | |
math(){ echo "$@" | bc -l; } | |
toMB(){ | |
gb=`math "$1 / 1024 / 1024"` | |
return "`int $gb`mb" | |
} | |
# Functions | |
get_ram_memory(){ | |
memline=`cat /proc/meminfo | tr '\t' ' ' | sed 's/ */ /g;/MemTotal/!d'` | |
mem=`echo $memline | cut -d ' ' -f 2` | |
mult=`echo $memline | cut -d ' ' -f 3 | sed 's/kb/1024/ig;s/mb/1024*1024/gi;s/gb/1024*1024*1024/gi'` | |
return `math "${mem} * ${mult}"` | |
} | |
get_shared_buffers(){ | |
ram_memory=`get_ram_memory` | |
shared_buffers="" | |
if [ "$ram_memory" -gt "$TWO_GIGABYTES" ]; then | |
shared_buffers=`math "$ram_memory * 0.20"` | |
else | |
shared_buffers=`math "$ram_memory * 0.25"` | |
fi | |
return `toMB $shared_buffers` | |
} | |
get_work_mem(){ | |
return "64MB" | |
} | |
get_maintenance_work_mem(){ | |
ram_memory=`get_ram_memory` | |
maintenance_work_mem=`math "$ram_memory * 0.10"` | |
return `toMB $maintenance_work_mem` | |
} | |
get_effective_cache_size(){ | |
return "16mb" | |
} | |
# main | |
cat<<EOF | removeTabs | |
shared_buffers = `get_shared_buffers` | |
work_mem = `get_work_mem` | |
maintenance_work_mem = `get_maintenance_work_mem` | |
effective_cache_size = `get_effective_cache_size` | |
wal_buffers = 16mb | |
checkpoint_completion_target = 0.9 | |
checkpoint_timeout = 10m | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on excellent post about PostgreSQL tunning:
http://reinout.vanrees.org/weblog/2012/06/04/djangocon-postgres.html