-
-
Save gkliska/8005360 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
PORT=6432 | |
# Create a ramfs | |
if [ -f /tmp/pg_on_ram ] | |
then | |
echo "/tmp/pg_on_ram already exists" | |
exit 1 | |
fi | |
mkdir /tmp/pg_on_ram | |
sudo mount -t ramfs -o size=6G ramfs /tmp/pg_on_ram | |
# Create a Postgres cluster | |
sudo chown -R postgres /tmp/pg_on_ram | |
sudo -u postgres /usr/lib/postgresql/9.1/bin/initdb /tmp/pg_on_ram | |
# change port to 6432 | |
sudo sed -i -e "s/^#\?\s*\(port\s*=\s*\).*$/\1$PORT/" /tmp/pg_on_ram/postgresql.conf | |
# better config for in-memory database (http://rhaas.blogspot.ch/2010/06/postgresql-as-in-memory-only-database_24.html) | |
sudo sed -i -e "s/^#?\(fsync\s*=\s*\).*$/\1off/" \ | |
-e "s/^#\?\s*\(synchronous_commit\s*=\s*\).*$/\1off/" \ | |
-e "s/^#\?\s*\(full_page_writes\s*=\s*\).*$/\1off/" \ | |
-e "s/^#\?\s*\(bgwriter_lru_maxpages\s*=\s*\).*$/\10/" \ | |
/tmp/pg_on_ram/postgresql.conf | |
sudo su postgres -c "/usr/lib/postgresql/9.1/bin/pg_ctl -D /tmp/pg_on_ram/ -l /tmp/pg_on_ram/postgresql.log start" | |
PID=$(sudo head -n 1 /tmp/pg_on_ram/postmaster.pid) | |
echo "postgresql started with PID $PID on port $PORT" | |
sudo tail -f /tmp/pg_on_ram/postgresql.log | |
sudo su postgres -c "/usr/lib/postgresql/9.1/bin/pg_ctl -D /tmp/pg_on_ram/ stop -m fast" | |
# Clean | |
sudo umount /tmp/pg_on_ram | |
sudo rm -rf /tmp/pg_on_ram |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment